comparison 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
comparison
equal deleted inserted replaced
12992:2b73a3279a9f 12993:a91334380699
579 class gitsubrepo(object): 579 class gitsubrepo(object):
580 def __init__(self, ctx, path, state): 580 def __init__(self, ctx, path, state):
581 # TODO add git version check. 581 # TODO add git version check.
582 self._state = state 582 self._state = state
583 self._ctx = ctx 583 self._ctx = ctx
584 self._relpath = path
584 self._path = ctx._repo.wjoin(path) 585 self._path = ctx._repo.wjoin(path)
585 self._ui = ctx._repo.ui 586 self._ui = ctx._repo.ui
586 587
587 def _gitcommand(self, commands): 588 def _gitcommand(self, commands):
588 return self._gitdir(commands)[0] 589 return self._gitdir(commands)[0]
631 632
632 def _githavelocally(self, revision): 633 def _githavelocally(self, revision):
633 out, code = self._gitdir(['cat-file', '-e', revision]) 634 out, code = self._gitdir(['cat-file', '-e', revision])
634 return code == 0 635 return code == 0
635 636
637 def _fetch(self, source, revision):
638 if not os.path.exists('%s/.git' % self._path):
639 self._ui.status(_('cloning subrepo %s\n') % self._relpath)
640 self._gitnodir(['clone', source, self._path])
641 if self._githavelocally(revision):
642 return
643 self._ui.status(_('pulling subrepo %s\n') % self._relpath)
644 self._gitcommand(['fetch', '--all', '-q'])
645 if not self._githavelocally(revision):
646 raise util.Abort(_("revision %s does not exist in subrepo %s\n") %
647 (revision, self._path))
648
636 def dirty(self): 649 def dirty(self):
637 if self._state[1] != self._gitstate(): # version checked out changed? 650 if self._state[1] != self._gitstate(): # version checked out changed?
638 return True 651 return True
639 # check for staged changes or modified files; ignore untracked files 652 # check for staged changes or modified files; ignore untracked files
640 # docs say --porcelain flag is future-proof format 653 # docs say --porcelain flag is future-proof format
641 changed = self._gitcommand(['status', '--porcelain', 654 changed = self._gitcommand(['status', '--porcelain',
642 '--untracked-files=no']) 655 '--untracked-files=no'])
643 return bool(changed.strip()) 656 return bool(changed.strip())
657
658 def get(self, state):
659 source, revision, kind = state
660 self._fetch(source, revision)
661 if self._gitstate() != revision:
662 self._ui.warn(_('checking out detached HEAD in subrepo %s\n') %
663 self._relpath)
664 self._ui.warn(_('check out a git branch if you intend '
665 'to make changes\n'))
666 self._gitcommand(['checkout', '-q', revision])
644 667
645 def commit(self, text, user, date): 668 def commit(self, text, user, date):
646 cmd = ['commit', '-a', '-m', text] 669 cmd = ['commit', '-a', '-m', text]
647 if user: 670 if user:
648 cmd += ['--author', user] 671 cmd += ['--author', user]