git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Damien Robert <damien.olivier.robert@gmail.com>
To: "Philippe Blain" <levraiphilippeblain@gmail.com>,
	"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Cc: git@vger.kernel.org
Subject: GIT_DIR in aliases [Re: Spurious GIT_DIR set when in a worktree [was Re: Nested submodule status bug]
Date: Thu, 27 Feb 2020 16:50:57 +0100	[thread overview]
Message-ID: <20200227155057.7idpa447ixo6sf6j@feanor> (raw)
In-Reply-To: <20200227104330.hp7zf2suquxsf6zw@feanor>

From Damien Robert, Thu 27 Feb 2020 at 11:43:30 (+0100) :
> And looking at setup.c:760 it appears that `set_git_dir` (which set up among
> other things the GIT_DIR env) is called because we are in a worktree.
> 
> More precisely: we have discovered a git dir (a git file), so we call
> setup_discovered_git_dir, which itself calls setup_explicit_git_dir because
> we are in a work tree environment. And set_up_explicit_git_dir calls
> set_git_dir.
> 
> So I don't know what's the proper way to fix this. Keep track when we add
> ourselves the GIT_DIR rather than when it is already provided and remove it
> before executing a shell alias? Don't run the full configuration setup when
> we are executing a shell alias anyway?

Sorry about the spam. Thinking about it some more, this has nothing to do
with submodules or worktrees, but about how we expect shell aliases to
work.

In Documentation/config/alias, it is documented that the alias will run a
the top level and GIT_PREFIX will be set.

In git.c#handle_alias, it is explicitly stated that shell alias call
setup_git_directory_gently because:
/* Aliases expect GIT_PREFIX, GIT_DIR etc to be set */

So one might argue that the behaviour I observed is not a bug, but it is
still surprising for me (as a user), and maybe this could be stated more
clearly in the docs?

Furthermore there is a question of consistency. GIT_DIR will not always be set
before running a shell alias. Looking at `setup_discovered_git_dir`, it will
be set if we are in a bare dir, or core.worktree / WORK_TREE is set, or if
we have a gitfile.

The annoying side effect is that I cannot use as an alias a command that
iterate over submodules and run git commands inside them, because in this
alias GIT_DIR will be set sometimes, and sometimes not (a quick fix would be to
unset GIT_DIR in my alias).

So what would be the best way to handle this?
Thanks,
Damien

  reply	other threads:[~2020-02-27 15:51 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-14 22:42 Nested submodule checkout Damien Robert
2020-02-17  4:51 ` Philippe Blain
2020-02-18 17:08   ` Damien Robert
2020-02-19  4:19     ` Philippe Blain
2020-02-26 17:23   ` Nested submodule status bug Damien Robert
2020-02-27 10:05     ` Damien Robert
2020-02-27 10:43       ` Spurious GIT_DIR set when in a worktree [was Re: Nested submodule status bug] Damien Robert
2020-02-27 15:50         ` Damien Robert [this message]
2020-02-28 19:02           ` GIT_DIR in aliases [Re: " Jeff King
2020-02-28 20:22             ` Junio C Hamano
2020-03-03 22:44             ` Damien Robert
2020-02-29  1:42           ` Philippe Blain
2020-03-03 21:56             ` Damien Robert

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=20200227155057.7idpa447ixo6sf6j@feanor \
    --to=damien.olivier.robert@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=levraiphilippeblain@gmail.com \
    --cc=pclouds@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).