#!/bin/sh global test_description := ''git init'' source ./test-lib.sh proc check_config { if test -d $1 && test -f "$1/config" && test -d "$1/refs" { : happy } else { echo "expected a directory $1, a file $1/config and $1/refs" return 1 } if test_have_prereq POSIXPERM && test -x "$1/config" { echo "$1/config is executable?" return 1 } global bare := $[cd $1 && git config --bool core.bare] global worktree := $[cd $1 && git config core.worktree] || global worktree := 'unset' test $bare = $2 && test $worktree = $3 || do { echo "expected bare=$2 worktree=$3" echo " got bare=$bare worktree=$worktree" return 1 } } test_expect_success 'plain' ' git init plain && check_config plain/.git false unset ' test_expect_success 'plain nested in bare' ' ( git init --bare bare-ancestor.git && cd bare-ancestor.git && mkdir plain-nested && cd plain-nested && git init ) && check_config bare-ancestor.git/plain-nested/.git false unset ' test_expect_success 'plain through aliased command, outside any git repo' ' ( HOME=$(pwd)/alias-config && export HOME && mkdir alias-config && echo "[alias] aliasedinit = init" >alias-config/.gitconfig && GIT_CEILING_DIRECTORIES=$(pwd) && export GIT_CEILING_DIRECTORIES && mkdir plain-aliased && cd plain-aliased && git aliasedinit ) && check_config plain-aliased/.git false unset ' test_expect_success 'plain nested through aliased command' ' ( git init plain-ancestor-aliased && cd plain-ancestor-aliased && echo "[alias] aliasedinit = init" >>.git/config && mkdir plain-nested && cd plain-nested && git aliasedinit ) && check_config plain-ancestor-aliased/plain-nested/.git false unset ' test_expect_success 'plain nested in bare through aliased command' ' ( git init --bare bare-ancestor-aliased.git && cd bare-ancestor-aliased.git && echo "[alias] aliasedinit = init" >>config && mkdir plain-nested && cd plain-nested && git aliasedinit ) && check_config bare-ancestor-aliased.git/plain-nested/.git false unset ' test_expect_success 'No extra GIT_* on alias scripts' ' write_script script <<-\EOF && env | sed -n \ -e "/^GIT_PREFIX=/d" \ -e "/^GIT_TEXTDOMAINDIR=/d" \ -e "/^GIT_/s/=.*//p" | sort EOF ./script >expected && git config alias.script \!./script && ( mkdir sub && cd sub && git script >../actual ) && test_cmp expected actual ' test_expect_success 'plain with GIT_WORK_TREE' ' mkdir plain-wt && test_must_fail env GIT_WORK_TREE="$(pwd)/plain-wt" git init plain-wt ' test_expect_success 'plain bare' ' git --bare init plain-bare-1 && check_config plain-bare-1 true unset ' test_expect_success 'plain bare with GIT_WORK_TREE' ' mkdir plain-bare-2 && test_must_fail \ env GIT_WORK_TREE="$(pwd)/plain-bare-2" \ git --bare init plain-bare-2 ' test_expect_success 'GIT_DIR bare' ' mkdir git-dir-bare.git && GIT_DIR=git-dir-bare.git git init && check_config git-dir-bare.git true unset ' test_expect_success 'init --bare' ' git init --bare init-bare.git && check_config init-bare.git true unset ' test_expect_success 'GIT_DIR non-bare' ' ( mkdir non-bare && cd non-bare && GIT_DIR=.git git init ) && check_config non-bare/.git false unset ' test_expect_success 'GIT_DIR & GIT_WORK_TREE (1)' ' ( mkdir git-dir-wt-1.git && GIT_WORK_TREE=$(pwd) GIT_DIR=git-dir-wt-1.git git init ) && check_config git-dir-wt-1.git false "$(pwd)" ' test_expect_success 'GIT_DIR & GIT_WORK_TREE (2)' ' mkdir git-dir-wt-2.git && test_must_fail env \ GIT_WORK_TREE="$(pwd)" \ GIT_DIR=git-dir-wt-2.git \ git --bare init ' test_expect_success 'reinit' ' ( mkdir again && cd again && git init >out1 2>err1 && git init >out2 2>err2 ) && test_i18ngrep "Initialized empty" again/out1 && test_i18ngrep "Reinitialized existing" again/out2 && >again/empty && test_i18ncmp again/empty again/err1 && test_i18ncmp again/empty again/err2 ' test_expect_success 'init with --template' ' mkdir template-source && echo content >template-source/file && git init --template=../template-source template-custom && test_cmp template-source/file template-custom/.git/file ' test_expect_success 'init with --template (blank)' ' git init template-plain && test_path_is_file template-plain/.git/info/exclude && git init --template= template-blank && test_path_is_missing template-blank/.git/info/exclude ' test_expect_success 'init with init.templatedir set' ' mkdir templatedir-source && echo Content >templatedir-source/file && test_config_global init.templatedir "${HOME}/templatedir-source" && ( mkdir templatedir-set && cd templatedir-set && sane_unset GIT_TEMPLATE_DIR && NO_SET_GIT_TEMPLATE_DIR=t && export NO_SET_GIT_TEMPLATE_DIR && git init ) && test_cmp templatedir-source/file templatedir-set/.git/file ' test_expect_success 'init --bare/--shared overrides system/global config' ' test_config_global core.bare false && test_config_global core.sharedRepository 0640 && 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) ' 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) ' test_expect_success 'init allows insanely long --template' ' git init --template=$(printf "x%09999dx" 1) test ' test_expect_success 'init creates a new directory' ' rm -fr newdir && git init newdir && test_path_is_dir newdir/.git/refs ' test_expect_success 'init creates a new bare directory' ' rm -fr newdir && git init --bare newdir && test_path_is_dir newdir/refs ' test_expect_success 'init recreates a directory' ' rm -fr newdir && mkdir newdir && git init newdir && test_path_is_dir newdir/.git/refs ' test_expect_success 'init recreates a new bare directory' ' rm -fr newdir && mkdir newdir && git init --bare newdir && test_path_is_dir newdir/refs ' test_expect_success 'init creates a new deep directory' ' rm -fr newdir && git init newdir/a/b/c && test_path_is_dir newdir/a/b/c/.git/refs ' test_expect_success POSIXPERM 'init creates a new deep directory (umask vs. shared)' ' rm -fr newdir && ( # Leading directories should honor umask while # the repository itself should follow "shared" umask 002 && git init --bare --shared=0660 newdir/a/b/c && test_path_is_dir newdir/a/b/c/refs && ls -ld newdir/a newdir/a/b > lsab.out && ! grep -v "^drwxrw[sx]r-x" lsab.out && ls -ld newdir/a/b/c > lsc.out && ! grep -v "^drwxrw[sx]---" lsc.out ) ' test_expect_success 'init notices EEXIST (1)' ' rm -fr newdir && >newdir && test_must_fail git init newdir && test_path_is_file newdir ' test_expect_success 'init notices EEXIST (2)' ' rm -fr newdir && mkdir newdir && >newdir/a && test_must_fail git init newdir/a/b && test_path_is_file newdir/a ' test_expect_success POSIXPERM,SANITY 'init notices EPERM' ' rm -fr newdir && mkdir newdir && chmod -w newdir && test_must_fail git init newdir/a/b ' test_expect_success 'init creates a new bare directory with global --bare' ' rm -rf newdir && git --bare init newdir && test_path_is_dir newdir/refs ' test_expect_success 'init prefers command line to GIT_DIR' ' rm -rf newdir && mkdir otherdir && GIT_DIR=otherdir git --bare init newdir && test_path_is_dir newdir/refs && test_path_is_missing otherdir/refs ' test_expect_success 'init with separate gitdir' ' rm -rf newdir && git init --separate-git-dir realgitdir newdir && echo "gitdir: $(pwd)/realgitdir" >expected && test_cmp expected newdir/.git && test_path_is_dir realgitdir/refs ' test_expect_success 're-init on .git file' ' ( cd newdir && git init ) ' test_expect_success 're-init to update git link' ' ( cd newdir && git init --separate-git-dir ../surrealgitdir ) && echo "gitdir: $(pwd)/surrealgitdir" >expected && test_cmp expected newdir/.git && test_path_is_dir surrealgitdir/refs && test_path_is_missing realgitdir/refs ' test_expect_success 're-init to move gitdir' ' rm -rf newdir realgitdir surrealgitdir && git init newdir && ( cd newdir && git init --separate-git-dir ../realgitdir ) && echo "gitdir: $(pwd)/realgitdir" >expected && test_cmp expected newdir/.git && test_path_is_dir realgitdir/refs ' test_expect_success SYMLINKS 're-init to move gitdir symlink' ' rm -rf newdir realgitdir && git init newdir && ( cd newdir && mv .git here && ln -s here .git && git init --separate-git-dir ../realgitdir ) && echo "gitdir: $(pwd)/realgitdir" >expected && test_cmp expected newdir/.git && test_cmp expected newdir/here && test_path_is_dir realgitdir/refs ' # Tests for the hidden file attribute on windows proc is_hidden { # Use the output of `attrib`, ignore the absolute path matchstr $[attrib $1] { *H*?:* { return 0} } return 1 } test_expect_success MINGW '.git hidden' ' rm -rf newdir && ( unset GIT_DIR GIT_WORK_TREE mkdir newdir && cd newdir && git init && is_hidden .git ) && check_config newdir/.git false unset ' test_expect_success MINGW 'bare git dir not hidden' ' rm -rf newdir && ( unset GIT_DIR GIT_WORK_TREE GIT_CONFIG mkdir newdir && cd newdir && git --bare init ) && ! is_hidden newdir ' test_expect_success 'remote init from does not use config from cwd' ' rm -rf newdir && test_config core.logallrefupdates true && git init newdir && echo true >expect && git -C newdir config --bool core.logallrefupdates >actual && test_cmp expect actual ' test_expect_success 're-init from a linked worktree' ' git init main-worktree && ( cd main-worktree && test_commit first && git worktree add ../linked-worktree && mv .git/info/exclude expected-exclude && cp .git/config expected-config && find .git/worktrees -print | sort >expected && git -C ../linked-worktree init && test_cmp expected-exclude .git/info/exclude && test_cmp expected-config .git/config && find .git/worktrees -print | sort >actual && test_cmp expected actual ) ' test_done (CommandList children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:test_description) op: Equal rhs: {(SQ <"git init">)} spids: [4] ) ] spids: [4] ) (C {(.)} {(./test-lib.sh)}) (FuncDef name: check_config body: (BraceGroup children: [ (If arms: [ (if_arm cond: [ (AndOr children: [ (C {(test)} {(-d)} {(DQ ($ VSub_Number "$1"))}) (AndOr children: [ (C {(test)} {(-f)} {(DQ ($ VSub_Number "$1") (/config))}) (C {(test)} {(-d)} {(DQ ($ VSub_Number "$1") (/refs))}) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] action: [(C {(Lit_Other ":")} {(happy)})] spids: [-1 56] ) ] else_action: [ (C {(echo)} { (DQ ("expected a directory ") ($ VSub_Number "$1") (", a file ") ($ VSub_Number "$1") ("/config and ") ($ VSub_Number "$1") (/refs) ) } ) (ControlFlow token: arg_word:{(1)}) ] spids: [64 85] ) (If arms: [ (if_arm cond: [ (AndOr children: [ (C {(test_have_prereq)} {(POSIXPERM)}) (C {(test)} {(-x)} {(DQ ($ VSub_Number "$1") (/config))}) ] op_id: Op_DAmp ) ] action: [ (C {(echo)} {(DQ ($ VSub_Number "$1") ("/config is executable?"))}) (ControlFlow token: arg_word:{(1)}) ] spids: [-1 107] ) ] spids: [-1 123] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:bare) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (AndOr children: [ (C {(cd)} {(DQ ($ VSub_Number "$1"))}) (C {(git)} {(config)} {(--bool)} {(core.bare)}) ] op_id: Op_DAmp ) ] ) left_token: spids: [128 144] ) } spids: [127] ) ] spids: [127] ) (AndOr children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:worktree) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (AndOr children: [ (C {(cd)} {(DQ ($ VSub_Number "$1"))}) (C {(git)} {(config)} {(core.worktree)}) ] op_id: Op_DAmp ) ] ) left_token: spids: [148 162] ) } spids: [147] ) ] spids: [147] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:worktree) op: Equal rhs: {(unset)} spids: [167] ) ] spids: [167] ) ] op_id: Op_DPipe ) (AndOr children: [ (C {(test)} {(DQ ($ VSub_Name "$bare"))} {(Lit_Other "=")} {(DQ ($ VSub_Number "$2"))}) (AndOr children: [ (C {(test)} {(DQ ($ VSub_Name "$worktree"))} {(Lit_Other "=")} {(DQ ($ VSub_Number "$3"))} ) (BraceGroup children: [ (C {(echo)} { (DQ ("expected bare=") ($ VSub_Number "$2") (" worktree=") ($ VSub_Number "$3") ) } ) (C {(echo)} { (DQ (" got bare=") ($ VSub_Name "$bare") (" worktree=") ($ VSub_Name "$worktree") ) } ) (ControlFlow token: arg_word: {(1)} ) ] spids: [200] ) ] op_id: Op_DPipe ) ] op_id: Op_DAmp ) ] spids: [20] ) spids: [15 19] ) (C {(test_expect_success)} {(SQ )} {(SQ <"\n"> <"\tgit init plain &&\n"> <"\tcheck_config plain/.git false unset\n">)} ) (C {(test_expect_success)} {(SQ <"plain nested in bare">)} { (SQ <"\n"> <"\t(\n"> <"\t\tgit init --bare bare-ancestor.git &&\n"> <"\t\tcd bare-ancestor.git &&\n"> <"\t\tmkdir plain-nested &&\n"> <"\t\tcd plain-nested &&\n"> <"\t\tgit init\n"> <"\t) &&\n"> <"\tcheck_config bare-ancestor.git/plain-nested/.git false unset\n"> ) } ) (C {(test_expect_success)} {(SQ <"plain through aliased command, outside any git repo">)} { (SQ <"\n"> <"\t(\n"> <"\t\tHOME=$(pwd)/alias-config &&\n"> <"\t\texport HOME &&\n"> <"\t\tmkdir alias-config &&\n"> <"\t\techo \"[alias] aliasedinit = init\" >alias-config/.gitconfig &&\n"> <"\n"> <"\t\tGIT_CEILING_DIRECTORIES=$(pwd) &&\n"> <"\t\texport GIT_CEILING_DIRECTORIES &&\n"> <"\n"> <"\t\tmkdir plain-aliased &&\n"> <"\t\tcd plain-aliased &&\n"> <"\t\tgit aliasedinit\n"> <"\t) &&\n"> <"\tcheck_config plain-aliased/.git false unset\n"> ) } ) (C {(test_expect_success)} {(SQ <"plain nested through aliased command">)} { (SQ <"\n"> <"\t(\n"> <"\t\tgit init plain-ancestor-aliased &&\n"> <"\t\tcd plain-ancestor-aliased &&\n"> <"\t\techo \"[alias] aliasedinit = init\" >>.git/config &&\n"> <"\t\tmkdir plain-nested &&\n"> <"\t\tcd plain-nested &&\n"> <"\t\tgit aliasedinit\n"> <"\t) &&\n"> <"\tcheck_config plain-ancestor-aliased/plain-nested/.git false unset\n"> ) } ) (C {(test_expect_success)} {(SQ <"plain nested in bare through aliased command">)} { (SQ <"\n"> <"\t(\n"> <"\t\tgit init --bare bare-ancestor-aliased.git &&\n"> <"\t\tcd bare-ancestor-aliased.git &&\n"> <"\t\techo \"[alias] aliasedinit = init\" >>config &&\n"> <"\t\tmkdir plain-nested &&\n"> <"\t\tcd plain-nested &&\n"> <"\t\tgit aliasedinit\n"> <"\t) &&\n"> <"\tcheck_config bare-ancestor-aliased.git/plain-nested/.git false unset\n"> ) } ) (C {(test_expect_success)} {(SQ <"No extra GIT_* on alias scripts">)} { (SQ <"\n"> <"\twrite_script script <<-\\EOF &&\n"> <"\tenv |\n"> <"\t\tsed -n \\\n"> <"\t\t\t-e \"/^GIT_PREFIX=/d\" \\\n"> <"\t\t\t-e \"/^GIT_TEXTDOMAINDIR=/d\" \\\n"> <"\t\t\t-e \"/^GIT_/s/=.*//p\" |\n"> <"\t\tsort\n"> <"\tEOF\n"> <"\t./script >expected &&\n"> <"\tgit config alias.script \\!./script &&\n"> <"\t( mkdir sub && cd sub && git script >../actual ) &&\n"> <"\ttest_cmp expected actual\n"> ) } ) (C {(test_expect_success)} {(SQ <"plain with GIT_WORK_TREE">)} { (SQ <"\n"> <"\tmkdir plain-wt &&\n"> <"\ttest_must_fail env GIT_WORK_TREE=\"$(pwd)/plain-wt\" git init plain-wt\n"> ) } ) (C {(test_expect_success)} {(SQ <"plain bare">)} { (SQ <"\n"> <"\tgit --bare init plain-bare-1 &&\n"> <"\tcheck_config plain-bare-1 true unset\n">) } ) (C {(test_expect_success)} {(SQ <"plain bare with GIT_WORK_TREE">)} { (SQ <"\n"> <"\tmkdir plain-bare-2 &&\n"> <"\ttest_must_fail \\\n"> <"\t\tenv GIT_WORK_TREE=\"$(pwd)/plain-bare-2\" \\\n"> <"\t\tgit --bare init plain-bare-2\n"> ) } ) (C {(test_expect_success)} {(SQ <"GIT_DIR bare">)} { (SQ <"\n"> <"\tmkdir git-dir-bare.git &&\n"> <"\tGIT_DIR=git-dir-bare.git git init &&\n"> <"\tcheck_config git-dir-bare.git true unset\n"> ) } ) (C {(test_expect_success)} {(SQ <"init --bare">)} { (SQ <"\n"> <"\tgit init --bare init-bare.git &&\n"> <"\tcheck_config init-bare.git true unset\n"> ) } ) (C {(test_expect_success)} {(SQ <"GIT_DIR non-bare">)} { (SQ <"\n"> <"\n"> <"\t(\n"> <"\t\tmkdir non-bare &&\n"> <"\t\tcd non-bare &&\n"> <"\t\tGIT_DIR=.git git init\n"> <"\t) &&\n"> <"\tcheck_config non-bare/.git false unset\n"> ) } ) (C {(test_expect_success)} {(SQ <"GIT_DIR & GIT_WORK_TREE (1)">)} { (SQ <"\n"> <"\n"> <"\t(\n"> <"\t\tmkdir git-dir-wt-1.git &&\n"> <"\t\tGIT_WORK_TREE=$(pwd) GIT_DIR=git-dir-wt-1.git git init\n"> <"\t) &&\n"> <"\tcheck_config git-dir-wt-1.git false \"$(pwd)\"\n"> ) } ) (C {(test_expect_success)} {(SQ <"GIT_DIR & GIT_WORK_TREE (2)">)} { (SQ <"\n"> <"\tmkdir git-dir-wt-2.git &&\n"> <"\ttest_must_fail env \\\n"> <"\t\tGIT_WORK_TREE=\"$(pwd)\" \\\n"> <"\t\tGIT_DIR=git-dir-wt-2.git \\\n"> <"\t\tgit --bare init\n"> ) } ) (C {(test_expect_success)} {(SQ )} { (SQ <"\n"> <"\n"> <"\t(\n"> <"\t\tmkdir again &&\n"> <"\t\tcd again &&\n"> <"\t\tgit init >out1 2>err1 &&\n"> <"\t\tgit init >out2 2>err2\n"> <"\t) &&\n"> <"\ttest_i18ngrep \"Initialized empty\" again/out1 &&\n"> <"\ttest_i18ngrep \"Reinitialized existing\" again/out2 &&\n"> <"\t>again/empty &&\n"> <"\ttest_i18ncmp again/empty again/err1 &&\n"> <"\ttest_i18ncmp again/empty again/err2\n"> ) } ) (C {(test_expect_success)} {(SQ <"init with --template">)} { (SQ <"\n"> <"\tmkdir template-source &&\n"> <"\techo content >template-source/file &&\n"> <"\tgit init --template=../template-source template-custom &&\n"> <"\ttest_cmp template-source/file template-custom/.git/file\n"> ) } ) (C {(test_expect_success)} {(SQ <"init with --template (blank)">)} { (SQ <"\n"> <"\tgit init template-plain &&\n"> <"\ttest_path_is_file template-plain/.git/info/exclude &&\n"> <"\tgit init --template= template-blank &&\n"> <"\ttest_path_is_missing template-blank/.git/info/exclude\n"> ) } ) (C {(test_expect_success)} {(SQ <"init with init.templatedir set">)} { (SQ <"\n"> <"\tmkdir templatedir-source &&\n"> <"\techo Content >templatedir-source/file &&\n"> <"\ttest_config_global init.templatedir \"${HOME}/templatedir-source\" &&\n"> <"\t(\n"> <"\t\tmkdir templatedir-set &&\n"> <"\t\tcd templatedir-set &&\n"> <"\t\tsane_unset GIT_TEMPLATE_DIR &&\n"> <"\t\tNO_SET_GIT_TEMPLATE_DIR=t &&\n"> <"\t\texport NO_SET_GIT_TEMPLATE_DIR &&\n"> <"\t\tgit init\n"> <"\t) &&\n"> <"\ttest_cmp templatedir-source/file templatedir-set/.git/file\n"> ) } ) (C {(test_expect_success)} {(SQ <"init --bare/--shared overrides system/global config">)} { (SQ <"\n"> <"\ttest_config_global core.bare false &&\n"> <"\ttest_config_global core.sharedRepository 0640 &&\n"> <"\tgit init --bare --shared=0666 init-bare-shared-override &&\n"> <"\tcheck_config init-bare-shared-override true unset &&\n"> <"\ttest x0666 = \\\n"> <"\tx$(git config -f init-bare-shared-override/config core.sharedRepository)\n"> ) } ) (C {(test_expect_success)} {(SQ <"init honors global core.sharedRepository">)} { (SQ <"\n"> <"\ttest_config_global core.sharedRepository 0666 &&\n"> <"\tgit init shared-honor-global &&\n"> <"\ttest x0666 = \\\n"> <"\tx$(git config -f shared-honor-global/.git/config core.sharedRepository)\n"> ) } ) (C {(test_expect_success)} {(SQ <"init allows insanely long --template">)} {(SQ <"\n"> <"\tgit init --template=$(printf \"x%09999dx\" 1) test\n">)} ) (C {(test_expect_success)} {(SQ <"init creates a new directory">)} { (SQ <"\n"> <"\trm -fr newdir &&\n"> <"\tgit init newdir &&\n"> <"\ttest_path_is_dir newdir/.git/refs\n"> ) } ) (C {(test_expect_success)} {(SQ <"init creates a new bare directory">)} { (SQ <"\n"> <"\trm -fr newdir &&\n"> <"\tgit init --bare newdir &&\n"> <"\ttest_path_is_dir newdir/refs\n"> ) } ) (C {(test_expect_success)} {(SQ <"init recreates a directory">)} { (SQ <"\n"> <"\trm -fr newdir &&\n"> <"\tmkdir newdir &&\n"> <"\tgit init newdir &&\n"> <"\ttest_path_is_dir newdir/.git/refs\n"> ) } ) (C {(test_expect_success)} {(SQ <"init recreates a new bare directory">)} { (SQ <"\n"> <"\trm -fr newdir &&\n"> <"\tmkdir newdir &&\n"> <"\tgit init --bare newdir &&\n"> <"\ttest_path_is_dir newdir/refs\n"> ) } ) (C {(test_expect_success)} {(SQ <"init creates a new deep directory">)} { (SQ <"\n"> <"\trm -fr newdir &&\n"> <"\tgit init newdir/a/b/c &&\n"> <"\ttest_path_is_dir newdir/a/b/c/.git/refs\n"> ) } ) (C {(test_expect_success)} {(POSIXPERM)} {(SQ <"init creates a new deep directory (umask vs. shared)">)} { (SQ <"\n"> <"\trm -fr newdir &&\n"> <"\t(\n"> <"\t\t# Leading directories should honor umask while\n"> <"\t\t# the repository itself should follow \"shared\"\n"> <"\t\tumask 002 &&\n"> <"\t\tgit init --bare --shared=0660 newdir/a/b/c &&\n"> <"\t\ttest_path_is_dir newdir/a/b/c/refs &&\n"> <"\t\tls -ld newdir/a newdir/a/b > lsab.out &&\n"> <"\t\t! grep -v \"^drwxrw[sx]r-x\" lsab.out &&\n"> <"\t\tls -ld newdir/a/b/c > lsc.out &&\n"> <"\t\t! grep -v \"^drwxrw[sx]---\" lsc.out\n"> <"\t)\n"> ) } ) (C {(test_expect_success)} {(SQ <"init notices EEXIST (1)">)} { (SQ <"\n"> <"\trm -fr newdir &&\n"> <"\t>newdir &&\n"> <"\ttest_must_fail git init newdir &&\n"> <"\ttest_path_is_file newdir\n"> ) } ) (C {(test_expect_success)} {(SQ <"init notices EEXIST (2)">)} { (SQ <"\n"> <"\trm -fr newdir &&\n"> <"\tmkdir newdir &&\n"> <"\t>newdir/a &&\n"> <"\ttest_must_fail git init newdir/a/b &&\n"> <"\ttest_path_is_file newdir/a\n"> ) } ) (C {(test_expect_success)} {(POSIXPERM) (Lit_Comma ",") (SANITY)} {(SQ <"init notices EPERM">)} { (SQ <"\n"> <"\trm -fr newdir &&\n"> <"\tmkdir newdir &&\n"> <"\tchmod -w newdir &&\n"> <"\ttest_must_fail git init newdir/a/b\n"> ) } ) (C {(test_expect_success)} {(SQ <"init creates a new bare directory with global --bare">)} { (SQ <"\n"> <"\trm -rf newdir &&\n"> <"\tgit --bare init newdir &&\n"> <"\ttest_path_is_dir newdir/refs\n"> ) } ) (C {(test_expect_success)} {(SQ <"init prefers command line to GIT_DIR">)} { (SQ <"\n"> <"\trm -rf newdir &&\n"> <"\tmkdir otherdir &&\n"> <"\tGIT_DIR=otherdir git --bare init newdir &&\n"> <"\ttest_path_is_dir newdir/refs &&\n"> <"\ttest_path_is_missing otherdir/refs\n"> ) } ) (C {(test_expect_success)} {(SQ <"init with separate gitdir">)} { (SQ <"\n"> <"\trm -rf newdir &&\n"> <"\tgit init --separate-git-dir realgitdir newdir &&\n"> <"\techo \"gitdir: $(pwd)/realgitdir\" >expected &&\n"> <"\ttest_cmp expected newdir/.git &&\n"> <"\ttest_path_is_dir realgitdir/refs\n"> ) } ) (C {(test_expect_success)} {(SQ <"re-init on .git file">)} {(SQ <"\n"> <"\t( cd newdir && git init )\n">)} ) (C {(test_expect_success)} {(SQ <"re-init to update git link">)} { (SQ <"\n"> <"\t(\n"> <"\tcd newdir &&\n"> <"\tgit init --separate-git-dir ../surrealgitdir\n"> <"\t) &&\n"> <"\techo \"gitdir: $(pwd)/surrealgitdir\" >expected &&\n"> <"\ttest_cmp expected newdir/.git &&\n"> <"\ttest_path_is_dir surrealgitdir/refs &&\n"> <"\ttest_path_is_missing realgitdir/refs\n"> ) } ) (C {(test_expect_success)} {(SQ <"re-init to move gitdir">)} { (SQ <"\n"> <"\trm -rf newdir realgitdir surrealgitdir &&\n"> <"\tgit init newdir &&\n"> <"\t(\n"> <"\tcd newdir &&\n"> <"\tgit init --separate-git-dir ../realgitdir\n"> <"\t) &&\n"> <"\techo \"gitdir: $(pwd)/realgitdir\" >expected &&\n"> <"\ttest_cmp expected newdir/.git &&\n"> <"\ttest_path_is_dir realgitdir/refs\n"> ) } ) (C {(test_expect_success)} {(SYMLINKS)} {(SQ <"re-init to move gitdir symlink">)} { (SQ <"\n"> <"\trm -rf newdir realgitdir &&\n"> <"\tgit init newdir &&\n"> <"\t(\n"> <"\tcd newdir &&\n"> <"\tmv .git here &&\n"> <"\tln -s here .git &&\n"> <"\tgit init --separate-git-dir ../realgitdir\n"> <"\t) &&\n"> <"\techo \"gitdir: $(pwd)/realgitdir\" >expected &&\n"> <"\ttest_cmp expected newdir/.git &&\n"> <"\ttest_cmp expected newdir/here &&\n"> <"\ttest_path_is_dir realgitdir/refs\n"> ) } ) (FuncDef name: is_hidden body: (BraceGroup children: [ (Case to_match: { (DQ (CommandSubPart command_list: (CommandList children: [(C {(attrib)} {(DQ ($ VSub_Number "$1"))})] ) left_token: spids: [879 885] ) ) } arms: [ (case_arm pat_list: [ {(Lit_Other "*") (H) (Lit_Other "*") (Lit_Other "?") (Lit_Other ":") (Lit_Other "*")} ] action: [(ControlFlow token: arg_word:{(0)})] spids: [890 896 901 -1] ) ] spids: [876 888 903] ) (ControlFlow token: arg_word:{(1)}) ] spids: [869] ) spids: [864 868] ) (C {(test_expect_success)} {(MINGW)} {(SQ <".git hidden">)} { (SQ <"\n"> <"\trm -rf newdir &&\n"> <"\t(\n"> <"\t\tunset GIT_DIR GIT_WORK_TREE\n"> <"\t\tmkdir newdir &&\n"> <"\t\tcd newdir &&\n"> <"\t\tgit init &&\n"> <"\t\tis_hidden .git\n"> <"\t) &&\n"> <"\tcheck_config newdir/.git false unset\n"> ) } ) (C {(test_expect_success)} {(MINGW)} {(SQ <"bare git dir not hidden">)} { (SQ <"\n"> <"\trm -rf newdir &&\n"> <"\t(\n"> <"\t\tunset GIT_DIR GIT_WORK_TREE GIT_CONFIG\n"> <"\t\tmkdir newdir &&\n"> <"\t\tcd newdir &&\n"> <"\t\tgit --bare init\n"> <"\t) &&\n"> <"\t! is_hidden newdir\n"> ) } ) (C {(test_expect_success)} {(SQ <"remote init from does not use config from cwd">)} { (SQ <"\n"> <"\trm -rf newdir &&\n"> <"\ttest_config core.logallrefupdates true &&\n"> <"\tgit init newdir &&\n"> <"\techo true >expect &&\n"> <"\tgit -C newdir config --bool core.logallrefupdates >actual &&\n"> <"\ttest_cmp expect actual\n"> ) } ) (C {(test_expect_success)} {(SQ <"re-init from a linked worktree">)} { (SQ <"\n"> <"\tgit init main-worktree &&\n"> <"\t(\n"> <"\t\tcd main-worktree &&\n"> <"\t\ttest_commit first &&\n"> <"\t\tgit worktree add ../linked-worktree &&\n"> <"\t\tmv .git/info/exclude expected-exclude &&\n"> <"\t\tcp .git/config expected-config &&\n"> <"\t\tfind .git/worktrees -print | sort >expected &&\n"> <"\t\tgit -C ../linked-worktree init &&\n"> <"\t\ttest_cmp expected-exclude .git/info/exclude &&\n"> <"\t\ttest_cmp expected-config .git/config &&\n"> <"\t\tfind .git/worktrees -print | sort >actual &&\n"> <"\t\ttest_cmp expected actual\n"> <"\t)\n"> ) } ) (C {(test_done)}) ] )