Mercurial > public > mercurial-scm > hg
diff mercurial/subrepo.py @ 12993:a91334380699
subrepo: cloning and updating of git subrepos
gitsubrepo based on patch from David Soria Parra:
http://bitbucket.org/segv/davids-poor-git-subrepo-attempt/
author | Eric Eisner <ede@mit.edu> |
---|---|
date | Sun, 14 Nov 2010 18:20:13 -0500 |
parents | 2b73a3279a9f |
children | 845c602b8635 |
line wrap: on
line diff
--- a/mercurial/subrepo.py Sun Nov 14 18:15:26 2010 -0500 +++ b/mercurial/subrepo.py Sun Nov 14 18:20:13 2010 -0500 @@ -581,6 +581,7 @@ # 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 @@ -633,6 +634,18 @@ 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 @@ -642,6 +655,16 @@ '--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: