#!/bin/sh global test_description := ''cd_to_toplevel'' source ./test-lib.sh global EXEC_PATH := $[git --exec-path] test_have_prereq !MINGW || matchstr $EXEC_PATH { [A-Za-z]:/* { global EXEC_PATH := ""/$(EXEC_PATH%%:*)$(EXEC_PATH#?:)"" } } proc test_cd_to_toplevel { test_expect_success $3 $2 ' ( cd '"'$1'"' && PATH="$EXEC_PATH:$PATH" && . git-sh-setup && cd_to_toplevel && [ "$(pwd -P)" = "$TOPLEVEL" ] ) ' } global TOPLEVEL := ""$[pwd -P]/repo"" mkdir -p repo/sub/dir mv .git repo/ global SUBDIRECTORY_OK := '1' test_cd_to_toplevel repo 'at physical root' test_cd_to_toplevel repo/sub/dir 'at physical subdir' ln -s repo symrepo !2 >/dev/null test_cd_to_toplevel symrepo 'at symbolic root' SYMLINKS ln -s repo/sub/dir subdir-link !2 >/dev/null test_cd_to_toplevel subdir-link 'at symbolic subdir' SYMLINKS cd repo ln -s sub/dir internal-link !2 >/dev/null test_cd_to_toplevel internal-link 'at internal symbolic subdir' SYMLINKS test_done (CommandList children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:test_description) op: Equal rhs: {(SQ )} spids: [4] ) ] spids: [4] ) (C {(.)} {(./test-lib.sh)}) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:EXEC_PATH) op: Equal rhs: { (DQ (CommandSubPart command_list: (CommandList children:[(C {(git)} {(--exec-path)})]) left_token: spids: [17 21] ) ) } spids: [15] ) ] spids: [15] ) (AndOr children: [ (C {(test_have_prereq)} {(KW_Bang "!") (MINGW)}) (Case to_match: {(DQ ($ VSub_Name "$EXEC_PATH"))} arms: [ (case_arm pat_list: [ {(Lit_Other "[") (A-Za-z) (Lit_Other "]") (Lit_Other ":") (/) (Lit_Other "*")} ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:EXEC_PATH) op: Equal rhs: { (DQ (/) (BracedVarSub token: suffix_op: (StringUnary op_id:VOp1_DPercent arg_word:{(":*")}) spids: [51 55] ) (BracedVarSub token: suffix_op: (StringUnary op_id:VOp1_Pound arg_word:{("?:")}) spids: [56 60] ) ) } spids: [48] ) ] spids: [48] ) ] spids: [39 45 64 -1] ) ] spids: [31 37 66] ) ] op_id: Op_DPipe ) (FuncDef name: test_cd_to_toplevel body: (BraceGroup children: [ (C {(test_expect_success)} {($ VSub_Number "$3")} {(DQ ($ VSub_Number "$2"))} {(SQ <"\n"> <"\t\t(\n"> <"\t\t\tcd ">) (DQ ("'") ($ VSub_Number "$1") ("'")) (SQ <" &&\n"> <"\t\t\tPATH=\"$EXEC_PATH:$PATH\" &&\n"> <"\t\t\t. git-sh-setup &&\n"> <"\t\t\tcd_to_toplevel &&\n"> <"\t\t\t[ \"$(pwd -P)\" = \"$TOPLEVEL\" ]\n"> <"\t\t)\n"> <"\t"> ) } ) ] spids: [74] ) spids: [69 73] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:TOPLEVEL) op: Equal rhs: { (DQ (CommandSubPart command_list: (CommandList children:[(C {(pwd)} {(-P)})]) left_token: spids: [110 114] ) (/repo) ) } spids: [108] ) ] spids: [108] ) (C {(mkdir)} {(-p)} {(repo/sub/dir)}) (C {(mv)} {(.git)} {(repo/)}) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:SUBDIRECTORY_OK) op:Equal rhs:{(1)} spids:[130])] spids: [130] ) (C {(test_cd_to_toplevel)} {(repo)} {(SQ <"at physical root">)}) (C {(test_cd_to_toplevel)} {(repo/sub/dir)} {(SQ <"at physical subdir">)}) (SimpleCommand words: [{(ln)} {(-s)} {(repo)} {(symrepo)}] redirects: [(Redir op_id:Redir_Great fd:2 arg_word:{(/dev/null)} spids:[160])] ) (C {(test_cd_to_toplevel)} {(symrepo)} {(SQ <"at symbolic root">)} {(SYMLINKS)}) (SimpleCommand words: [{(ln)} {(-s)} {(repo/sub/dir)} {(subdir-link)}] redirects: [(Redir op_id:Redir_Great fd:2 arg_word:{(/dev/null)} spids:[182])] ) (C {(test_cd_to_toplevel)} {(subdir-link)} {(SQ <"at symbolic subdir">)} {(SYMLINKS)}) (C {(cd)} {(repo)}) (SimpleCommand words: [{(ln)} {(-s)} {(sub/dir)} {(internal-link)}] redirects: [(Redir op_id:Redir_Great fd:2 arg_word:{(/dev/null)} spids:[208])] ) (C {(test_cd_to_toplevel)} {(internal-link)} {(SQ <"at internal symbolic subdir">)} {(SYMLINKS)}) (C {(test_done)}) ] )