diff --git a/mercurial/subrepo.py b/mercurial/subrepo.py --- a/mercurial/subrepo.py +++ b/mercurial/subrepo.py @@ -678,6 +678,25 @@ class gitsubrepo(object): # 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, diff --git a/tests/test-subrepo-git.t b/tests/test-subrepo-git.t --- a/tests/test-subrepo-git.t +++ b/tests/test-subrepo-git.t @@ -81,3 +81,93 @@ update to previous substate 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