Skip to content

Commit

Permalink
Add check for empty Git repo
Browse files Browse the repository at this point in the history
  • Loading branch information
mikusaq committed Jan 8, 2025
1 parent ea5d4e0 commit b0f8686
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions modules/bringauto_repository/GitLFSRepository.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,14 @@ func (lfs *GitLFSRepository) CommitAllChanges() error {
// RestoreAllChanges
// Restores all changes in repository and cleans all untracked changes.
func (lfs *GitLFSRepository) RestoreAllChanges() error {
err := lfs.gitRestoreAll()
if err != nil {
return err
var err error
if !lfs.isRepoEmpty() {
err = lfs.gitRestoreAll()
if err != nil {
return err
}
}

err = lfs.gitCleanAll()
if err != nil {
return err
Expand Down Expand Up @@ -271,6 +275,14 @@ func (lfs *GitLFSRepository) gitCleanAll() error {
return nil
}

func (lfs *GitLFSRepository) isRepoEmpty() bool {
var ok, _ = lfs.prepareAndRun([]string{
"log",
},
)
return !ok
}

func (repo *GitLFSRepository) prepareAndRun(cmdline []string) (bool, *bytes.Buffer) {
var cmd exec.Cmd
var outBuffer bytes.Buffer
Expand Down

0 comments on commit b0f8686

Please sign in to comment.