git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCHv3] git-p4: support git worktrees

From
Junio C Hamano <gitster@pobox.com>
Date
Dec 14, 2016, 00:08 UTC
Message-ID
<xmqqlgvjz81j.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<20161213215128.20288-2-luke@diamand.org>
Luke Diamand <luke@diamand.org> writes:
Show 63 quoted lines
> git-p4 would attempt to find the git directory using
> its own specific code, which did not know about git
> worktrees.
>
> Rework it to use "git rev-parse --git-dir" instead.
>
> Add test cases for worktree usage and specifying
> git directory via --git-dir and $GIT_DIR.
>
> Signed-off-by: Luke Diamand <luke@diamand.org>
> ---
>  git-p4.py                 | 17 +++++++++++++----
>  t/t9800-git-p4-basic.sh   | 20 ++++++++++++++++++++
>  t/t9806-git-p4-options.sh | 32 ++++++++++++++++++++++++++++++++
>  3 files changed, 65 insertions(+), 4 deletions(-)
>
> diff --git a/git-p4.py b/git-p4.py
> index fd5ca52..6a1f65f 100755
> --- a/git-p4.py
> +++ b/git-p4.py
> @@ -85,6 +85,16 @@ def p4_build_cmd(cmd):
>          real_cmd += cmd
>      return real_cmd
>  
> +def git_dir(path):
> +    """ Return TRUE if the given path is a git directory (/path/to/dir/.git).
> +        This won't automatically add ".git" to a directory.
> +    """
> +    d = read_pipe(["git", "--git-dir", path, "rev-parse", "--git-dir"], True).strip()
> +    if not d or len(d) == 0:
> +        return None
> +    else:
> +        return d
> +
>  def chdir(path, is_client_path=False):
>      """Do chdir to the given path, and set the PWD environment
>         variable for use by P4.  It does not look at getcwd() output.
> @@ -563,10 +573,7 @@ def currentGitBranch():
>          return read_pipe(["git", "name-rev", "HEAD"]).split(" ")[1].strip()
>  
>  def isValidGitDir(path):
> -    if (os.path.exists(path + "/HEAD")
> -        and os.path.exists(path + "/refs") and os.path.exists(path + "/objects")):
> -        return True;
> -    return False
> +    return git_dir(path) != None
>  
>  def parseRevision(ref):
>      return read_pipe("git rev-parse %s" % ref).strip()
> @@ -3682,6 +3689,7 @@ def main():
>          if cmd.gitdir == None:
>              cmd.gitdir = os.path.abspath(".git")
>              if not isValidGitDir(cmd.gitdir):
> +                # "rev-parse --git-dir" without arguments will try $PWD/.git
>                  cmd.gitdir = read_pipe("git rev-parse --git-dir").strip()
>                  if os.path.exists(cmd.gitdir):
>                      cdup = read_pipe("git rev-parse --show-cdup").strip()
> @@ -3694,6 +3702,7 @@ def main():
>              else:
>                  die("fatal: cannot locate git repository at %s" % cmd.gitdir)
>  
> +        # so git commands invoked from the P4 workspace will succeed
>          os.environ["GIT_DIR"] = cmd.gitdir
The real fix has become surprisingly short and "feels right".
Will queue. Thanks.
Previous: Luke Diamand
Message 3 of 3 in “[PATCHv3] git-p4 worktree support”
  1. Luke DiamandDec 13, 2016
  2. [PATCHv3] git-p4: support git worktreesLuke Diamand, Dec 13, 2016
  3. Junio C HamanoDec 14, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.