Skip to content

Commit

Permalink
fix: prevent orphaned commit when patching files during a tag
Browse files Browse the repository at this point in the history
  • Loading branch information
purpleclay committed Jan 3, 2025
1 parent 0422f27 commit 68b11c8
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions cmd/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,28 @@ func pushAll(gitc *git.Client, tags []string, opts *Options) error {
return nil
}

_, err := gitc.Push(git.WithRefSpecs(tags...))
opts.Logger.Debug("pushed all changes to origin", "tags", tags)
// NOTE: this won't work when if the repository has a detached HEAD
branch, err := gitc.Exec("git branch --show-current")
if err != nil {
return err
}

notPushed, err := gitc.Exec(fmt.Sprintf("git log %s --not --remotes", branch))
if err != nil {
return err
}

if notPushed == "" && len(tags) == 0 {
opts.Logger.Debug("nothing to push to remote")
return nil
}

var refs []string
refs = append(refs, branch)
refs = append(refs, tags...)

_, err = gitc.Push(git.WithRefSpecs(refs...))
opts.Logger.Debug("pushed all changes to remote", "ref_specs", refs)
return err
}

Expand Down

0 comments on commit 68b11c8

Please sign in to comment.