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
This commit is contained in:
Mark Nauwelaerts
2016-07-09 09:39:50 +02:00
parent b852ee18b2
commit fd210eb002
2 changed files with 42 additions and 2 deletions

View File

@@ -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)

View File

@@ -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*" &&