Skip to content

Commit 7050d0b

Browse files
committed
handle lock file deletion before checkoputRevision
Signed-off-by: reggie-k <regina.voloshin@codefresh.io>
1 parent afb4476 commit 7050d0b

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

reposerver/repository/repository.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2536,21 +2536,19 @@ func fetch(gitClient git.Client, targetRevisions []string) error {
25362536
// removeStaleGitLocks best-effort removes common stale git lock files in the repository.
25372537
// It is safe to call while holding the per-repo lock and before running any git commands.
25382538

2539-
func removeStaleGitLocks(repoRoot string) {
2539+
func removeStaleGitLock(repoRoot string) {
25402540
path := filepath.Join(repoRoot, ".git", "HEAD.lock")
25412541
log.Infof("Checking whether HEAD.lock exists %s", path)
25422542
if _, err := os.Stat(path); err == nil {
25432543
log.Warnf("HEAD.lock present in git repository %s, removing it", repoRoot)
2544-
if rmErr := os.Remove(path); rmErr == nil {
2545-
log.Infof("Removed stale git lock %s", path)
2546-
} else if !os.IsNotExist(rmErr) {
2547-
log.Warnf("Failed to remove git lock %s: %v", path, rmErr)
2544+
if rmErr := os.Remove(path); rmErr != nil {
2545+
log.Errorf("Failed to remove git lock %s: %v", path, rmErr)
25482546
}
25492547
}
25502548
}
25512549

25522550
func checkoutRevision(gitClient git.Client, revision string, submoduleEnabled bool) error {
2553-
removeStaleGitLocks(gitClient.Root())
2551+
removeStaleGitLock(gitClient.Root())
25542552

25552553
err := gitClient.Init()
25562554
if err != nil {

reposerver/repository/repository_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3028,15 +3028,15 @@ func TestRemoveStaleGitHeadLock(t *testing.T) {
30283028
_, err := os.Stat(headLock)
30293029
require.NoError(t, err)
30303030

3031-
removeStaleGitLocks(dir)
3031+
removeStaleGitLock(dir)
30323032

30333033
// lock should be gone after cleanup
30343034
_, err = os.Stat(headLock)
30353035
require.Error(t, err)
30363036
require.True(t, os.IsNotExist(err))
30373037

30383038
// calling again should be a no-op (no error)
3039-
removeStaleGitLocks(dir)
3039+
removeStaleGitLock(dir)
30403040
}
30413041

30423042
// TestCheckoutRevisionCanGetNonstandardRefs shows that we can fetch a revision that points to a non-standard ref. In

0 commit comments

Comments
 (0)