commit: don't change phases for preexisting commits stable
authorDan Villiom Podlaski Christiansen <danchr@gmail.com>
Thu, 29 Oct 2020 07:51:13 +0100
branchstable
changeset 45757 067707e026b4
parent 45755 8ed69bd42f10
child 45758 14ac6a74e7e7
commit: don't change phases for preexisting commits I noticed when pulling with hg-git in a repository that already had the changes, but pulled from another Mercurial repository. This meant that hg-git would re-create exact matches of the changesets, and if they were public, they'd get reverted to drafts. Differential Revision: https://phab.mercurial-scm.org/D9253
mercurial/commit.py
tests/test-phases.t
--- a/mercurial/commit.py	Thu Oct 22 18:38:41 2020 -0400
+++ b/mercurial/commit.py	Thu Oct 29 07:51:13 2020 +0100
@@ -79,6 +79,9 @@
         if repo.changelog._copiesstorage == b'extra':
             extra = _extra_with_copies(repo, extra, files)
 
+        # save the tip to check whether we actually committed anything
+        oldtip = repo.changelog.tiprev()
+
         # update changelog
         repo.ui.note(_(b"committing changelog\n"))
         repo.changelog.delayupdate(tr)
@@ -99,7 +102,11 @@
         )
         # set the new commit is proper phase
         targetphase = subrepoutil.newcommitphase(repo.ui, ctx)
-        if targetphase:
+
+        # prevent unmarking changesets as public on recommit
+        waspublic = oldtip == repo.changelog.tiprev() and not repo[n].phase()
+
+        if targetphase and not waspublic:
             # retract boundary do not alter parent changeset.
             # if a parent have higher the resulting phase will
             # be compliant anyway
--- a/tests/test-phases.t	Thu Oct 22 18:38:41 2020 -0400
+++ b/tests/test-phases.t	Thu Oct 29 07:51:13 2020 +0100
@@ -999,3 +999,55 @@
      date:        Thu Jan 01 00:00:00 1970 +0000
      summary:     A
   
+  $ cd ..
+
+Recommitting an exact match of a public commit shouldn't change it to
+draft:
+
+  $ cd initialrepo
+  $ hg phase -r 2
+  2: public
+  $ hg up -C 1
+  0 files updated, 0 files merged, 4 files removed, 0 files unresolved
+  $ mkcommit C
+  created new head
+  $ hg phase -r 2
+  2: public
+
+Same, but for secret:
+
+  $ hg up 7
+  3 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ mkcommit F -s
+  test-debug-phase: new rev 8:  x -> 2
+  test-hook-close-phase: de414268ec5ce2330c590b942fbb5ff0b0ca1a0a:   -> secret
+  $ hg up 7
+  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  $ hg phase
+  7: draft
+  $ mkcommit F
+  test-debug-phase: new rev 8:  x -> 2
+  test-hook-close-phase: de414268ec5ce2330c590b942fbb5ff0b0ca1a0a:   -> secret
+  $ hg phase -r tip
+  8: secret
+
+But what about obsoleted changesets?
+
+  $ hg up 4
+  0 files updated, 0 files merged, 2 files removed, 0 files unresolved
+  $ mkcommit H
+  test-debug-phase: new rev 5:  x -> 2
+  created new head
+  test-hook-close-phase: a030c6be5127abc010fcbff1851536552e6951a8:   -> secret
+  $ hg phase -r 5
+  5: secret
+  $ hg par
+  changeset:   5:a030c6be5127
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  obsolete:    pruned
+  summary:     H
+  
+  $ hg up tip
+  2 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  $ cd ..