#!/bin/sh global test_description := ''test various @{X} syntax combinations together'' source ./test-lib.sh proc check { test_expect_$(4:-success) "$1 = $3" " echo '$3' >expect && if test '$2' = 'commit' then git log -1 --format=%s '$1' >actual elif test '$2' = 'ref' then git rev-parse --symbolic-full-name '$1' >actual else git cat-file -p '$1' >actual fi && test_cmp expect actual " } proc nonsense { test_expect_$(2:-success) "$1 is nonsensical" " test_must_fail git rev-parse --verify '$1' " } proc fail { @Argv failure } test_expect_success 'setup' ' test_commit master-one && test_commit master-two && git checkout -b upstream-branch && test_commit upstream-one && test_commit upstream-two && if test_have_prereq !MINGW then git checkout -b @/at-test fi && git checkout -b @@/at-test && git checkout -b @at-test && git checkout -b old-branch && test_commit old-one && test_commit old-two && git checkout -b new-branch && test_commit new-one && test_commit new-two && git branch -u master old-branch && git branch -u upstream-branch new-branch ' check HEAD ref refs/heads/new-branch check "@{1}" commit new-one check "HEAD@{1}" commit new-one check "@{now}" commit new-two check "HEAD@{now}" commit new-two check "@{-1}" ref refs/heads/old-branch check "@{-1}@{0}" commit old-two check "@{-1}@{1}" commit old-one check "@{u}" ref refs/heads/upstream-branch check "HEAD@{u}" ref refs/heads/upstream-branch check "@{u}@{1}" commit upstream-one check "@{-1}@{u}" ref refs/heads/master check "@{-1}@{u}@{1}" commit master-one check "@" commit new-two check "@@{u}" ref refs/heads/upstream-branch check "@@/at-test" ref refs/heads/@@/at-test test_have_prereq MINGW || check "@/at-test" ref refs/heads/@/at-test check "@at-test" ref refs/heads/@at-test nonsense "@{u}@{-1}" nonsense "@{0}@{0}" nonsense "@{1}@{u}" nonsense "HEAD@{-1}" nonsense "@{-1}@{-1}" # @{N} versus HEAD@{N} check "HEAD@{3}" commit old-two nonsense "@{3}" test_expect_success 'switch to old-branch' ' git checkout old-branch ' check HEAD ref refs/heads/old-branch check "HEAD@{1}" commit new-two check "@{1}" commit old-one test_expect_success 'create path with @' ' echo content >normal && echo content >fun@ny && git add normal fun@ny && git commit -m "funny path" ' check "@:normal" blob content check "@:fun@ny" blob content test_done (CommandList children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:test_description) op: Equal rhs: {(SQ <"test various @{X} syntax combinations together">)} spids: [4] ) ] spids: [4] ) (C {(.)} {(./test-lib.sh)}) (FuncDef name: check body: (BraceGroup children: [ (C {(test_expect_) (BracedVarSub token: suffix_op: (StringUnary op_id:VTest_ColonHyphen arg_word:{(success)}) spids: [22 26] ) } {(DQ ($ VSub_Number "$1") (" = ") ($ VSub_Number "$3"))} { (DQ ("\n") ("\t\techo '") ($ VSub_Number "$3") ("' >expect &&\n") ("\t\tif test '") ($ VSub_Number "$2") ("' = 'commit'\n") ("\t\tthen\n") ("\t\t\tgit log -1 --format=%s '") ($ VSub_Number "$1") ("' >actual\n") ("\t\telif test '") ($ VSub_Number "$2") ("' = 'ref'\n") ("\t\tthen\n") ("\t\t\tgit rev-parse --symbolic-full-name '") ($ VSub_Number "$1") ("' >actual\n") ("\t\telse\n") ("\t\t\tgit cat-file -p '") ($ VSub_Number "$1") ("' >actual\n") ("\t\tfi &&\n") ("\t\ttest_cmp expect actual\n") ("\t") ) } ) ] spids: [18] ) spids: [14 17] ) (FuncDef name: nonsense body: (BraceGroup children: [ (C {(test_expect_) (BracedVarSub token: suffix_op: (StringUnary op_id:VTest_ColonHyphen arg_word:{(success)}) spids: [73 77] ) } {(DQ ($ VSub_Number "$1") (" is nonsensical"))} { (DQ ("\n") ("\t\ttest_must_fail git rev-parse --verify '") ($ VSub_Number "$1") ("'\n") ("\t") ) } ) ] spids: [69] ) spids: [65 68] ) (FuncDef name: fail body: (BraceGroup children:[(C {(DQ ($ VSub_At "$@"))} {(failure)})] spids:[99]) spids: [95 98] ) (C {(test_expect_success)} {(SQ )} { (SQ <"\n"> <"\ttest_commit master-one &&\n"> <"\ttest_commit master-two &&\n"> <"\tgit checkout -b upstream-branch &&\n"> <"\ttest_commit upstream-one &&\n"> <"\ttest_commit upstream-two &&\n"> <"\tif test_have_prereq !MINGW\n"> <"\tthen\n"> <"\t\tgit checkout -b @/at-test\n"> <"\tfi &&\n"> <"\tgit checkout -b @@/at-test &&\n"> <"\tgit checkout -b @at-test &&\n"> <"\tgit checkout -b old-branch &&\n"> <"\ttest_commit old-one &&\n"> <"\ttest_commit old-two &&\n"> <"\tgit checkout -b new-branch &&\n"> <"\ttest_commit new-one &&\n"> <"\ttest_commit new-two &&\n"> <"\tgit branch -u master old-branch &&\n"> <"\tgit branch -u upstream-branch new-branch\n"> ) } ) (C {(check)} {(HEAD)} {(ref)} {(refs/heads/new-branch)}) (C {(check)} {(DQ ("@{1}"))} {(commit)} {(new-one)}) (C {(check)} {(DQ ("HEAD@{1}"))} {(commit)} {(new-one)}) (C {(check)} {(DQ ("@{now}"))} {(commit)} {(new-two)}) (C {(check)} {(DQ ("HEAD@{now}"))} {(commit)} {(new-two)}) (C {(check)} {(DQ ("@{-1}"))} {(ref)} {(refs/heads/old-branch)}) (C {(check)} {(DQ ("@{-1}@{0}"))} {(commit)} {(old-two)}) (C {(check)} {(DQ ("@{-1}@{1}"))} {(commit)} {(old-one)}) (C {(check)} {(DQ ("@{u}"))} {(ref)} {(refs/heads/upstream-branch)}) (C {(check)} {(DQ ("HEAD@{u}"))} {(ref)} {(refs/heads/upstream-branch)}) (C {(check)} {(DQ ("@{u}@{1}"))} {(commit)} {(upstream-one)}) (C {(check)} {(DQ ("@{-1}@{u}"))} {(ref)} {(refs/heads/master)}) (C {(check)} {(DQ ("@{-1}@{u}@{1}"))} {(commit)} {(master-one)}) (C {(check)} {(DQ ("@"))} {(commit)} {(new-two)}) (C {(check)} {(DQ ("@@{u}"))} {(ref)} {(refs/heads/upstream-branch)}) (C {(check)} {(DQ ("@@/at-test"))} {(ref)} {(refs/heads/) (Lit_Other "@") (Lit_Other "@") (/at-test)}) (AndOr children: [ (C {(test_have_prereq)} {(MINGW)}) (C {(check)} {(DQ ("@/at-test"))} {(ref)} {(refs/heads/) (Lit_Other "@") (/at-test)}) ] op_id: Op_DPipe ) (C {(check)} {(DQ ("@at-test"))} {(ref)} {(refs/heads/) (Lit_Other "@") (at-test)}) (C {(nonsense)} {(DQ ("@{u}@{-1}"))}) (C {(nonsense)} {(DQ ("@{0}@{0}"))}) (C {(nonsense)} {(DQ ("@{1}@{u}"))}) (C {(nonsense)} {(DQ ("HEAD@{-1}"))}) (C {(nonsense)} {(DQ ("@{-1}@{-1}"))}) (C {(check)} {(DQ ("HEAD@{3}"))} {(commit)} {(old-two)}) (C {(nonsense)} {(DQ ("@{3}"))}) (C {(test_expect_success)} {(SQ <"switch to old-branch">)} {(SQ <"\n"> <"\tgit checkout old-branch\n">)} ) (C {(check)} {(HEAD)} {(ref)} {(refs/heads/old-branch)}) (C {(check)} {(DQ ("HEAD@{1}"))} {(commit)} {(new-two)}) (C {(check)} {(DQ ("@{1}"))} {(commit)} {(old-one)}) (C {(test_expect_success)} {(SQ <"create path with @">)} { (SQ <"\n"> <"\techo content >normal &&\n"> <"\techo content >fun@ny &&\n"> <"\tgit add normal fun@ny &&\n"> <"\tgit commit -m \"funny path\"\n"> ) } ) (C {(check)} {(DQ ("@:normal"))} {(blob)} {(content)}) (C {(check)} {(DQ ("@:fun@ny"))} {(blob)} {(content)}) (C {(test_done)}) ] )