#!/bin/sh global test_description := ''checkout and pathspecs/refspecs ambiguities'' source ./test-lib.sh test_expect_success 'setup' ' echo hello >world && echo hello >all && git add all world && git commit -m initial && git branch world ' test_expect_success 'reference must be a tree' ' test_must_fail git checkout $(git hash-object ./all) -- ' test_expect_success 'branch switching' ' test "refs/heads/master" = "$(git symbolic-ref HEAD)" && git checkout world -- && test "refs/heads/world" = "$(git symbolic-ref HEAD)" ' test_expect_success 'checkout world from the index' ' echo bye > world && git checkout -- world && git diff --exit-code --quiet ' test_expect_success 'non ambiguous call' ' git checkout all ' test_expect_success 'allow the most common case' ' git checkout world && test "refs/heads/world" = "$(git symbolic-ref HEAD)" ' test_expect_success 'check ambiguity' ' test_must_fail git checkout world all ' test_expect_success 'check ambiguity in subdir' ' mkdir sub && # not ambiguous because sub/world does not exist git -C sub checkout world ../all && echo hello >sub/world && # ambiguous because sub/world does exist test_must_fail git -C sub checkout world ../all ' test_expect_success 'disambiguate checking out from a tree-ish' ' echo bye > world && git checkout world -- world && git diff --exit-code --quiet ' test_expect_success 'accurate error message with more than one ref' ' test_must_fail git checkout HEAD master -- 2>actual && test_i18ngrep 2 actual && test_i18ngrep "one reference expected, 2 given" actual ' test_done (CommandList children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:test_description) op: Equal rhs: {(SQ <"checkout and pathspecs/refspecs ambiguities">)} spids: [4] ) ] spids: [4] ) (C {(.)} {(./test-lib.sh)}) (C {(test_expect_success)} {(SQ )} { (SQ <"\n"> <"\techo hello >world &&\n"> <"\techo hello >all &&\n"> <"\tgit add all world &&\n"> <"\tgit commit -m initial &&\n"> <"\tgit branch world\n"> ) } ) (C {(test_expect_success)} {(SQ <"reference must be a tree">)} {(SQ <"\n"> <"\ttest_must_fail git checkout $(git hash-object ./all) --\n">)} ) (C {(test_expect_success)} {(SQ <"branch switching">)} { (SQ <"\n"> <"\ttest \"refs/heads/master\" = \"$(git symbolic-ref HEAD)\" &&\n"> <"\tgit checkout world -- &&\n"> <"\ttest \"refs/heads/world\" = \"$(git symbolic-ref HEAD)\"\n"> ) } ) (C {(test_expect_success)} {(SQ <"checkout world from the index">)} { (SQ <"\n"> <"\techo bye > world &&\n"> <"\tgit checkout -- world &&\n"> <"\tgit diff --exit-code --quiet\n"> ) } ) (C {(test_expect_success)} {(SQ <"non ambiguous call">)} {(SQ <"\n"> <"\tgit checkout all\n">)}) (C {(test_expect_success)} {(SQ <"allow the most common case">)} { (SQ <"\n"> <"\tgit checkout world &&\n"> <"\ttest \"refs/heads/world\" = \"$(git symbolic-ref HEAD)\"\n"> ) } ) (C {(test_expect_success)} {(SQ <"check ambiguity">)} {(SQ <"\n"> <"\ttest_must_fail git checkout world all\n">)} ) (C {(test_expect_success)} {(SQ <"check ambiguity in subdir">)} { (SQ <"\n"> <"\tmkdir sub &&\n"> <"\t# not ambiguous because sub/world does not exist\n"> <"\tgit -C sub checkout world ../all &&\n"> <"\techo hello >sub/world &&\n"> <"\t# ambiguous because sub/world does exist\n"> <"\ttest_must_fail git -C sub checkout world ../all\n"> ) } ) (C {(test_expect_success)} {(SQ <"disambiguate checking out from a tree-ish">)} { (SQ <"\n"> <"\techo bye > world &&\n"> <"\tgit checkout world -- world &&\n"> <"\tgit diff --exit-code --quiet\n"> ) } ) (C {(test_expect_success)} {(SQ <"accurate error message with more than one ref">)} { (SQ <"\n"> <"\ttest_must_fail git checkout HEAD master -- 2>actual &&\n"> <"\ttest_i18ngrep 2 actual &&\n"> <"\ttest_i18ngrep \"one reference expected, 2 given\" actual\n"> ) } ) (C {(test_done)}) ] )