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

Clean up local dangling reference to deleted remote branches. #8487

Closed
wants to merge 1 commit into from

Conversation

asakatida
Copy link

@asakatida asakatida commented Dec 22, 2023

Fixes #8515

@asakatida asakatida requested a review from a team as a code owner December 22, 2023 18:35
@asakatida asakatida requested review from andyfeller and removed request for a team December 22, 2023 18:35
@cliAutomation
Copy link
Collaborator

Hi! Thanks for the pull request. Please ensure that this change is linked to an issue by mentioning an issue number in the description of the pull request. If this pull request would close the issue, please put the word 'Fixes' before the issue number somewhere in the pull request body. If this is a tiny change like fixing a typo, feel free to ignore this message.

@cliAutomation cliAutomation added the external pull request originating outside of the CLI core team label Dec 22, 2023
@cliAutomation cliAutomation added this to Needs review 🤔 in The GitHub CLI Dec 22, 2023
pkg/cmd/pr/merge/merge.go Outdated Show resolved Hide resolved
@samcoe
Copy link
Contributor

samcoe commented Jan 2, 2024

@asakatida Thanks for the contribution. Can you please elaborate in the PR description what this PR is trying to achieve and link it to an open issue. Without this context we will not be able to review the PR.

@asakatida
Copy link
Author

@samcoe #8515 has been filed for you

Copy link
Contributor

@andyfeller andyfeller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@asakatida : Thank you for this PR to improve the GitHub CLI experience! Really appreciate changes for the tests, too ❤️

I have only 1 concern with regards to separation of concerns in the changes but fortunately I think it is something we can work through to get these changes through.

git/client.go Outdated Show resolved Hide resolved
@RoseHuynh92

This comment was marked as spam.

@@ -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`,
Copy link
Author

Choose a reason for hiding this comment

The 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

return err
{
track := fmt.Sprintf("origin/%s", branch)
args := []string{"branch", "-d", "-r", track}
Copy link
Member

Choose a reason for hiding this comment

The 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 git branch -D <branch> followed by git branch -d -r <branch>. What about git branch -D -r <branch> doesn't work?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

git branch -D -r <branch> will only delete the remote branch. It will not touch the local branch.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahhh! I naively assumed that -r was additive! I guess it makes sense because a local branch main isn't necessarily related to remote tracking branches e.g. origin/main or upstream/main (although I think in some cases git manages a 1:1 relationship)

if err != nil {
return err
{
track := fmt.Sprintf("origin/%s", branch)
Copy link
Member

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?

Copy link
Contributor

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.

@williammartin
Copy link
Member

@asakatida this PR seems to have gone stale some time ago; perhaps the next steps were not clear since Sam left GitHub around this time. Is this something you are still interested in getting merged?

@asakatida
Copy link
Author

@williammartin the next steps were clear, but at that point it was easier to migrate my workflows away from using this client. So, not something that needs merging from my end anymore

@williammartin
Copy link
Member

Got it, thanks for trying and good luck. I'll leave the issue open in case anyone else wants to address it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
external pull request originating outside of the CLI core team
Projects
No open projects
The GitHub CLI
  
Needs review 🤔
Development

Successfully merging this pull request may close these issues.

gh operations that delete the remote branch leave a dangling reference in the local git repo
7 participants