Merge branch 'mh/config-flip-xbit-back-after-checking' into maint
authorJunio C Hamano <gitster@pobox.com>
Mon, 22 Dec 2014 20:18:00 +0000 (12:18 -0800)
committerJunio C Hamano <gitster@pobox.com>
Mon, 22 Dec 2014 20:18:00 +0000 (12:18 -0800)
"git init" (hence "git clone") initialized the per-repository
configuration file .git/config with x-bit by mistake.

* mh/config-flip-xbit-back-after-checking:
create_default_files(): don't set u+x bit on $GIT_DIR/config

1  2 
builtin/init-db.c
t/t0001-init.sh
diff --combined builtin/init-db.c
index 587a5055ed677c3541c85101d944ffb0a19b1962,a6d58fde49e30ffb49655829d5d443038cd87c04..aab44d2e451b1b6a2c764a5d62464ae690ab5566
@@@ -254,7 -254,8 +254,8 @@@ static int create_default_files(const c
                struct stat st2;
                filemode = (!chmod(path, st1.st_mode ^ S_IXUSR) &&
                                !lstat(path, &st2) &&
-                               st1.st_mode != st2.st_mode);
+                               st1.st_mode != st2.st_mode &&
+                               !chmod(path, st1.st_mode));
        }
        git_config_set("core.filemode", filemode ? "true" : "false");
  
@@@ -330,12 -331,12 +331,12 @@@ int set_git_dir_init(const char *git_di
                 * moving the target repo later on in separate_git_dir()
                 */
                git_link = xstrdup(real_path(git_dir));
 +              set_git_dir(real_path(real_git_dir));
        }
        else {
 -              real_git_dir = real_path(git_dir);
 +              set_git_dir(real_path(git_dir));
                git_link = NULL;
        }
 -      set_git_dir(real_path(real_git_dir));
        return 0;
  }
  
@@@ -426,9 -427,8 +427,9 @@@ int init_db(const char *template_dir, u
  
  static int guess_repository_type(const char *git_dir)
  {
 -      char cwd[PATH_MAX];
        const char *slash;
 +      char *cwd;
 +      int cwd_is_git_dir;
  
        /*
         * "GIT_DIR=. git init" is always bare.
         */
        if (!strcmp(".", git_dir))
                return 1;
 -      if (!getcwd(cwd, sizeof(cwd)))
 -              die_errno(_("cannot tell cwd"));
 -      if (!strcmp(git_dir, cwd))
 +      cwd = xgetcwd();
 +      cwd_is_git_dir = !strcmp(git_dir, cwd);
 +      free(cwd);
 +      if (cwd_is_git_dir)
                return 1;
        /*
         * "GIT_DIR=.git or GIT_DIR=something/.git is usually not.
@@@ -537,9 -536,10 +538,9 @@@ int cmd_init_db(int argc, const char **
                usage(init_db_usage[0]);
        }
        if (is_bare_repository_cfg == 1) {
 -              static char git_dir[PATH_MAX+1];
 -
 -              setenv(GIT_DIR_ENVIRONMENT,
 -                      getcwd(git_dir, sizeof(git_dir)), argc > 0);
 +              char *cwd = xgetcwd();
 +              setenv(GIT_DIR_ENVIRONMENT, cwd, argc > 0);
 +              free(cwd);
        }
  
        if (init_shared_repository != -1)
                        git_work_tree_cfg = xstrdup(real_path(rel));
                        free(rel);
                }
 -              if (!git_work_tree_cfg) {
 -                      git_work_tree_cfg = xcalloc(PATH_MAX, 1);
 -                      if (!getcwd(git_work_tree_cfg, PATH_MAX))
 -                              die_errno (_("Cannot access current working directory"));
 -              }
 +              if (!git_work_tree_cfg)
 +                      git_work_tree_cfg = xgetcwd();
                if (work_tree)
 -                      set_git_work_tree(real_path(work_tree));
 +                      set_git_work_tree(work_tree);
                else
                        set_git_work_tree(git_work_tree_cfg);
                if (access(get_git_work_tree(), X_OK))
        }
        else {
                if (work_tree)
 -                      set_git_work_tree(real_path(work_tree));
 +                      set_git_work_tree(work_tree);
        }
  
        set_git_dir_init(git_dir, real_git_dir, 1);
diff --combined t/t0001-init.sh
index e62c0ffbc22cffffd9c29254a96222bfb5b85633,e808431e963e288276cb073799b83a03ac35a128..7de8d85ee85e2387463e8d98175c9d8f66ca8959
@@@ -12,6 -12,13 +12,13 @@@ check_config () 
                echo "expected a directory $1, a file $1/config and $1/refs"
                return 1
        fi
+       if test_have_prereq POSIXPERM && test -x "$1/config"
+       then
+               echo "$1/config is executable?"
+               return 1
+       fi
        bare=$(cd "$1" && git config --bool core.bare)
        worktree=$(cd "$1" && git config core.worktree) ||
        worktree=unset
@@@ -56,7 -63,7 +63,7 @@@ test_expect_success 'plain through alia
        check_config plain-aliased/.git false unset
  '
  
 -test_expect_failure 'plain nested through aliased command' '
 +test_expect_success 'plain nested through aliased command' '
        (
                git init plain-ancestor-aliased &&
                cd plain-ancestor-aliased &&
@@@ -68,7 -75,7 +75,7 @@@
        check_config plain-ancestor-aliased/plain-nested/.git false unset
  '
  
 -test_expect_failure 'plain nested in bare through aliased command' '
 +test_expect_success 'plain nested in bare through aliased command' '
        (
                git init --bare bare-ancestor-aliased.git &&
                cd bare-ancestor-aliased.git &&
@@@ -185,14 -192,14 +192,14 @@@ test_expect_success 'init --bare/--shar
        git init --bare --shared=0666 init-bare-shared-override &&
        check_config init-bare-shared-override true unset &&
        test x0666 = \
 -      x`git config -f init-bare-shared-override/config core.sharedRepository`
 +      x$(git config -f init-bare-shared-override/config core.sharedRepository)
  '
  
  test_expect_success 'init honors global core.sharedRepository' '
        test_config_global core.sharedRepository 0666 &&
        git init shared-honor-global &&
        test x0666 = \
 -      x`git config -f shared-honor-global/.git/config core.sharedRepository`
 +      x$(git config -f shared-honor-global/.git/config core.sharedRepository)
  '
  
  test_expect_success 'init rejects insanely long --template' '
@@@ -285,7 -292,7 +292,7 @@@ test_expect_success 'init prefers comma
  test_expect_success 'init with separate gitdir' '
        rm -rf newdir &&
        git init --separate-git-dir realgitdir newdir &&
 -      echo "gitdir: `pwd`/realgitdir" >expected &&
 +      echo "gitdir: $(pwd)/realgitdir" >expected &&
        test_cmp expected newdir/.git &&
        test_path_is_dir realgitdir/refs
  '
@@@ -299,7 -306,7 +306,7 @@@ test_expect_success 're-init to update 
        cd newdir &&
        git init --separate-git-dir ../surrealgitdir
        ) &&
 -      echo "gitdir: `pwd`/surrealgitdir" >expected &&
 +      echo "gitdir: $(pwd)/surrealgitdir" >expected &&
        test_cmp expected newdir/.git &&
        test_path_is_dir surrealgitdir/refs &&
        test_path_is_missing realgitdir/refs
@@@ -312,7 -319,7 +319,7 @@@ test_expect_success 're-init to move gi
        cd newdir &&
        git init --separate-git-dir ../realgitdir
        ) &&
 -      echo "gitdir: `pwd`/realgitdir" >expected &&
 +      echo "gitdir: $(pwd)/realgitdir" >expected &&
        test_cmp expected newdir/.git &&
        test_path_is_dir realgitdir/refs
  '
@@@ -326,7 -333,7 +333,7 @@@ test_expect_success SYMLINKS 're-init t
        ln -s here .git &&
        git init --separate-git-dir ../realgitdir
        ) &&
 -      echo "gitdir: `pwd`/realgitdir" >expected &&
 +      echo "gitdir: $(pwd)/realgitdir" >expected &&
        test_cmp expected newdir/.git &&
        test_cmp expected newdir/here &&
        test_path_is_dir realgitdir/refs