[PATCH 0 of 1 rfc] Update -C on git and svn subrepos
Eric Eisner
ede at mit.edu
Fri Jan 7 09:34:55 CST 2011
On Fri, Jan 7, 2011 at 09:41, Augie Fackler <durin42 at gmail.com> wrote:
> On Jan 7, 2011, at 8:34 AM, Erik Zielke wrote:
> >
> > On 07-01-2011 15:16, Martin Geisler wrote:
> >> Please write what git command you are talking about so that we don't
> >> have to dig it out ourselves -- as far as I can see we're talking about
> >>
> >> git --reset hard HEAD
> >>
> >> here? And for Subversion you use
> >>
> >> svn revert --recursive
> >>
> >> How are they different from what 'hg update -C' does -- something about
> >> whether they delete untracked files?
> >>
> > Yep, its those I am not sure whether is right, especially the git thing.
>
> I think the git command you really want is 'git checkout HEAD .' for
> undoing all changes to currently-checked-out files (assuming nothing is
> staged in the index.)
There is some complicated logic in gitsubrepo.get for determining what
branch you want to end up on, but almost all paths of logic end in calling a
'git checkout' with different arguments. The docs claim that checkout takes
a --force flag which seems to be more or less the same as hg's --clean flag.
I'd propose something like:
diff --git a/mercurial/subrepo.py b/mercurial/subrepo.py
--- a/mercurial/subrepo.py
+++ b/mercurial/subrepo.py
@@ -739,7 +739,7 @@ class gitsubrepo(abstractsubrepo):
out, code = self._gitdir(['diff-index', '--quiet', 'HEAD'])
return code == 1
- def get(self, state):
+ def get(self, state, overwrite=False):
source, revision, kind = state
self._fetch(source, revision)
# if the repo was set to be bare, unbare it
@@ -749,16 +749,24 @@ class gitsubrepo(abstractsubrepo):
self._gitcommand(['reset', '--hard', 'HEAD'])
return
elif self._gitstate() == revision:
+ if overwrite:
+ self._gitcommand(['reset', '--hard', 'HEAD'])
return
branch2rev, rev2branch = self._gitbranchmap()
+ def checkout(args):
+ cmd = ['checkout']
+ if overwrite:
+ cmd.append('-f')
+ self._gitcommand(cmd + args)
+
def rawcheckout():
# no branch to checkout, check it out with no branch
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])
+ checkout(['-q', revision])
if revision not in rev2branch:
rawcheckout()
@@ -773,7 +781,7 @@ class gitsubrepo(abstractsubrepo):
if not firstlocalbranch and not b.startswith('refs/remotes/'):
firstlocalbranch = b
if firstlocalbranch:
- self._gitcommand(['checkout', firstlocalbranch])
+ checkout([firstlocalbranch])
return
tracking = self._gittracking(branch2rev.keys())
@@ -788,7 +796,7 @@ class gitsubrepo(abstractsubrepo):
if remote not in tracking:
# create a new local tracking branch
local = remote.split('/', 2)[2]
- self._gitcommand(['checkout', '-b', local, remote])
+ checkout(['-b', local, remote])
elif self._gitisancestor(branch2rev[tracking[remote]], remote):
# When updating to a tracked remote branch,
# if the local tracking branch is downstream of it,
@@ -797,7 +805,7 @@ class gitsubrepo(abstractsubrepo):
# Since we are only looking at branching at update, we need to
# detect this situation and perform this action lazily.
if tracking[remote] != self._gitcurrentbranch():
- self._gitcommand(['checkout', tracking[remote]])
+ checkout([tracking[remote]])
self._gitcommand(['merge', '--ff', remote])
else:
# a real merge would be required, just checkout the revision
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://selenic.com/pipermail/mercurial-devel/attachments/20110107/f166a4c3/attachment.htm>
More information about the Mercurial-devel
mailing list