#!/bin/sh global test_description := ''selecting remote repo in ambiguous cases'' source ./test-lib.sh proc reset { rm -rf foo foo.git fetch clone } proc make_tree { git init $1 && shell {cd $1 && test_commit $1} } proc make_bare { git init --bare $1 && shell {cd $1 && global tree := $[git hash-object -w -t tree /dev/null] && global commit := $[echo $1 | git commit-tree $tree] && git update-ref HEAD $commit } } proc get { git init --bare fetch && shell {cd fetch && git fetch "../$1"} && git clone $1 clone } proc check { echo $1 >expect && shell {cd fetch && git log -1 --format=%s FETCH_HEAD} >actual.fetch && shell {cd clone && git log -1 --format=%s HEAD} >actual.clone && test_cmp expect actual.fetch && test_cmp expect actual.clone } test_expect_success 'find .git dir in worktree' ' reset && make_tree foo && get foo && check foo ' test_expect_success 'automagically add .git suffix' ' reset && make_bare foo.git && get foo && check foo.git ' test_expect_success 'automagically add .git suffix to worktree' ' reset && make_tree foo.git && get foo && check foo.git ' test_expect_success 'prefer worktree foo over bare foo.git' ' reset && make_tree foo && make_bare foo.git && get foo && check foo ' test_expect_success 'prefer bare foo over bare foo.git' ' reset && make_bare foo && make_bare foo.git && get foo && check foo ' test_expect_success 'disambiguate with full foo.git' ' reset && make_bare foo && make_bare foo.git && get foo.git && check foo.git ' test_expect_success 'we are not fooled by non-git foo directory' ' reset && make_bare foo.git && mkdir foo && get foo && check foo.git ' test_expect_success 'prefer inner .git over outer bare' ' reset && make_tree foo && make_bare foo.git && mv foo/.git foo.git && get foo.git && check foo ' test_done (CommandList children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:test_description) op: Equal rhs: {(SQ <"selecting remote repo in ambiguous cases">)} spids: [4] ) ] spids: [4] ) (C {(.)} {(./test-lib.sh)}) (FuncDef name: reset body: (BraceGroup children: [(C {(rm)} {(-rf)} {(foo)} {(foo.git)} {(fetch)} {(clone)})] spids: [18] ) spids: [14 17] ) (FuncDef name: make_tree body: (BraceGroup children: [ (AndOr children: [ (C {(git)} {(init)} {(DQ ($ VSub_Number "$1"))}) (Subshell child: (AndOr children: [ (C {(cd)} {(DQ ($ VSub_Number "$1"))}) (C {(test_commit)} {(DQ ($ VSub_Number "$1"))}) ] op_id: Op_DAmp ) spids: [54 68] ) ] op_id: Op_DAmp ) ] spids: [40] ) spids: [36 39] ) (FuncDef name: make_bare body: (BraceGroup children: [ (AndOr children: [ (C {(git)} {(init)} {(--bare)} {(DQ ($ VSub_Number "$1"))}) (Subshell child: (AndOr children: [ (C {(cd)} {(DQ ($ VSub_Number "$1"))}) (AndOr children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:tree) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (C {(git)} {(hash-object)} {(-w)} {(-t)} {(tree)} {(/dev/null)} ) ] ) left_token: spids: [104 116] ) } spids: [103] ) ] spids: [103] ) (AndOr children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:commit) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(echo)} {(DQ ($ VSub_Number "$1"))}) (C {(git)} {(commit-tree)} {($ VSub_Name "$tree")}) ] negated: False ) ] ) left_token: spids: [122 136] ) } spids: [121] ) ] spids: [121] ) (C {(git)} {(update-ref)} {(HEAD)} {($ VSub_Name "$commit")}) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) spids: [93 150] ) ] op_id: Op_DAmp ) ] spids: [77] ) spids: [73 76] ) (FuncDef name: get body: (BraceGroup children: [ (AndOr children: [ (C {(git)} {(init)} {(--bare)} {(fetch)}) (AndOr children: [ (Subshell child: (AndOr children: [ (C {(cd)} {(fetch)}) (C {(git)} {(fetch)} {(DQ (../) ($ VSub_Number "$1"))}) ] op_id: Op_DAmp ) spids: [173 188] ) (C {(git)} {(clone)} {(DQ ($ VSub_Number "$1"))} {(clone)}) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] spids: [159] ) spids: [155 158] ) (FuncDef name: check body: (BraceGroup children: [ (AndOr children: [ (SimpleCommand words: [{(echo)} {(DQ ($ VSub_Number "$1"))}] redirects: [(Redir op_id:Redir_Great fd:-1 arg_word:{(expect)} spids:[219])] ) (AndOr children: [ (Subshell child: (AndOr children: [ (C {(cd)} {(fetch)}) (C {(git)} {(log)} {(-1)} {(--format) (Lit_Other "=") (Lit_Other "%") (s)} {(FETCH_HEAD)} ) ] op_id: Op_DAmp ) redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(actual.fetch)} spids: [246] ) ] spids: [225 244] ) (AndOr children: [ (Subshell child: (AndOr children: [ (C {(cd)} {(clone)}) (C {(git)} {(log)} {(-1)} {(--format) (Lit_Other "=") (Lit_Other "%") (s)} {(HEAD)} ) ] op_id: Op_DAmp ) redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(actual.clone)} spids: [273] ) ] spids: [252 271] ) (AndOr children: [ (C {(test_cmp)} {(expect)} {(actual.fetch)}) (C {(test_cmp)} {(expect)} {(actual.clone)}) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] spids: [210] ) spids: [206 209] ) (C {(test_expect_success)} {(SQ <"find .git dir in worktree">)} {(SQ <"\n"> <"\treset &&\n"> <"\tmake_tree foo &&\n"> <"\tget foo &&\n"> <"\tcheck foo\n">)} ) (C {(test_expect_success)} {(SQ <"automagically add .git suffix">)} { (SQ <"\n"> <"\treset &&\n"> <"\tmake_bare foo.git &&\n"> <"\tget foo &&\n"> <"\tcheck foo.git\n">) } ) (C {(test_expect_success)} {(SQ <"automagically add .git suffix to worktree">)} { (SQ <"\n"> <"\treset &&\n"> <"\tmake_tree foo.git &&\n"> <"\tget foo &&\n"> <"\tcheck foo.git\n">) } ) (C {(test_expect_success)} {(SQ <"prefer worktree foo over bare foo.git">)} { (SQ <"\n"> <"\treset &&\n"> <"\tmake_tree foo &&\n"> <"\tmake_bare foo.git &&\n"> <"\tget foo &&\n"> <"\tcheck foo\n"> ) } ) (C {(test_expect_success)} {(SQ <"prefer bare foo over bare foo.git">)} { (SQ <"\n"> <"\treset &&\n"> <"\tmake_bare foo &&\n"> <"\tmake_bare foo.git &&\n"> <"\tget foo &&\n"> <"\tcheck foo\n"> ) } ) (C {(test_expect_success)} {(SQ <"disambiguate with full foo.git">)} { (SQ <"\n"> <"\treset &&\n"> <"\tmake_bare foo &&\n"> <"\tmake_bare foo.git &&\n"> <"\tget foo.git &&\n"> <"\tcheck foo.git\n"> ) } ) (C {(test_expect_success)} {(SQ <"we are not fooled by non-git foo directory">)} { (SQ <"\n"> <"\treset &&\n"> <"\tmake_bare foo.git &&\n"> <"\tmkdir foo &&\n"> <"\tget foo &&\n"> <"\tcheck foo.git\n"> ) } ) (C {(test_expect_success)} {(SQ <"prefer inner .git over outer bare">)} { (SQ <"\n"> <"\treset &&\n"> <"\tmake_tree foo &&\n"> <"\tmake_bare foo.git &&\n"> <"\tmv foo/.git foo.git &&\n"> <"\tget foo.git &&\n"> <"\tcheck foo\n"> ) } ) (C {(test_done)}) ] )