From bd0ba1bf5e4f0433c5d38e5a75db0c778bbc7321 Mon Sep 17 00:00:00 2001 From: dadada Date: Mon, 23 May 2022 18:07:09 +0200 Subject: [PATCH] fix unsafe concurrent access to git repo --- main.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index 66ce44f..f0c3965 100644 --- a/main.go +++ b/main.go @@ -33,6 +33,10 @@ func commit( commitmu.Lock() defer commitmu.Unlock() + if _, err := tree.Add(padfile); err != nil { + return plumbing.ZeroHash, fmt.Errorf("Failed to stage %s: %w", padfile, err) + } + commit, err := tree.Commit( fmt.Sprintf("Updated %s from %s", padfile, url), &git.CommitOptions{ @@ -85,10 +89,6 @@ func update( return plumbing.ZeroHash, fmt.Errorf("No changes recorded for %s", url) } - if _, err = tree.Add(padfile); err != nil { - return plumbing.ZeroHash, fmt.Errorf("Failed to stage %s: %w", padfile, err) - } - return commit(tree, padfile, url) }