# HG changeset patch
# User Dan Villiom Podlaski Christiansen <dan@magenta.dk>
# Date 1625839603 -7200
#      Fri Jul 09 16:06:43 2021 +0200
# Node ID 2c655a70b9b593bc340cac92596c541bda5afdd8
# Parent  d4b7380435c63607e771a00872dd685df0911447
pull: log all bookmark changes on subsequent pulls

diff --git a/hggit/git_handler.py b/hggit/git_handler.py
--- a/hggit/git_handler.py
+++ b/hggit/git_handler.py
@@ -1651,12 +1651,26 @@
             for head, hgsha in self._get_heads(refs).items():
                 bm = head + (self.branch_bookmark_suffix or b'')
 
-                if bm not in bms:
+                if bms.get(bm) == hgsha:
+                    self.ui.note(_(b"bookmark %s is up-to-date\n") % bm)
+
+                elif bm not in bms:
                     # new branch
                     changes.append((bm, hgsha))
+
+                    # only log additions on subsequent pulls
+                    if not self.is_clone:
+                        self.ui.status(_("adding bookmark %s\n") % bm)
+
                 elif self.repo[bms[bm]].isancestorof(self.repo[hgsha]):
                     # fast forward
                     changes.append((bm, hgsha))
+                    self.ui.status(_("updating bookmark %s\n") % bm)
+
+                else:
+                    self.ui.status(
+                        _("not updating diverged bookmark %s\n") % bm,
+                    )
 
             if changes:
                 with self.repo.wlock(), self.repo.lock():
diff --git a/tests/test-branch-bookmark-suffix.t b/tests/test-branch-bookmark-suffix.t
--- a/tests/test-branch-bookmark-suffix.t
+++ b/tests/test-branch-bookmark-suffix.t
@@ -98,6 +98,9 @@
   $ hg pull ../repo.git
   pulling from ../repo.git
   importing 3 git commits
+  updating bookmark branch1_bookmark
+  updating bookmark branch2_bookmark
+  adding bookmark branch3_bookmark
   new changesets 8211cade99e4:faf44fc3a4e8 (3 drafts)
   (run 'hg heads' to see heads)
   $ hg log --graph
@@ -226,6 +229,9 @@
   $ hg -R hgrepo pull repo.git
   pulling from repo.git
   importing 5 git commits
+  adding bookmark branch1_bookmark
+  adding bookmark branch2_bookmark
+  adding bookmark branch3_bookmark
   new changesets 40a840c1f8ae:faf44fc3a4e8 (5 drafts)
   (run 'hg heads' to see heads, 'hg merge' to merge)
 #endif
@@ -239,6 +245,7 @@
   $ hg pull ../repo.git
   pulling from ../repo.git
   importing 1 git commits
+  not updating diverged bookmark branch1_bookmark
   new changesets 895d0307f8b7 (1 drafts)
   (run 'hg update' to get a working copy)
   $ hg log --graph
diff --git a/tests/test-clone.t b/tests/test-clone.t
--- a/tests/test-clone.t
+++ b/tests/test-clone.t
@@ -124,6 +124,9 @@
   $ hg -R hgrepo-shared pull gitrepo
   pulling from gitrepo
   no changes found
+  adding bookmark beta
+  adding bookmark gamma
+  adding bookmark master
   $ hg -R hgrepo-shared push gitrepo
   pushing to gitrepo
   searching for changes
diff --git a/tests/test-git-workflow.t b/tests/test-git-workflow.t
--- a/tests/test-git-workflow.t
+++ b/tests/test-git-workflow.t
@@ -51,6 +51,7 @@
 get things back to hg
   $ hg gimport
   importing 1 git commits
+  updating bookmark master
   new changesets 9f124f3c1fc2 (1 drafts)
   $ hg log --graph --debug | grep -v phase:
   o  changeset:   1:9f124f3c1fc29a14f5eb027c24811b0ac9d5ff10
@@ -117,6 +118,7 @@
   > git commit -m newcommit > /dev/null || echo "git commit error"
   $ hg gimport
   importing 2 git commits
+  updating bookmark master
   new changesets befdecd14df5:3d10b7289d79 (2 drafts)
   $ hg log --graph
   o  changeset:   3:3d10b7289d79
diff --git a/tests/test-incoming.t b/tests/test-incoming.t
--- a/tests/test-incoming.t
+++ b/tests/test-incoming.t
@@ -140,6 +140,8 @@
   $ hg pull | grep -v "adding remote bookmark"
   pulling from $TESTTMP/gitrepo
   importing 3 git commits
+  adding bookmark b1
+  updating bookmark master
   new changesets 7fe02317c63d:248d83ebf472 (3 drafts)
   (run 'hg heads' to see heads, 'hg merge' to merge)
   $ hg incoming | grep -v 'no changes found'
diff --git a/tests/test-multiple-remotes.t b/tests/test-multiple-remotes.t
--- a/tests/test-multiple-remotes.t
+++ b/tests/test-multiple-remotes.t
@@ -30,6 +30,8 @@
   $ hg pull
   pulling from $TESTTMP/gitrepo
   importing 1 git commits
+  adding bookmark master
+  adding bookmark not-master
   new changesets ff7a2f2d8d70 (1 drafts)
   (run 'hg update' to get a working copy)
   pulling from $TESTTMP/repo.git
diff --git a/tests/test-outgoing.t b/tests/test-outgoing.t
--- a/tests/test-outgoing.t
+++ b/tests/test-outgoing.t
@@ -105,6 +105,7 @@
   $ hg pull
   pulling from */gitrepo (glob)
   importing 1 git commits
+  not updating diverged bookmark master
   new changesets 25eed24f5e8f (1 drafts)
   (run 'hg heads' to see heads, 'hg merge' to merge)
   $ hg log --graph
diff --git a/tests/test-phases-draft.t b/tests/test-phases-draft.t
--- a/tests/test-phases-draft.t
+++ b/tests/test-phases-draft.t
@@ -33,6 +33,7 @@
   $ hg pull
   pulling from $TESTTMP/gitrepo
   importing 1 git commits
+  updating bookmark master
   new changesets 7fe02317c63d (1 drafts)
   (run 'hg update' to get a working copy)
   $ hg phase -r master
diff --git a/tests/test-phases-public.t b/tests/test-phases-public.t
--- a/tests/test-phases-public.t
+++ b/tests/test-phases-public.t
@@ -79,6 +79,7 @@
   $ hg pull -r master other
   pulling from $TESTTMP/gitrepo/.git
   importing 1 git commits
+  updating bookmark master
   new changesets 7fe02317c63d
   1 local changesets published
   (run 'hg update' to get a working copy)
@@ -86,6 +87,7 @@
   $ hg pull -r master other
   pulling from $TESTTMP/gitrepo/.git
   importing 1 git commits
+  updating bookmark master
   new changesets 7fe02317c63d (1 drafts)
   (run 'hg update' to get a working copy)
 #endif
@@ -97,6 +99,7 @@
   $ hg pull
   pulling from $TESTTMP/gitrepo
   importing 2 git commits
+  adding bookmark not-master
   new changesets ca33a262eb46:03769a650ded (1 drafts)
   1 local changesets published
   (run 'hg update' to get a working copy)
@@ -104,6 +107,7 @@
   $ hg pull
   pulling from $TESTTMP/gitrepo
   importing 2 git commits
+  adding bookmark not-master
   new changesets ca33a262eb46:03769a650ded (1 drafts)
   2 local changesets published
   (run 'hg update' to get a working copy)
diff --git a/tests/test-pull-after-rebase.t b/tests/test-pull-after-rebase.t
--- a/tests/test-pull-after-rebase.t
+++ b/tests/test-pull-after-rebase.t
@@ -87,6 +87,7 @@
   $ hg pull
   pulling from $TESTTMP/repo.git
   importing 1 git commits
+  adding bookmark otherbranch
   1 new orphan changesets
   new changesets f4bd265a9d39 (1 drafts)
   (run 'hg heads' to see heads, 'hg merge' to merge)
@@ -118,6 +119,7 @@
   $ hg pull
   pulling from $TESTTMP/repo.git
   no changes found
+  not updating diverged bookmark otherbranch
   $ hg state
   *  otherbranch tip 4:f4bd265a9d39e5c4da2c0a752de5ea70335199c5
   |  add gamma
diff --git a/tests/test-pull-after-strip.t b/tests/test-pull-after-strip.t
--- a/tests/test-pull-after-strip.t
+++ b/tests/test-pull-after-strip.t
@@ -78,6 +78,7 @@
   $ hg pull -r beta | grep -v "adding remote bookmark"
   pulling from $TESTTMP/gitrepo
   importing 2 git commits
+  updating bookmark beta
   new changesets 7fe02317c63d:cc1e605d90db (2 drafts)
   (run 'hg update' to get a working copy)
   $ hg log --graph
diff --git a/tests/test-pull.t b/tests/test-pull.t
--- a/tests/test-pull.t
+++ b/tests/test-pull.t
@@ -35,6 +35,7 @@
   $ hg -R hgrepo pull -r t_alpha
   pulling from $TESTTMP/gitrepo
   importing 1 git commits
+  adding bookmark master
   new changesets ff7a2f2d8d70 (1 drafts)
   (run 'hg update' to get a working copy)
   $ hg -R hgrepo update t_alpha
@@ -62,6 +63,7 @@
   $ hg -R hgrepo pull -r epsilon
   pulling from $TESTTMP/gitrepo
   no changes found
+  adding bookmark epsilon
 
 pull something that doesn't exist
   $ hg -R hgrepo pull -r kaflaflibob
@@ -81,6 +83,7 @@
   $ hg -R hgrepo pull -r beta
   pulling from $TESTTMP/gitrepo
   importing 1 git commits
+  adding bookmark beta
   new changesets 7fe02317c63d (1 drafts)
   (run 'hg update' to get a working copy)
   $ hg -R hgrepo log --graph --template=phases
@@ -128,6 +131,8 @@
   $ hg -R hgrepo pull
   pulling from $TESTTMP/gitrepo
   importing 2 git commits
+  adding bookmark delta
+  updating bookmark master
   new changesets 678ebee93e38:6f898ad1f3e1 (2 drafts)
   (run 'hg heads' to see heads, 'hg merge' to merge)
   $ hg -R hgrepo log --graph --template=phases
@@ -181,6 +186,7 @@
   $ hg -R hgrepo pull --config git.pull-prune-remote-branches=false
   pulling from $TESTTMP/gitrepo
   importing 1 git commits
+  updating bookmark master
   new changesets a02330f767a4 (1 drafts)
   (run 'hg update' to get a working copy)
   $ hg -R hgrepo tags | grep default/beta
@@ -250,6 +256,8 @@
   $ hg -R hgrepo pull -r 'releases/*'
   pulling from $TESTTMP/gitrepo
   importing 2 git commits
+  adding bookmark releases/v1
+  adding bookmark releases/v2
   new changesets 218b2d0660d3:a3f95e150b0a (2 drafts)
   (run 'hg heads .' to see heads, 'hg merge' to merge)
   $ hg -R hgrepo log --graph
@@ -359,6 +367,7 @@
   $ hg -R hgrepo pull
   pulling from $TESTTMP/gitrepo
   importing 3 git commits
+  updating bookmark master
   new changesets 49713da8f665:e103a73f33be (3 drafts)
   (run 'hg heads .' to see heads, 'hg merge' to merge)
   $ hg -R hgrepo heads
diff --git a/tests/test-push.t b/tests/test-push.t
--- a/tests/test-push.t
+++ b/tests/test-push.t
@@ -74,6 +74,7 @@
   $ hg pull 2>&1 | grep -v 'divergent bookmark'
   pulling from $TESTTMP/gitrepo
   importing 1 git commits
+  not updating diverged bookmark master
   new changesets 25eed24f5e8f (1 drafts)
   (run 'hg heads' to see heads, 'hg merge' to merge)
 TODO shouldn't need to do this since we're (in theory) pushing master explicitly,
diff --git a/tests/test-serve-ci.t b/tests/test-serve-ci.t
--- a/tests/test-serve-ci.t
+++ b/tests/test-serve-ci.t
@@ -89,6 +89,7 @@
   $ hg -R repo-git pull -u
   pulling from git://git-server/repo.git
   importing 1 git commits
+  adding bookmark master
   new changesets fa22339f4ab8 (1 drafts)
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
 
@@ -108,6 +109,7 @@
   >    pull -u
   pulling from http://git-server/repo.git
   importing 1 git commits
+  adding bookmark master
   new changesets fa22339f4ab8 (1 drafts)
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
 
diff --git a/tests/test-subrepos.t b/tests/test-subrepos.t
--- a/tests/test-subrepos.t
+++ b/tests/test-subrepos.t
@@ -102,6 +102,7 @@
   $ hg pull
   pulling from $TESTTMP/gitrepo1
   importing 1 git commits
+  updating bookmark master
   new changesets [0-9a-f]{12,12} \(1 drafts\) (re)
   (run 'hg update' to get a working copy)
   $ hg checkout -C
diff --git a/tests/test-transactions.t b/tests/test-transactions.t
--- a/tests/test-transactions.t
+++ b/tests/test-transactions.t
@@ -124,6 +124,7 @@
   new changesets 1c8407413fa3:abc468b9e51b (25 drafts)
   new changesets 217c308baf47:d5d14eeedd08 (25 drafts)
   new changesets d9807ef6abcb:4678067bd500 (25 drafts)
+  adding bookmark master
   new changesets c31a154888bb:eda59117ba04 (25 drafts)
   (run 'hg update' to get a working copy)
 
@@ -142,6 +143,7 @@
   new changesets 1c8407413fa3:abc468b9e51b
   new changesets 217c308baf47:d5d14eeedd08
   new changesets d9807ef6abcb:4678067bd500
+  updating bookmark master
   new changesets c31a154888bb:eda59117ba04
   (run 'hg update' to get a working copy)