Skip to content

Commit 34ca703

Browse files
committed
Error checkout if repository is dirty
Under certain circumstances, go-git can fail to complete checkout, while not even returning an error. While the clean and hard reset processes should ensure this is corrected, the fact that it is necessary casts doubt on the reliability of go-git. It's very important that the releases distributed by Library Manager match the repository, so it's better to reject any releases that can't be brought into a clean state.
1 parent 356139b commit 34ca703

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

internal/libraries/gitutils/gitutils.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
package gitutils
2525

2626
import (
27+
"fmt"
2728
"sort"
2829

2930
"github.com/go-git/go-git/v5"
@@ -189,5 +190,13 @@ func CheckoutTag(repository *git.Repository, tag *plumbing.Reference) error {
189190
return err
190191
}
191192

193+
repoStatus, err := repoTree.Status()
194+
if err != nil {
195+
return err
196+
}
197+
if !repoStatus.IsClean() {
198+
return fmt.Errorf("failed to get repository to clean state")
199+
}
200+
192201
return nil
193202
}

0 commit comments

Comments
 (0)