From: "Johannes Schindelin via GitGitGadget" <gitgitgadget@gmail.com> To: git@vger.kernel.org Cc: Junio C Hamano <gitster@pobox.com>, Johannes Schindelin <johannes.schindelin@gmx.de> Subject: [PATCH v2 1/1] config: work around bug with includeif:onbranch and early config Date: Wed, 31 Jul 2019 13:06:42 -0700 (PDT) Message-ID: <ea1a746113b85bde5319c410f68fe3dc75f8a328.1564603600.git.gitgitgadget@gmail.com> (raw) In-Reply-To: <pull.300.v2.git.gitgitgadget@gmail.com> From: Johannes Schindelin <johannes.schindelin@gmx.de> Since 07b2c0eacac (config: learn the "onbranch:" includeIf condition, 2019-06-05), there is a potential catch-22 in the early config path: if the `include.onbranch:` feature is used, Git assumes that the Git directory has been initialized already. However, in the early config code path that is not true. One way to trigger this is to call the following commands in any repository: git config includeif.onbranch:refs/heads/master.path broken git help -a The symptom triggered by the `git help -a` invocation reads like this: BUG: refs.c:1851: attempting to get main_ref_store outside of repository Let's work around this, simply by ignoring the `includeif.onbranch:` setting when parsing the config when the ref store has not been initialized (yet). Technically, there is a way to solve this properly: teach the refs machinery to initialize the ref_store from a given gitdir/commondir pair (which we _do_ have in the early config code path), and then use that in `include_by_branch()`. This, however, is a pretty involved project, and we're already in the feature freeze for Git v2.23.0. Note: when calling above-mentioned two commands _outside_ of any Git worktree (passing the `--global` flag to `git config`, as there is obviously no repository config available), at the point when `include_by_branch()` is called, `the_repository` is `NULL`, therefore we have to be extra careful not to dereference it in that case. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> --- config.c | 3 ++- t/t1309-early-config.sh | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/config.c b/config.c index ed7f58e0fc..3900e4947b 100644 --- a/config.c +++ b/config.c @@ -275,7 +275,8 @@ static int include_by_branch(const char *cond, size_t cond_len) int flags; int ret; struct strbuf pattern = STRBUF_INIT; - const char *refname = resolve_ref_unsafe("HEAD", 0, NULL, &flags); + const char *refname = !the_repository || !the_repository->gitdir ? + NULL : resolve_ref_unsafe("HEAD", 0, NULL, &flags); const char *shortname; if (!refname || !(flags & REF_ISSYMREF) || diff --git a/t/t1309-early-config.sh b/t/t1309-early-config.sh index 413642aa56..0c37e7180d 100755 --- a/t/t1309-early-config.sh +++ b/t/t1309-early-config.sh @@ -89,4 +89,9 @@ test_expect_failure 'ignore .git/ with invalid config' ' test_with_config "[" ' +test_expect_success 'early config and onbranch' ' + echo "[broken" >broken && + test_with_config "[includeif \"onbranch:refs/heads/master\"]path=../broken" +' + test_done -- gitgitgadget
next prev parent reply other threads:[~2019-07-31 20:06 UTC|newest] Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-07-31 19:53 [PATCH 0/1] Make the includeif:onbranch feature more robust Johannes Schindelin via GitGitGadget 2019-07-31 19:53 ` [PATCH 1/1] config: work around bug with includeif:onbranch and early config Johannes Schindelin via GitGitGadget 2019-07-31 21:37 ` Junio C Hamano 2019-07-31 20:06 ` [PATCH v2 0/1] Make the includeif:onbranch feature more robust Johannes Schindelin via GitGitGadget 2019-07-31 20:06 ` Johannes Schindelin via GitGitGadget [this message] 2019-07-31 22:02 ` [PATCH v2 1/1] config: work around bug with includeif:onbranch and early config Jeff King 2019-07-31 22:13 ` Johannes Schindelin 2019-07-31 23:12 ` Jeff King 2019-08-01 0:49 ` Jeff King 2019-08-01 17:24 ` Jeff Hostetler 2019-08-06 12:26 ` [PATCH 0/3] the_repository initialization cleanup Jeff King 2019-08-06 12:26 ` [PATCH 1/3] t1309: use short branch name in includeIf.onbranch test Jeff King 2019-08-06 12:27 ` [PATCH 2/3] common-main: delay trace2 initialization Jeff King 2019-08-06 12:27 ` [PATCH 3/3] config: stop checking whether the_repository is NULL Jeff King 2019-08-06 12:49 ` Jeff King 2019-08-08 19:48 ` Johannes Schindelin 2019-08-06 12:56 ` [PATCH v2 1/1] config: work around bug with includeif:onbranch and early config 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 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=ea1a746113b85bde5319c410f68fe3dc75f8a328.1564603600.git.gitgitgadget@gmail.com \ --to=gitgitgadget@gmail.com \ --cc=git@vger.kernel.org \ --cc=gitster@pobox.com \ --cc=johannes.schindelin@gmx.de \ /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
git@vger.kernel.org list mirror (unofficial, one of many) This inbox may be cloned and mirrored by anyone: git clone --mirror https://public-inbox.org/git git clone --mirror http://ou63pmih66umazou.onion/git git clone --mirror http://czquwvybam4bgbro.onion/git git clone --mirror http://hjrcffqmbrq6wope.onion/git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V1 git git/ https://public-inbox.org/git \ git@vger.kernel.org public-inbox-index git Example config snippet for mirrors. Newsgroups are available over NNTP: nntp://news.public-inbox.org/inbox.comp.version-control.git nntp://ou63pmih66umazou.onion/inbox.comp.version-control.git nntp://czquwvybam4bgbro.onion/inbox.comp.version-control.git nntp://hjrcffqmbrq6wope.onion/inbox.comp.version-control.git nntp://news.gmane.io/gmane.comp.version-control.git note: .onion URLs require Tor: https://www.torproject.org/ code repositories for the project(s) associated with this inbox: https://80x24.org/mirrors/git.git AGPL code for this site: git clone https://public-inbox.org/public-inbox.git