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

detect and alert (or otherwise handle) when local branch is out of sync with remote #134

Open
cabbey opened this issue Jun 2, 2023 · 3 comments
Labels
enhancement New feature or request

Comments

@cabbey
Copy link

cabbey commented Jun 2, 2023

When the remote repo has branches that are not in sync with the local one, the tool gives a very clear warning:

Remote 'cabbey' is not up to date with 1 local branch(es):
  - main

This will likely impair detection of merged branches for remote 'cabbey'.
Please consider getting it back in sync by running
  $ git push cabbey main

and then invoking git-delete-merged-branches, again.

However when the opposite is true, you just get a warning and error from git and an overall failure:

warning: not deleting branch 'improve-encryption' that is not yet merged to
         'refs/remotes/cabbey/improve-encryption', even though it is merged to HEAD.
error: The branch 'improve-encryption' is not fully merged.
If you are sure you want to delete it, run 'git branch -D improve-encryption'.
Deleted branch bye-render (was 30e49492767).
Deleted branch crop-vs-orientation (was 95b84c24f6d).
...
Error: Command 'git branch --delete bye-render crop-vs-orientation improve-encryption ...' returned non-zero exit status 1.

It would be nice if the tool could detect that this is going to happen and either omit those branches from the delete command and explain to the user that they are not in sync. (In my case there had been a last minute merge of main into the branch, which was then merged to main and pushed up to upstream, but was not pushed to my personal fork. I just did a git branch -D improve-encryption and re-ran the tool.)

@hartwork
Copy link
Owner

hartwork commented Jun 2, 2023

Hi @cabbey for each branch we would need to do a git cherry against all existing remotes I suppose? That doesn't seem ideal, worth the runtime, worth the implementation effort. Any other ideas to detect this situation?

@hartwork hartwork added the enhancement New feature or request label Jun 2, 2023
@cabbey
Copy link
Author

cabbey commented Jun 2, 2023

I don't think you would have to do quite that much. Assuming you have fetched the remote it should just be a matter of comparing what hash is used by refs/heads/foo and refs/remotes/target/foo. At least in the majority case where they match that should be fast. Some additional overhead maybe needed to understand WHY they don't match, as it could be either way around, either local or remote may have changes that the other doesn't, or worse: both. I'd think all three cases should be handled the same though... don't try to delete it on the remote side as it's potentially not what you compared to locally to determine if it was fully merged.

@hartwork
Copy link
Owner

hartwork commented Jun 2, 2023

@cabbey comparing hashes is an interesting idea. I'll sleep over this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants