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
|
||||
self.bare_git.symbolic_ref('-m', msg, ref, dst)
|
||||
|
||||
def _InitWorkTree(self):
|
||||
def _LinkWorkTree(self, relink=False):
|
||||
dotgit = os.path.join(self.worktree, '.git')
|
||||
if not os.path.exists(dotgit):
|
||||
if not relink:
|
||||
os.makedirs(dotgit)
|
||||
|
||||
for name in ['config',
|
||||
@ -1120,6 +1120,8 @@ class Project(object):
|
||||
try:
|
||||
src = os.path.join(self.gitdir, name)
|
||||
dst = os.path.join(dotgit, name)
|
||||
if relink:
|
||||
os.remove(dst)
|
||||
os.symlink(relpath(src, dst), dst)
|
||||
except OSError, e:
|
||||
if e.errno == errno.EPERM:
|
||||
@ -1127,6 +1129,11 @@ class Project(object):
|
||||
else:
|
||||
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())
|
||||
|
||||
cmd = ['read-tree', '--reset', '-u']
|
||||
|
Loading…
Reference in New Issue
Block a user