summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--project.py23
1 files changed, 16 insertions, 7 deletions
diff --git a/project.py b/project.py
index a0cb5e97..185507c0 100644
--- a/project.py
+++ b/project.py
@@ -1817,6 +1817,18 @@ class Project(object):
1817 1817
1818# Branch Management ## 1818# Branch Management ##
1819 1819
1820 def GetHeadPath(self):
1821 """Return the full path to the HEAD ref."""
1822 dotgit = os.path.join(self.worktree, '.git')
1823 if os.path.isfile(dotgit):
1824 # Git worktrees use a "gitdir:" syntax to point to the scratch space.
1825 with open(dotgit) as fp:
1826 setting = fp.read()
1827 assert setting.startswith('gitdir:')
1828 gitdir = setting.split(':', 1)[1].strip()
1829 dotgit = os.path.join(self.worktree, gitdir)
1830 return os.path.join(dotgit, HEAD)
1831
1820 def StartBranch(self, name, branch_merge='', revision=None): 1832 def StartBranch(self, name, branch_merge='', revision=None):
1821 """Create a new branch off the manifest's revision. 1833 """Create a new branch off the manifest's revision.
1822 """ 1834 """
@@ -1856,8 +1868,7 @@ class Project(object):
1856 except OSError: 1868 except OSError:
1857 pass 1869 pass
1858 _lwrite(ref, '%s\n' % revid) 1870 _lwrite(ref, '%s\n' % revid)
1859 _lwrite(os.path.join(self.worktree, '.git', HEAD), 1871 _lwrite(self.GetHeadPath(), 'ref: %s%s\n' % (R_HEADS, name))
1860 'ref: %s%s\n' % (R_HEADS, name))
1861 branch.Save() 1872 branch.Save()
1862 return True 1873 return True
1863 1874
@@ -1904,8 +1915,7 @@ class Project(object):
1904 # Same revision; just update HEAD to point to the new 1915 # Same revision; just update HEAD to point to the new
1905 # target branch, but otherwise take no other action. 1916 # target branch, but otherwise take no other action.
1906 # 1917 #
1907 _lwrite(os.path.join(self.worktree, '.git', HEAD), 1918 _lwrite(self.GetHeadPath(), 'ref: %s%s\n' % (R_HEADS, name))
1908 'ref: %s%s\n' % (R_HEADS, name))
1909 return True 1919 return True
1910 1920
1911 return GitCommand(self, 1921 return GitCommand(self,
@@ -1938,8 +1948,7 @@ class Project(object):
1938 1948
1939 revid = self.GetRevisionId(all_refs) 1949 revid = self.GetRevisionId(all_refs)
1940 if head == revid: 1950 if head == revid:
1941 _lwrite(os.path.join(self.worktree, '.git', HEAD), 1951 _lwrite(self.GetHeadPath(), '%s\n' % revid)
1942 '%s\n' % revid)
1943 else: 1952 else:
1944 self._Checkout(revid, quiet=True) 1953 self._Checkout(revid, quiet=True)
1945 1954
@@ -3002,7 +3011,7 @@ class Project(object):
3002 if self._bare: 3011 if self._bare:
3003 path = os.path.join(self._project.gitdir, HEAD) 3012 path = os.path.join(self._project.gitdir, HEAD)
3004 else: 3013 else:
3005 path = os.path.join(self._project.worktree, '.git', HEAD) 3014 path = self._project.GetHeadPath()
3006 try: 3015 try:
3007 with open(path) as fd: 3016 with open(path) as fd:
3008 line = fd.readline() 3017 line = fd.readline()