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

"git remote prune [remotename]" does not prune bookmarks #15

Open
TamsynUlthara opened this issue Sep 8, 2014 · 11 comments
Open

"git remote prune [remotename]" does not prune bookmarks #15

TamsynUlthara opened this issue Sep 8, 2014 · 11 comments

Comments

@TamsynUlthara
Copy link

When a bookmark has been deleted [1] from the Mercurial remote, running git remote prune [remotename] after a fetch does not prune the deleted bookmark branches from the remote.

[1] Externally, since we can't delete them via git-remote-hg.

@nathanielcook
Copy link

Is there any workaround to get rid of the bookmark from the list of remote branches without re-cloning the entire repository?

@TamsynUlthara
Copy link
Author

I haven't been using git-remote-hg anymore; it looks like a dead project, and I've since sworn off working on anything that's based in Mercurial. ;-)

@fingolfin
Copy link
Contributor

My fork https://github.com/fingolfin/git-remote-hg is actually quite alive :)

However, I also do not much more than fixing serious bugs and ensuring it stays compatible with new Mercurial releases for now. This is because I do not need it for major projects anymore, as I used to. Still, I feel that this project is quite useful for many people, so I try to fix at least the worst issues.

Regarding this issue: I think the problem is that when a Mercurial bookmark is deleted on the server, this change is not reflected in clones. In particular, there seems to be no analog to git fetch --prune.

So, to fix this, it will likely be necessary to implement the corresponding logic. I.e. fetch a list of remote bookmarks, then delete any local bookmarks that are not on the remote -- and only then begin exporting everything to git.

@nathanielcook
Copy link

@fingolfin I use your fork on OSX. It works great, so thank you for your work on that. If you ever get some extra time to fix it so that it clones and checks out correctly on Windows that would be awesome. Currently I am limited to OSX. The bookmarks issue for me is not a big deal at the moment since I don't normally use bookmarks.

@nathanielcook
Copy link

@fingolfin After a bookmark is deleted from the hg remote, what exactly is necessary to manually remove the bookmark and bookmark branch (so as to avoid having to re-clone)? I did the following:

  1. deleted the bookmark entry from .git/hg/origin/marks-hg
  2. deleted the entry from .git/hg/origin/clone/.hg/bookmarks
  3. did a git fetch --prune in git

...and the bookmark branch went away, so that seems to have worked. Is there anything else I should do, or is there anything wrong with the steps I took above?

By the way, my main problem is that, when I create a branch in git, sometimes I forget to add the branches/ prefix. So when I push it creates a bookmark that I have to remove. It would be nice to somehow disallow adding a branch without the branches/ prefix.

@fingolfin
Copy link
Contributor

@nathanielcook THat sounds about right to me. The "problem" is to automate that. It actually shouldn't be that hard, but "somebody" has to do it (and ideally also write test cases for it ;-).

I am not quite sure what you mean with "disallowing" branches without the branches/ prefix -- the remote helper cannot control what branches you create. Aha, but perhaps you mean that it should refuse to let you push branches that have a name without branches/ prefix? Hmmm, I guess one could add a config option to do that... Feel free to file a feature request at my branch (but I am not promising anything, this project cannot be priority for me right now, sorry)

@nathanielcook
Copy link

@fingolfin Yes; I meant to say block pushing branches without the branches/ prefix.

Appreciate all that you've done already! I wish I was a python guy; I have looked at potentially modifying the script myself. :-)

@fingolfin
Copy link
Contributor

@nathanielcook I am not really a python guy myself, but it's easy enough to pick up ;-). Anyway, I think the place you need to look at is updatebookmarks. It reads bookmarks available on the remote, and updates the local bookmarks from that. In principle, one should be able to use that to remove local bookmarks that are gone on the remote. But I have not thought this fully through -- maybe this would have undesirable side effects...

@felipec
Copy link
Owner

felipec commented May 17, 2016

This is a limitation of Git's core.

You can manually delete all the refs:

git for-each-ref --format='delete %(refname)' refs/remotes/origin

And pass that to git update-ref --stdin, however, you need to remove the HEAD.

mnauw added a commit to mnauw/git-remote-hg that referenced this issue Aug 1, 2016
... rather than only adding remote ones locally and never deleting.
In particular, makes fetch --prune work.

Fixes felipec#15
@mnauw
Copy link
Contributor

mnauw commented Aug 1, 2016

I am not quite sure what git core is to blame for here. As mentioned in previous comments, what happens is that bookmarks are only fetched from remote repo and then added to the local proxy clone, but bookmarks are never deleted from the proxy clone when deleted on the remote.

So, it is/was a matter of automating bookmark sync, and the above commit does just that after which fetch --prune works as expected.

@felipec
Copy link
Owner

felipec commented Jun 18, 2019

So, it is/was a matter of automating bookmark sync, and the above commit does just that after which fetch --prune works as expected.

Yes, and that patch is a hack. A remote helper in't supposed to be calling other git commands. There should be a way for the remote helper to tell git fast-import to delete those branches. I believe in recent versions of Git there is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants