All of lore.kernel.org
 help / color / mirror / Atom feed
From: Duy Nguyen <pclouds@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: Danny Sauer <danny@dannysauer.com>,
	Git Mailing List <git@vger.kernel.org>,
	Johannes Schindelin <Johannes.Schindelin@gmx.de>
Subject: Re: [PATCH] Make git log work for git CWD outside of work tree
Date: Mon, 10 Apr 2017 19:01:00 +0700	[thread overview]
Message-ID: <CACsJy8CLBY22j3EjR4PW3n+K6PWUzb-HCgxTVeCGpwtApZF-6g@mail.gmail.com> (raw)
In-Reply-To: <xmqqvaqdqfhe.fsf@gitster.mtv.corp.google.com>

On Mon, Apr 10, 2017 at 7:21 AM, Junio C Hamano <gitster@pobox.com> wrote:
> If your arrangement is even more exotic, e.g. you have these two
> variables set, and then are running from OUTSIDE the working tree,
> my knee-jerk reaction is that you should get your head examined, as
> it is totally unclear what "git add foo" would mean if you did this:
>
>     $ export GIT_DIR=~/myproject/.git GIT_WORK_TREE=~/myproject
>     $ cd ~/myproject/../somewhere/else
>     $ git add foo
>
> But it should still "work" in the sense that the above command
> should notice that you are trying to add "../somewhere/else/foo" to
> the index, which is obviously nonsense, and die with a message.
>
> Similarly, if you replace "git add foo" with "git log", it still
> should work in the above, i.e.
>
>     $ export GIT_DIR=~/myproject/.git GIT_WORK_TREE=~/myproject
>     $ cd ~/myproject/../somewhere/else
>     $ git log
>
> If Git is not chdir(2)ing to ~/myproject before calling cmd_log()
> in the above (again, this is my down week so I didn't and will not
> check with the code myself), we may want to call that a bug and fix
> it, so that you do not have to do anything special to get to the
> path of ".mailmap" that is at the top-level.

The behavior is "documented" in t1510 since f3bb8b4b84 (Merge branch
'nd/setup' - 2010-12-28)

"11. When user's cwd is outside worktree, cwd remains unchanged,
    prefix is NULL."

This behavior probably started long before my topic though, mine was
more of documentation, making worktree detection more consistent. It's
the same case with defining GIT_DIR without GIT_WORK_TREE, I think:
scripts started to depend on a behavior that we did not clearly
define, by the time we knew what we wanted and we kept the old
behavior forever.

I think it's just safer to go with Johannes' suggestion.

An alternative is, when you have found out you need to read .mailmap,
you call setup_work_tree() then, which prepares the worktree for you
(including moving back to cwd) or dies if worktree does not exist, or
no-op if worktree has already been asked by somebody. Many commands do
lazy worktree initialization this way.
-- 
Duy

  reply	other threads:[~2017-04-10 12:01 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-09  2:21 [PATCH] Make git log work for git CWD outside of work tree Danny Sauer
2017-04-09 10:54 ` Johannes Schindelin
2017-04-09 14:15   ` Danny Sauer
2017-04-10  0:21     ` Junio C Hamano
2017-04-10 12:01       ` Duy Nguyen [this message]
2017-04-10 17:13         ` Jeff King
2017-04-12  6:30           ` Duy Nguyen
2017-04-12  8:41             ` Junio C Hamano
2017-04-12 11:13               ` Duy Nguyen
2017-04-12 13:01                 ` Jeff King
2017-04-12 13:11                   ` Duy Nguyen
2017-04-13 21:29                     ` Jeff King
2017-04-17  0:41                       ` Junio C Hamano
2017-04-17 10:29                       ` Duy Nguyen
2017-04-12 12:53             ` Jeff King

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

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

  git send-email \
    --in-reply-to=CACsJy8CLBY22j3EjR4PW3n+K6PWUzb-HCgxTVeCGpwtApZF-6g@mail.gmail.com \
    --to=pclouds@gmail.com \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=danny@dannysauer.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.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.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.