mirror of
https://gerrit.googlesource.com/git-repo
synced 2024-12-21 07:16:21 +00:00
Teach Project how to relink a .git/ in the work tree
The _LinkWorkTree method can now be used to relink the work tree, such as if the real repository was moved to a different location on disk. Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
parent
98ea26b8d8
commit
ca3d8ff4fc
11
project.py
11
project.py
@ -1102,9 +1102,9 @@ class Project(object):
|
|||||||
msg = 'manifest set to %s' % self.revisionExpr
|
msg = 'manifest set to %s' % self.revisionExpr
|
||||||
self.bare_git.symbolic_ref('-m', msg, ref, dst)
|
self.bare_git.symbolic_ref('-m', msg, ref, dst)
|
||||||
|
|
||||||
def _InitWorkTree(self):
|
def _LinkWorkTree(self, relink=False):
|
||||||
dotgit = os.path.join(self.worktree, '.git')
|
dotgit = os.path.join(self.worktree, '.git')
|
||||||
if not os.path.exists(dotgit):
|
if not relink:
|
||||||
os.makedirs(dotgit)
|
os.makedirs(dotgit)
|
||||||
|
|
||||||
for name in ['config',
|
for name in ['config',
|
||||||
@ -1120,6 +1120,8 @@ class Project(object):
|
|||||||
try:
|
try:
|
||||||
src = os.path.join(self.gitdir, name)
|
src = os.path.join(self.gitdir, name)
|
||||||
dst = os.path.join(dotgit, name)
|
dst = os.path.join(dotgit, name)
|
||||||
|
if relink:
|
||||||
|
os.remove(dst)
|
||||||
os.symlink(relpath(src, dst), dst)
|
os.symlink(relpath(src, dst), dst)
|
||||||
except OSError, e:
|
except OSError, e:
|
||||||
if e.errno == errno.EPERM:
|
if e.errno == errno.EPERM:
|
||||||
@ -1127,6 +1129,11 @@ class Project(object):
|
|||||||
else:
|
else:
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
def _InitWorkTree(self):
|
||||||
|
dotgit = os.path.join(self.worktree, '.git')
|
||||||
|
if not os.path.exists(dotgit):
|
||||||
|
self._LinkWorkTree()
|
||||||
|
|
||||||
_lwrite(os.path.join(dotgit, HEAD), '%s\n' % self.GetRevisionId())
|
_lwrite(os.path.join(dotgit, HEAD), '%s\n' % self.GetRevisionId())
|
||||||
|
|
||||||
cmd = ['read-tree', '--reset', '-u']
|
cmd = ['read-tree', '--reset', '-u']
|
||||||
|
Loading…
Reference in New Issue
Block a user