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

Set av-pushed-remote and av-pushed-ref on push #237

Merged
merged 2 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions internal/actions/pr.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,12 @@ func CreatePullRequest(
if _, err := repo.Git(pushFlags...); err != nil {
return nil, errors.WrapIf(err, "failed to push")
}
if err := repo.BranchSetConfig(opts.BranchName, "av-pushed-remote", "origin"); err != nil {
return nil, err
}
if err := repo.BranchSetConfig(opts.BranchName, "av-pushed-ref", fmt.Sprintf("refs/heads/%s", opts.BranchName)); err != nil {
return nil, err
}
} else {
_, _ = fmt.Fprint(os.Stderr,
" - skipping push to GitHub",
Expand Down
6 changes: 6 additions & 0 deletions internal/actions/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@ func Push(repo *git.Repo, branchName string, opts PushOpts) error {
}
return errors.WrapIff(err, "failed to push branch %q", branchName)
}
if err := repo.BranchSetConfig(branchName, "av-pushed-remote", "origin"); err != nil {
return err
}
if err := repo.BranchSetConfig(branchName, "av-pushed-ref", fmt.Sprintf("refs/heads/%s", branchName)); err != nil {
return err
}
_, _ = fmt.Fprint(os.Stderr,
colors.Success("okay"), "\n",
)
Expand Down
12 changes: 12 additions & 0 deletions internal/git/branch.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package git

import "fmt"

// BranchDelete deletes the given branches (equivalent to `git branch -D`).
func (r *Repo) BranchDelete(names ...string) error {
_, err := r.Run(&RunOpts{
Expand All @@ -8,3 +10,13 @@ func (r *Repo) BranchDelete(names ...string) error {
})
return err
}

// BranchSetConfig sets a config on the given branch (equivalent to `git config
// branch.<branch>.<key> <value>`).
func (r *Repo) BranchSetConfig(name, key, value string) error {
_, err := r.Run(&RunOpts{
Args: []string{"config", fmt.Sprintf("branch.%s.%s", name, key), value},
ExitError: true,
})
return err
}