Skip to content

Commit 356139b

Browse files
committed
Do hard reset after checkout
Even though in theory it shouldn't ever be necessary to do a hard reset in this application, under certain circumstances, go-git can fail to complete checkout, while not even returning an error. The resulting dirty repository state would cause Library Manager to serve a corrupted release. A hard reset after each checkout ensures that the repository is at its tagged state.
1 parent e7bbb3d commit 356139b

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

internal/libraries/gitutils/gitutils.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,20 @@ func CheckoutTag(repository *git.Repository, tag *plumbing.Reference) error {
174174
return err
175175
}
176176

177+
// Remove now-empty folders which are left behind after checkout. These would not be removed by the reset action.
178+
// Remove untracked files. These would also be removed by the reset action.
177179
if err = repoTree.Clean(&git.CleanOptions{Dir: true}); err != nil {
178180
return err
179181
}
180182

183+
// Remove untracked files and reset tracked files to clean state.
184+
// Even though in theory it shouldn't ever be necessary to do a hard reset in this application, under certain
185+
// circumstances, go-git can fail to complete checkout, while not even returning an error. This results in an
186+
// unexpected dirty repository state, which is corrected via a hard reset.
187+
// See: https://github.com/go-git/go-git/issues/99
188+
if err = repoTree.Reset(&git.ResetOptions{Mode: git.HardReset}); err != nil {
189+
return err
190+
}
191+
181192
return nil
182193
}

0 commit comments

Comments
 (0)