Bug 1488133 - Local git aliases don't work in linked working tree
Summary: Local git aliases don't work in linked working tree
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Fedora
Classification: Fedora
Component: git
Version: 26
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Petr Stodulka
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2017-09-04 12:11 UTC by Jonathan Wakely
Modified: 2017-09-08 16:21 UTC (History)
7 users (show)

Fixed In Version: git-2.13.5-2.fc26
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2017-09-08 16:21:50 UTC
Type: Bug


Attachments (Terms of Use)
Backport of upstream fix to 2.13.5 (5.79 KB, patch)
2017-09-04 14:12 UTC, Jonathan Wakely
no flags Details | Diff

Description Jonathan Wakely 2017-09-04 12:11:31 UTC
Description of problem:

Git aliases defined in the .git/config file (i.e. --local ones) do not work in a linked working tree.

This is a regression from F24. It worked correctly with git-2.7.5-1.fc24.x86_64 and I'm told it works correctly with 2.14.1 so please see if the fix can be backported.


Version-Release number of selected component (if applicable):

git-2.13.5-1.fc26.x86_64


How reproducible:

Always


Steps to Reproduce:


tmp$ cd git
git$ mkdir primary
git$ cd primary
primary$ git init
Initialized empty Git repository in /tmp/git/primary/.git/
master primary$ git config alias.l log
master primary$ git l
fatal: your current branch 'master' does not have any commits yet
master primary$ touch file
master% primary$ git add file
master+ primary$ git ci -m begin
[master (root-commit) 3ad78a7] begin
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 file
master primary$ git l
commit 3ad78a703906f304bbc34cbcc6ab32522ddb6e01 (HEAD -> master)
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Mon Sep 4 12:51:53 2017 +0100

    begin

master primary$ git worktree add -b secondary ../secondary
Preparing ../secondary (identifier secondary)
HEAD is now at 3ad78a7 begin
master primary$ cd ../secondary
secondary secondary$ git l
git: 'l' is not a git command. See 'git --help'.

The most similar command is
        log

Comment 1 Jonathan Wakely 2017-09-04 12:14:23 UTC
(In reply to Jonathan Wakely from comment #0)
> Steps to Reproduce:
 
I missed the first lines out, which should have been:

cd /tmp
mkdir git

> tmp$ cd git
> git$ mkdir primary
> git$ cd primary
> primary$ git init
> Initialized empty Git repository in /tmp/git/primary/.git/
> master primary$ git config alias.l log
> master primary$ git l
> fatal: your current branch 'master' does not have any commits yet
> master primary$ touch file
> master% primary$ git add file
> master+ primary$ git ci -m begin

Sorry, "ci" is a (global) alias on my machine. That should have been "commit".

Comment 2 Jonathan Wakely 2017-09-04 12:19:55 UTC
(In reply to Jonathan Wakely from comment #0)
> Description of problem:
> 
> Git aliases defined in the .git/config file (i.e. --local ones) do not work
> in a linked working tree.
> 
> This is a regression from F24. It worked correctly with
> git-2.7.5-1.fc24.x86_64 and I'm told it works correctly with 2.14.1 so
> please see if the fix can be backported.

It works correctly in F25 with git-2.9.5-1.fc25.x86_64

It works correctly in rawhide with git-2.14.1-2.fc27.x86_64.rpm

Only F26 doesn't work.

Comment 3 Jonathan Wakely 2017-09-04 13:05:45 UTC
Fixed upstream by:

commit f31d23a399d557d687266b4375a0436f920cc051 (HEAD)
Merge: 5812b3f73 dc8441fdb
Author: Junio C Hamano <gitster@pobox.com>
Date:   Sat Jun 24 14:28:40 2017 -0700

    Merge branch 'bw/config-h'
    
    Fix configuration codepath to pay proper attention to commondir
    that is used in multi-worktree situation, and isolate config API
    into its own header file.
    
    * bw/config-h:
      config: don't implicitly use gitdir or commondir
      config: respect commondir
      setup: teach discover_git_directory to respect the commondir
      config: don't include config.h by default
      config: remove git_config_iter
      config: create config.h

Comment 4 Jonathan Wakely 2017-09-04 13:21:23 UTC
The bug was introduced by:

commit a9bcf6586d1a4888aea91553d73cda20494b8335 (HEAD)
Author: Johannes Schindelin <johannes.schindelin@gmx.de>
Date:   Wed Jun 14 13:36:00 2017 +0200

    alias: use the early config machinery to expand aliases
    
    Instead of discovering the .git/ directory, reading the config and then
    trying to painstakingly reset all the global state if we did not find a
    matching alias, let's use the early config machinery instead.
    
    It may look like unnecessary work to discover the .git/ directory in the
    early config machinery and then call setup_git_directory_gently() in the
    case of a shell alias, repeating the very same discovery *again*.
    However, we have to do this as the early config machinery takes pains
    *not* to touch any global state, while shell aliases expect a possibly
    changed working directory and at least the GIT_PREFIX and GIT_DIR
    variables to be set.
    
    This change also fixes a known issue where Git tried to read the pager
    config from an incorrect path in a subdirectory of a Git worktree if an
    alias expanded to a shell command.
    
    Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
    Reviewed-by: Jeff King <peff@peff.net>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>

Comment 5 Petr Stodulka 2017-09-04 13:46:44 UTC
Thanks Jonathan for report and investigation. I am going to test this and create new build.

Comment 6 Jonathan Wakely 2017-09-04 14:12:23 UTC
Created attachment 1321880 [details]
Backport of upstream fix to 2.13.5

This patch is a smaller version of the upstream fix, just adding the commondir field to struct config_options, and populating it appropriately. The changes to create a new config.h header and move function prototypes to it (and rename some functions) are not included here, as those are just refactoring and don't change any functionality.

However a new f26 RPM containing the patch fails to build:

*** t0012-help.sh ***
ok 1 - setup
not ok 2 - works for commands and guides by default
#
#               configure_help &&
#               git help status &&
#               echo "test://html/git-status.html" >expect &&
#               test_cmp expect test-browser.log &&
#               git help revisions &&
#               echo "test://html/gitrevisions.html" >expect &&
#               test_cmp expect test-browser.log
#
ok 3 - --exclude-guides does not work for guides
ok 4 - --help does not work for guides
# failed 1 among 4 test(s)
1..4
make[2]: *** [Makefile:49: t0012-help.sh] Error 1
make[2]: Leaving directory '/builddir/build/BUILD/git-2.13.5/t'
make[1]: Leaving directory '/builddir/build/BUILD/git-2.13.5/t'
make[1]: *** [Makefile:36: test] Error 2
make: *** [Makefile:2322: test] Error 2

Comment 7 Petr Stodulka 2017-09-05 15:09:46 UTC
It fails because the test-browser.log doesn't exists:
  $ sh t0012-help.sh -v
  <snip>
  diff: test-browser.log: No such file or directory
  not ok 2 - works for commands and guides by default
  <snip>

but still do not know exactly what is source of troubles. I found that there are more tests that failed now, so I will do better investigation now.

Additional info:
The patch in attachment works on upstream branch correctly after the 4b44b7b1d commit (with small updates for setup.c). However it doesn't contain complete fix for Git v2.13.5 yet.

Comment 8 Petr Stodulka 2017-09-06 19:09:31 UTC
My big mistake. Whole problem solves a560d87033729. The problem was about the git_common_dir, that was not initialized. My mistake as I probably did testing wrongly for the first time when I tried that, so I waste time by looking for solution elsewhere.

Comment 9 Fedora Update System 2017-09-07 08:17:00 UTC
git-2.13.5-2.fc26 has been submitted as an update to Fedora 26. https://bodhi.fedoraproject.org/updates/FEDORA-2017-5aa2567cee

Comment 10 Fedora Update System 2017-09-08 00:24:36 UTC
git-2.13.5-2.fc26 has been pushed to the Fedora 26 testing repository. If problems still persist, please make note of it in this bug report.
See https://fedoraproject.org/wiki/QA:Updates_Testing for
instructions on how to install test updates.
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2017-5aa2567cee

Comment 11 Fedora Update System 2017-09-08 16:21:50 UTC
git-2.13.5-2.fc26 has been pushed to the Fedora 26 stable repository. If problems still persist, please make note of it in this bug report.


Note You need to log in before you can comment on or make changes to this bug.