diff options
author | Mike Frysinger <vapier@google.com> | 2020-02-23 23:22:34 -0500 |
---|---|---|
committer | Mike Frysinger <vapier@google.com> | 2020-02-24 17:41:36 +0000 |
commit | 4b0eb5a4418babdb12ae6fc50150473dc6dd5733 (patch) | |
tree | a8b7b139e81431fbdd8024d377e47c466c3e1af3 | |
parent | d38300c7565461d4e0b9d7bedf88552e9fd6bf3b (diff) | |
download | git-repo-4b0eb5a4418babdb12ae6fc50150473dc6dd5733.tar.gz |
project: fix rebase check with worktrees
Add a helper to our git wrapper to find the .git subdir,
and then use that to detect internal rebase state.
Change-Id: I3b3b6ed4c1f45cc8c3c98dc19c7ca3aabdc46905
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/256532
Reviewed-by: David Pursehouse <dpursehouse@collab.net>
Tested-by: Mike Frysinger <vapier@google.com>
-rw-r--r-- | project.py | 31 |
1 files changed, 23 insertions, 8 deletions
@@ -986,11 +986,9 @@ class Project(object): | |||
986 | return None | 986 | return None |
987 | 987 | ||
988 | def IsRebaseInProgress(self): | 988 | def IsRebaseInProgress(self): |
989 | w = self.worktree | 989 | return (os.path.exists(self.work_git.GetDotgitPath('rebase-apply')) or |
990 | g = os.path.join(w, '.git') | 990 | os.path.exists(self.work_git.GetDotgitPath('rebase-merge')) or |
991 | return os.path.exists(os.path.join(g, 'rebase-apply')) \ | 991 | os.path.exists(os.path.join(self.worktree, '.dotest'))) |
992 | or os.path.exists(os.path.join(g, 'rebase-merge')) \ | ||
993 | or os.path.exists(os.path.join(w, '.dotest')) | ||
994 | 992 | ||
995 | def IsDirty(self, consider_untracked=True): | 993 | def IsDirty(self, consider_untracked=True): |
996 | """Is the working directory modified in some way? | 994 | """Is the working directory modified in some way? |
@@ -3232,11 +3230,28 @@ class Project(object): | |||
3232 | finally: | 3230 | finally: |
3233 | p.Wait() | 3231 | p.Wait() |
3234 | 3232 | ||
3235 | def GetHead(self): | 3233 | def GetDotgitPath(self, subpath=None): |
3234 | """Return the full path to the .git dir. | ||
3235 | |||
3236 | As a convenience, append |subpath| if provided. | ||
3237 | """ | ||
3236 | if self._bare: | 3238 | if self._bare: |
3237 | path = os.path.join(self._project.gitdir, HEAD) | 3239 | dotgit = self._gitdir |
3238 | else: | 3240 | else: |
3239 | path = self._project.GetHeadPath() | 3241 | dotgit = os.path.join(self._project.worktree, '.git') |
3242 | if os.path.isfile(dotgit): | ||
3243 | # Git worktrees use a "gitdir:" syntax to point to the scratch space. | ||
3244 | with open(dotgit) as fp: | ||
3245 | setting = fp.read() | ||
3246 | assert setting.startswith('gitdir:') | ||
3247 | gitdir = setting.split(':', 1)[1].strip() | ||
3248 | dotgit = os.path.normpath(os.path.join(self._project.worktree, gitdir)) | ||
3249 | |||
3250 | return dotgit if subpath is None else os.path.join(dotgit, subpath) | ||
3251 | |||
3252 | def GetHead(self): | ||
3253 | """Return the ref that HEAD points to.""" | ||
3254 | path = self.GetDotgitPath(subpath=HEAD) | ||
3240 | try: | 3255 | try: |
3241 | with open(path) as fd: | 3256 | with open(path) as fd: |
3242 | line = fd.readline() | 3257 | line = fd.readline() |