-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
Clean up local dangling reference to deleted remote branches. #8487
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -336,14 +336,28 @@ func (c *Client) DeleteLocalTag(ctx context.Context, tag string) error { | |
} | ||
|
||
func (c *Client) DeleteLocalBranch(ctx context.Context, branch string) error { | ||
args := []string{"branch", "-D", branch} | ||
cmd, err := c.Command(ctx, args...) | ||
if err != nil { | ||
return err | ||
{ | ||
args := []string{"branch", "-D", branch} | ||
cmd, err := c.Command(ctx, args...) | ||
if err != nil { | ||
return err | ||
} | ||
_, err = cmd.Output() | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
_, err = cmd.Output() | ||
if err != nil { | ||
return err | ||
{ | ||
track := fmt.Sprintf("origin/%s", branch) | ||
args := []string{"branch", "-d", "-r", track} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @asakatida I'm missing something here. Why do you think we need to run There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ahhh! I naively assumed that |
||
cmd, err := c.Command(ctx, args...) | ||
if err != nil { | ||
return err | ||
} | ||
_, err = cmd.Output() | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -608,7 +608,7 @@ func TestClientDeleteLocalBranch(t *testing.T) { | |
}{ | ||
{ | ||
name: "delete local branch", | ||
wantCmdArgs: `path/to/git branch -D trunk`, | ||
wantCmdArgs: `path/to/git branch -D trunk path/to/git branch -d -r origin/trunk`, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this still leaves this test erroring and I am not clear on how to correct the expectations |
||
}, | ||
{ | ||
name: "git error", | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm, I think we're going to need to inject something here. We can't know for sure that their remote is called
origin
. @samcoe can you advise?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah we will want to make sure that we have the correct remote name. Perhaps that is a n indication that we should create a new method
DeleteLocalTrackingBranch
that takes in the remote name and the remote branch name.Or we reverse course and go with
git push --delete
since it only requires the branch name and automatically figures out the tracking branch to delete based on the push URL.