Commits

Eric Roshan Eisner committed a913343

subrepo: cloning and updating of git subrepos

gitsubrepo based on patch from David Soria Parra:
http://bitbucket.org/segv/davids-poor-git-subrepo-attempt/

  • Participants
  • Parent commits 2b73a32

Comments (0)

Files changed (2)

mercurial/subrepo.py

         # TODO add git version check.
         self._state = state
         self._ctx = ctx
+        self._relpath = path
         self._path = ctx._repo.wjoin(path)
         self._ui = ctx._repo.ui
 
         out, code = self._gitdir(['cat-file', '-e', revision])
         return code == 0
 
+    def _fetch(self, source, revision):
+        if not os.path.exists('%s/.git' % self._path):
+            self._ui.status(_('cloning subrepo %s\n') % self._relpath)
+            self._gitnodir(['clone', source, self._path])
+        if self._githavelocally(revision):
+            return
+        self._ui.status(_('pulling subrepo %s\n') % self._relpath)
+        self._gitcommand(['fetch', '--all', '-q'])
+        if not self._githavelocally(revision):
+            raise util.Abort(_("revision %s does not exist in subrepo %s\n") %
+                               (revision, self._path))
+
     def dirty(self):
         if self._state[1] != self._gitstate(): # version checked out changed?
             return True
                                     '--untracked-files=no'])
         return bool(changed.strip())
 
+    def get(self, state):
+        source, revision, kind = state
+        self._fetch(source, revision)
+        if self._gitstate() != revision:
+            self._ui.warn(_('checking out detached HEAD in subrepo %s\n') %
+                          self._relpath)
+            self._ui.warn(_('check out a git branch if you intend '
+                            'to make changes\n'))
+            self._gitcommand(['checkout', '-q', revision])
+
     def commit(self, text, user, date):
         cmd = ['commit', '-a', '-m', text]
         if user:

tests/test-subrepo-git.t

   path s
    source   ../gitroot
    revision 126f2a14290cd5ce061fdedc430170e8d39e1c5a
+
+clone root
+
+  $ hg clone . ../tc
+  updating to branch default
+  cloning subrepo s
+  3 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ cd ../tc
+  $ hg debugsub
+  path s
+   source   ../gitroot
+   revision 126f2a14290cd5ce061fdedc430170e8d39e1c5a
+
+update to previous substate
+
+  $ hg update 1
+  checking out detached HEAD in subrepo s
+  check out a git branch if you intend to make changes
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ cat s/g
+  g
+  $ hg debugsub
+  path s
+   source   ../gitroot
+   revision da5f5b1d8ffcf62fb8327bcd3c89a4367a6018e7