[PATCH 5 of 5 VERSION2] subrepo: removing (and restoring) git subrepo state
Augie Fackler
durin42 at gmail.com
Mon Nov 15 01:45:05 UTC 2010
On Nov 14, 2010, at 5:45 PM, Eric Eisner wrote:
> # HG changeset patch
> # User Eric Eisner <ede at mit.edu>
> # Date 1289777500 18000
> # Node ID 409d03424755c354bb7f1eb2cc1812cadf9c0faf
> # Parent 3a9ac41494337e32f41d458b1320af9ea116e01b
> subrepo: removing (and restoring) git subrepo state
>
> diff --git a/mercurial/subrepo.py b/mercurial/subrepo.py
> --- a/mercurial/subrepo.py
> +++ b/mercurial/subrepo.py
> @@ -678,7 +678,14 @@ class gitsubrepo(object):
> def get(self, state):
> source, revision, kind = state
> self._fetch(source, revision)
> - if self._gitstate() == revision:
> + # if the repo was set to be bare, unbare it
> + if self._gitcommand(['config', '--get', 'core.bare']
> + ).strip() == 'true':
> + self._gitcommand(['config', 'core.bare', 'false'])
> + if self._gitstate() == revision:
> + self._gitcommand(['reset', '--hard', 'HEAD'])
> + return
> + elif self._gitstate() == revision:
> return
> current, bm = self._gitbranchmap()
> if revision not in bm:
> @@ -742,6 +749,24 @@ class gitsubrepo(object):
> 'nothing to push') % self._relpath)
> return False
>
> + def remove(self):
> + if self.dirty():
> + self._ui.warn(_('not removing repo %s because '
> + 'it has changes.\n') % self._path)
> + return
> + # we can't fully delete the repository as it may contain
> + # local-only history
> + self._ui.note(_('removing subrepo %s\n') % self._path)
> + self._gitcommand(['config', 'core.bare', 'true'])
Why mark a repo as bare? I suppose that emulates hg co null, but that seems like a strange thing to do. I'm not sure if we can do better though, so I guess it's just something we have to live with.
> + for f in os.listdir(self._path):
> + if f == '.git':
> + continue
> + path = os.path.join(self._path, f)
> + if os.path.isdir(path) and not os.path.islink(path):
> + shutil.rmtree(path)
> + else:
> + os.remove(path)
What's this code doing? Just trying to understand.
> +
> 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
> @@ -175,3 +175,21 @@ user a pulls, merges, commits
> adding manifests
> adding file changes
> added 2 changesets with 2 changes to 1 files
> +
> +update to a revision without the subrepo, keeping the local git repository
> +
> + $ cd ../t
> + $ hg up 0
> + 0 files updated, 0 files merged, 2 files removed, 0 files unresolved
> + $ ls s -a
> + .
> + ..
> + .git
> +
> + $ hg up 2
> + 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
> + $ ls s -a
> + .
> + ..
> + .git
> + g
More information about the Mercurial-devel
mailing list