Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: prevent orphaned commit when patching files during a tag #219

Merged
merged 3 commits into from
Jan 3, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading