summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGavin Mak <gavinmak@google.com>2025-07-17 17:54:22 +0000
committerLUCI <gerrit-scoped@luci-project-accounts.iam.gserviceaccount.com>2025-07-17 15:41:59 -0700
commit74edacd8e54a11c9358421894a5fcce04b02c47d (patch)
treeb0fbefcd0a70dd1ef04feb2367bdca63639959ad
parent5d95ba8d85e189c25195beae9431d5f6823e083a (diff)
downloadgit-repo-74edacd8e54a11c9358421894a5fcce04b02c47d.tar.gz
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>
-rw-r--r--project.py13
1 files changed, 3 insertions, 10 deletions
diff --git a/project.py b/project.py
index 2d802f24..3def4d32 100644
--- a/project.py
+++ b/project.py
@@ -2061,10 +2061,7 @@ class Project:
2061 if head == revid: 2061 if head == revid:
2062 # Same revision; just update HEAD to point to the new 2062 # Same revision; just update HEAD to point to the new
2063 # target branch, but otherwise take no other action. 2063 # target branch, but otherwise take no other action.
2064 _lwrite( 2064 self.work_git.SetHead(R_HEADS + name)
2065 self.work_git.GetDotgitPath(subpath=HEAD),
2066 f"ref: {R_HEADS}{name}\n",
2067 )
2068 return True 2065 return True
2069 2066
2070 GitCommand( 2067 GitCommand(
@@ -2100,9 +2097,7 @@ class Project:
2100 2097
2101 revid = self.GetRevisionId(all_refs) 2098 revid = self.GetRevisionId(all_refs)
2102 if head == revid: 2099 if head == revid:
2103 _lwrite( 2100 self.work_git.DetachHead(revid)
2104 self.work_git.GetDotgitPath(subpath=HEAD), "%s\n" % revid
2105 )
2106 else: 2101 else:
2107 self._Checkout(revid, quiet=True) 2102 self._Checkout(revid, quiet=True)
2108 GitCommand( 2103 GitCommand(
@@ -3492,9 +3487,7 @@ class Project:
3492 self._createDotGit(dotgit) 3487 self._createDotGit(dotgit)
3493 3488
3494 if init_dotgit: 3489 if init_dotgit:
3495 _lwrite( 3490 self.work_git.UpdateRef(HEAD, self.GetRevisionId(), detach=True)
3496 os.path.join(self.gitdir, HEAD), f"{self.GetRevisionId()}\n"
3497 )
3498 3491
3499 # Finish checking out the worktree. 3492 # Finish checking out the worktree.
3500 cmd = ["read-tree", "--reset", "-u", "-v", HEAD] 3493 cmd = ["read-tree", "--reset", "-u", "-v", HEAD]