subrepo: allow git subrepos to push and merge
(master branch only)
gitsubrepo based on patch from David Soria Parra:
http://bitbucket.org/segv/davids-poor-git-subrepo-attempt/
--- a/mercurial/subrepo.py Sun Nov 14 18:20:13 2010 -0500
+++ b/mercurial/subrepo.py Sun Nov 14 18:22:33 2010 -0500
@@ -678,6 +678,25 @@
# circumstances
return self._gitstate()
+ def merge(self, state):
+ source, revision, kind = state
+ self._fetch(source, revision)
+ base = self._gitcommand(['merge-base', revision,
+ self._state[1]]).strip()
+ if base == revision:
+ self.get(state) # fast forward merge
+ elif base != self._state[1]:
+ self._gitcommand(['merge', '--no-commit', revision])
+
+ def push(self, force):
+ cmd = ['push']
+ if force:
+ cmd.append('--force')
+ # as subrepos have no notion of "where to push to" we
+ # assume origin master. This is git's default
+ self._gitcommand(cmd + ['origin', 'master', '-q'])
+ return True
+
types = {
'hg': hgsubrepo,
'svn': svnsubrepo,
--- a/tests/test-subrepo-git.t Sun Nov 14 18:20:13 2010 -0500
+++ b/tests/test-subrepo-git.t Sun Nov 14 18:22:33 2010 -0500
@@ -81,3 +81,93 @@
path s
source ../gitroot
revision da5f5b1d8ffcf62fb8327bcd3c89a4367a6018e7
+
+make $GITROOT pushable, by replacing it with a clone with nothing checked out
+
+ $ cd ..
+ $ git clone gitroot gitrootbare --bare -q
+ $ rm -rf gitroot
+ $ mv gitrootbare gitroot
+
+clone root, make local change
+
+ $ cd t
+ $ hg clone . ../ta
+ updating to branch default
+ cloning subrepo s
+ 3 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
+ $ cd ../ta
+ $ echo ggg >> s/g
+ $ hg commit -m ggg
+ committing subrepository $TESTTMP/ta/s
+ $ hg debugsub
+ path s
+ source ../gitroot
+ revision 79695940086840c99328513acbe35f90fcd55e57
+
+clone root separately, make different local change
+
+ $ cd ../t
+ $ hg clone . ../tb
+ updating to branch default
+ cloning subrepo s
+ 3 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
+ $ cd ../tb/s
+ $ echo f > f
+ $ git add f
+ $ cd ..
+
+ $ hg commit -m f
+ committing subrepository $TESTTMP/tb/s
+ $ hg debugsub
+ path s
+ source ../gitroot
+ revision aa84837ccfbdfedcdcdeeedc309d73e6eb069edc
+
+user b push changes
+
+ $ hg push
+ pushing to $TESTTMP/t
+ searching for changes
+ adding changesets
+ adding manifests
+ adding file changes
+ added 1 changesets with 1 changes to 1 files
+
+user a pulls, merges, commits
+
+ $ cd ../ta
+ $ hg pull
+ pulling from $TESTTMP/t
+ searching for changes
+ adding changesets
+ adding manifests
+ adding file changes
+ added 1 changesets with 1 changes to 1 files (+1 heads)
+ (run 'hg heads' to see heads, 'hg merge' to merge)
+ $ hg merge
+ Automatic merge went well; stopped before committing as requested
+ pulling subrepo s
+ 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+ (branch merge, don't forget to commit)
+ $ cat s/f
+ f
+ $ cat s/g
+ g
+ gg
+ ggg
+ $ hg commit -m 'merge'
+ committing subrepository $TESTTMP/ta/s
+ $ hg debugsub
+ path s
+ source ../gitroot
+ revision f47b465e1bce645dbf37232a00574aa1546ca8d3
+ $ hg push
+ pushing to $TESTTMP/t
+ searching for changes
+ adding changesets
+ adding manifests
+ adding file changes
+ added 2 changesets with 2 changes to 1 files