git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Luke Diamand <luke@diamand.org>
Cc: git@vger.kernel.org, viniciusalexandre@gmail.com,
	Lars Schneider <larsxschneider@gmail.com>,
	Duy Nguyen <pclouds@gmail.com>
Subject: Re: [PATCHv3] git-p4: support git worktrees
Date: Tue, 13 Dec 2016 16:08:40 -0800	[thread overview]
Message-ID: <xmqqlgvjz81j.fsf@gitster.mtv.corp.google.com> (raw)
In-Reply-To: <20161213215128.20288-2-luke@diamand.org> (Luke Diamand's message of "Tue, 13 Dec 2016 21:51:28 +0000")

Luke Diamand <luke@diamand.org> writes:

> 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.


      reply	other threads:[~2016-12-14  0:09 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-13 21:51 [PATCHv3] git-p4 worktree support Luke Diamand
2016-12-13 21:51 ` [PATCHv3] git-p4: support git worktrees Luke Diamand
2016-12-14  0:08   ` Junio C Hamano [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqlgvjz81j.fsf@gitster.mtv.corp.google.com \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=larsxschneider@gmail.com \
    --cc=luke@diamand.org \
    --cc=pclouds@gmail.com \
    --cc=viniciusalexandre@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).