project: Use plumbing commands to manage HEAD
Don't directly manipulate `.git/HEAD` since it bypasses Git's internal state management. Bug: 432200791 Change-Id: I1c9264bcf107d34574a82b60a22ea2c83792951b Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/491841 Commit-Queue: Gavin Mak <gavinmak@google.com> Reviewed-by: Scott Lee <ddoman@google.com> Tested-by: Gavin Mak <gavinmak@google.com>
This commit is contained in:
parent
5d95ba8d85
commit
74edacd8e5
1 changed files with 3 additions and 10 deletions
13
project.py
13
project.py
|
@ -2061,10 +2061,7 @@ class Project:
|
||||||
if head == revid:
|
if head == revid:
|
||||||
# Same revision; just update HEAD to point to the new
|
# Same revision; just update HEAD to point to the new
|
||||||
# target branch, but otherwise take no other action.
|
# target branch, but otherwise take no other action.
|
||||||
_lwrite(
|
self.work_git.SetHead(R_HEADS + name)
|
||||||
self.work_git.GetDotgitPath(subpath=HEAD),
|
|
||||||
f"ref: {R_HEADS}{name}\n",
|
|
||||||
)
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
GitCommand(
|
GitCommand(
|
||||||
|
@ -2100,9 +2097,7 @@ class Project:
|
||||||
|
|
||||||
revid = self.GetRevisionId(all_refs)
|
revid = self.GetRevisionId(all_refs)
|
||||||
if head == revid:
|
if head == revid:
|
||||||
_lwrite(
|
self.work_git.DetachHead(revid)
|
||||||
self.work_git.GetDotgitPath(subpath=HEAD), "%s\n" % revid
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
self._Checkout(revid, quiet=True)
|
self._Checkout(revid, quiet=True)
|
||||||
GitCommand(
|
GitCommand(
|
||||||
|
@ -3492,9 +3487,7 @@ class Project:
|
||||||
self._createDotGit(dotgit)
|
self._createDotGit(dotgit)
|
||||||
|
|
||||||
if init_dotgit:
|
if init_dotgit:
|
||||||
_lwrite(
|
self.work_git.UpdateRef(HEAD, self.GetRevisionId(), detach=True)
|
||||||
os.path.join(self.gitdir, HEAD), f"{self.GetRevisionId()}\n"
|
|
||||||
)
|
|
||||||
|
|
||||||
# Finish checking out the worktree.
|
# Finish checking out the worktree.
|
||||||
cmd = ["read-tree", "--reset", "-u", "-v", HEAD]
|
cmd = ["read-tree", "--reset", "-u", "-v", HEAD]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue