Merge branch 'nd/conditional-config-in-early-config'
authorJunio C Hamano <gitster@pobox.com>
Wed, 26 Apr 2017 06:39:05 +0000 (15:39 +0900)
committerJunio C Hamano <gitster@pobox.com>
Wed, 26 Apr 2017 06:39:05 +0000 (15:39 +0900)
The recently introduced conditional inclusion of configuration did
not work well when early-config mechanism was involved.

* nd/conditional-config-in-early-config:
config: correct file reading order in read_early_config()
config: handle conditional include when $GIT_DIR is not set up
config: prepare to pass more info in git_config_with_options()

1  2 
builtin/config.c
cache.h
config.c
t/t1305-config-include.sh
Simple merge
diff --cc cache.h
Simple merge
diff --cc config.c
index 0daaed338eabecb209e42ee5944e1dc432f94070,fffda653e359379b5df26aaf847b026700a88d82..b4a3205da32faf43db1ab990f08c0bb941af87d0
+++ b/config.c
@@@ -212,8 -213,16 +213,16 @@@ static int include_by_gitdir(const stru
        struct strbuf text = STRBUF_INIT;
        struct strbuf pattern = STRBUF_INIT;
        int ret = 0, prefix;
+       const char *git_dir;
  
-       strbuf_realpath(&text, get_git_dir(), 1);
+       if (opts->git_dir)
+               git_dir = opts->git_dir;
+       else if (have_git_dir())
+               git_dir = get_git_dir();
+       else
+               goto done;
 -      strbuf_add_absolute_path(&text, git_dir);
++      strbuf_realpath(&text, git_dir, 1);
        strbuf_add(&pattern, cond, cond_len);
        prefix = prepare_include_condition_pattern(&pattern);
  
@@@ -1515,8 -1509,15 +1526,15 @@@ static int do_git_config_sequence(cons
  {
        int ret = 0;
        char *xdg_config = xdg_config_home("config");
 -      char *user_config = expand_user_path("~/.gitconfig");
 +      char *user_config = expand_user_path("~/.gitconfig", 0);
-       char *repo_config = have_git_dir() ? git_pathdup("config") : NULL;
+       char *repo_config;
+       if (opts->git_dir)
+               repo_config = mkpathdup("%s/config", opts->git_dir);
+       else if (have_git_dir())
+               repo_config = git_pathdup("config");
+       else
+               repo_config = NULL;
  
        current_parsing_scope = CONFIG_SCOPE_SYSTEM;
        if (git_config_system() && !access_or_die(git_etc_gitconfig(), R_OK, 0))
index 8fbc7a029f79b1fd9ffae2fa6183ebdd4bbbb923,fddb47bafa62d967e9964c65363afc42c848397d..933915ec06ec725f7cf6a9ed3e251f6ff2390f76
@@@ -218,50 -208,17 +218,61 @@@ test_expect_success 'conditional includ
        )
  '
  
+ test_expect_success 'conditional include, early config reading' '
+       (
+               cd foo &&
+               echo "[includeIf \"gitdir:foo/\"]path=bar6" >>.git/config &&
+               echo "[test]six=6" >.git/bar6 &&
+               echo 6 >expect &&
+               test-config read_early_config test.six >actual &&
+               test_cmp expect actual
+       )
+ '
 +test_expect_success SYMLINKS 'conditional include, set up symlinked $HOME' '
 +      mkdir real-home &&
 +      ln -s real-home home &&
 +      (
 +              HOME="$TRASH_DIRECTORY/home" &&
 +              export HOME &&
 +              cd "$HOME" &&
 +
 +              git init foo &&
 +              cd foo &&
 +              mkdir sub
 +      )
 +'
 +
 +test_expect_success SYMLINKS 'conditional include, $HOME expansion with symlinks' '
 +      (
 +              HOME="$TRASH_DIRECTORY/home" &&
 +              export HOME &&
 +              cd "$HOME"/foo &&
 +
 +              echo "[includeIf \"gitdir:~/foo/\"]path=bar2" >>.git/config &&
 +              echo "[test]two=2" >.git/bar2 &&
 +              echo 2 >expect &&
 +              force_setup_explicit_git_dir &&
 +              git -C sub config test.two >actual &&
 +              test_cmp expect actual
 +      )
 +'
 +
 +test_expect_success SYMLINKS 'conditional include, relative path with symlinks' '
 +      echo "[includeIf \"gitdir:./foo/.git\"]path=bar4" >home/.gitconfig &&
 +      echo "[test]four=4" >home/bar4 &&
 +      (
 +              HOME="$TRASH_DIRECTORY/home" &&
 +              export HOME &&
 +              cd "$HOME"/foo &&
 +
 +              echo 4 >expect &&
 +              force_setup_explicit_git_dir &&
 +              git -C sub config test.four >actual &&
 +              test_cmp expect actual
 +      )
 +'
 +
  test_expect_success 'include cycles are detected' '
        cat >.gitconfig <<-\EOF &&
        [test]value = gitconfig