From fd210eb002f279731cfbea6bc21e340713a6be9a Mon Sep 17 00:00:00 2001 From: Mark Nauwelaerts Date: Sat, 9 Jul 2016 09:39:50 +0200 Subject: [PATCH] Also ensure 2-way sync of remote bookmarks to proxy ... rather than only adding remote ones locally and never deleting. In particular, makes fetch --prune work. Fixes felipec/git-remote-hg#15 --- git-remote-hg | 15 +++++++++++++-- test/main.t | 29 +++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/git-remote-hg b/git-remote-hg index 81ef78f..f5eb575 100755 --- a/git-remote-hg +++ b/git-remote-hg @@ -371,8 +371,19 @@ def fixup_user(user): def updatebookmarks(repo, peer): remotemarks = peer.listkeys('bookmarks') - localmarks = repo._bookmarks + # delete bookmarks locally that disappeared on remote + localmarks = bookmarks.listbookmarks(repo) + remote = set(remotemarks.keys()) + local = set(localmarks.keys()) + for bmark in local - remote: + bookmarks.pushbookmark(repo, bmark, localmarks[bmark], '') + # also delete private ref + pbookmark = '%s/bookmarks/%s' % (prefix, bmark) + subprocess.call(['git', 'update-ref', '-d', pbookmark]) + + # now add or update remote bookmarks to local, if any + localmarks = repo._bookmarks if not remotemarks: return @@ -1320,8 +1331,8 @@ def main(args): dry_run = False notes = set() - repo = get_repo(url, alias) prefix = 'refs/hg/%s' % alias + repo = get_repo(url, alias) if not is_tmp: fix_path(alias, peer or repo, url) diff --git a/test/main.t b/test/main.t index ca50f79..11667b3 100755 --- a/test/main.t +++ b/test/main.t @@ -783,6 +783,35 @@ test_expect_success 'remote double failed push' ' test_expect_code 1 git push ) ' +test_expect_success 'fetch prune' ' + test_when_finished "rm -rf gitrepo hgrepo" && + + ( + hg init hgrepo && + cd hgrepo && + echo zero > content && + hg add content && + hg commit -m zero && + echo feature-a > content && + hg commit -m feature-a + hg bookmark feature-a + ) && + + git clone "hg::hgrepo" gitrepo && + check gitrepo origin/feature-a feature-a && + + ( + cd hgrepo && + hg bookmark -d feature-a + ) && + + ( + cd gitrepo && + git fetch --prune origin + git branch -a > out && + ! grep feature-a out + ) +' test_expect_success 'clone remote with null bookmark, then push' ' test_when_finished "rm -rf gitrepo* hgrepo*" &&