changeset 24858:a99931201d1b stable

subrepo: don't write .hgsubstate lines with empty subrepo state (issue4622) The '' that is used to represent the state of a not-yet-committed subrepo cannot be written to the file, because the code that parses the file splits on ' ' and expects two parts. Given that the .hgsubstate file is automatically rewritten on commit, it seems a little strange that the file is written out during a merge.
author Matt Harbison <matt_harbison@yahoo.com>
date Fri, 24 Apr 2015 23:23:55 -0400
parents d8505bfe4825
children 64e3f97bdf08
files mercurial/subrepo.py tests/test-subrepo.t
diffstat 2 files changed, 41 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/subrepo.py	Sat Apr 25 23:54:31 2015 -0400
+++ b/mercurial/subrepo.py	Fri Apr 24 23:23:55 2015 -0400
@@ -153,7 +153,8 @@
 
 def writestate(repo, state):
     """rewrite .hgsubstate in (outer) repo with these subrepo states"""
-    lines = ['%s %s\n' % (state[s][1], s) for s in sorted(state)]
+    lines = ['%s %s\n' % (state[s][1], s) for s in sorted(state)
+                                                if state[s][1] != nullstate[1]]
     repo.wwrite('.hgsubstate', ''.join(lines), '')
 
 def submerge(repo, wctx, mctx, actx, overwrite):
--- a/tests/test-subrepo.t	Sat Apr 25 23:54:31 2015 -0400
+++ b/tests/test-subrepo.t	Fri Apr 24 23:23:55 2015 -0400
@@ -1026,6 +1026,45 @@
   no changes found
   [1]
 
+Check that merge of a new subrepo doesn't write the uncommitted state to
+.hgsubstate (issue4622)
+
+  $ hg init issue1852a/addedsub
+  $ echo zzz > issue1852a/addedsub/zz.txt
+  $ hg -R issue1852a/addedsub ci -Aqm "initial ZZ"
+
+  $ hg clone issue1852a/addedsub issue1852d/addedsub
+  updating to branch default
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
+  $ echo def > issue1852a/sub/repo/foo
+  $ hg -R issue1852a ci -SAm 'tweaked subrepo'
+  adding tmp/sub/repo/foo_p
+  committing subrepository sub/repo (glob)
+
+  $ echo 'addedsub = addedsub' >> issue1852d/.hgsub
+  $ echo xyz > issue1852d/sub/repo/foo
+  $ hg -R issue1852d pull -u
+  pulling from $TESTTMP/issue1852a (glob)
+  searching for changes
+  adding changesets
+  adding manifests
+  adding file changes
+  added 1 changesets with 2 changes to 2 files
+   subrepository sub/repo diverged (local revision: f42d5c7504a8, remote revision: 46cd4aac504c)
+  (M)erge, keep (l)ocal or keep (r)emote? m
+  pulling subrepo sub/repo from $TESTTMP/issue1852a/sub/repo (glob)
+  searching for changes
+  adding changesets
+  adding manifests
+  adding file changes
+  added 1 changesets with 1 changes to 1 files
+   subrepository sources for sub/repo differ (glob)
+  use (l)ocal source (f42d5c7504a8) or (r)emote source (46cd4aac504c)? l
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ cat issue1852d/.hgsubstate
+  f42d5c7504a811dda50f5cf3e5e16c3330b87172 sub/repo
+
 Check status of files when none of them belong to the first
 subrepository: