Skip to content

Commit

Permalink
Handle case when working tree is clean but new tag has been created
Browse files Browse the repository at this point in the history
  • Loading branch information
4nte committed Jan 22, 2023
1 parent c1ba3bd commit dac60a6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
8 changes: 6 additions & 2 deletions git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func Tag(repoName string, tag string) {
}
}

func Commit(repoName string, message string) CommitInfo {
func Commit(repoName string, message string) (CommitInfo, bool) {
repoDir := path.Join(os.TempDir(), repoName)
_, err := os.Stat(repoDir)
if err != nil {
Expand All @@ -143,6 +143,10 @@ func Commit(repoName string, message string) CommitInfo {
cmd.Stderr = os.Stderr
cmd.Stdout = os.Stdout
if err := cmd.Run(); err != nil {
if strings.Contains(err.Error(), "nothing to commit, working tree clean") {
return CommitInfo{}, false
}

panic(fmt.Errorf("failed to commit: %s: %s", repoName, err))
}

Expand All @@ -166,7 +170,7 @@ func Commit(repoName string, message string) CommitInfo {
return CommitInfo{
Timestamp: time.Unix(unix, 0).UTC(),
Hash: commitData[1],
}
}, true
}

func Push(repoName string, branch string) {
Expand Down
8 changes: 6 additions & 2 deletions internal/distribute/distribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,12 @@ func DoWork(gitCfg git.Config, dryRun bool) {
for _, target := range targets {
targetRepoName := fmt.Sprintf("proto-%s", target)
git.AddAll(targetRepoName)
commit := git.Commit(targetRepoName, "add pb files")
log.Printf("commit created: %s", commit.Hash)
if commit, ok := git.Commit(targetRepoName, "add pb files"); ok {
log.Printf("commit created: %s", commit.Hash)
} else {
log.Printf("no commit has been create, there is nothing to commit.")
}

refType, refName := gitCfg.ParseRef()
if refType == git.TagRef {
// Create a git tag
Expand Down

0 comments on commit dac60a6

Please sign in to comment.