t / t2019-checkout-ambiguous-ref.shon commit Merge branch 'nd/clone-linked-checkout' (b9d23c2)
   1#!/bin/sh
   2
   3test_description='checkout handling of ambiguous (branch/tag) refs'
   4. ./test-lib.sh
   5
   6test_expect_success 'setup ambiguous refs' '
   7        test_commit branch file &&
   8        git branch ambiguity &&
   9        git branch vagueness &&
  10        test_commit tag file &&
  11        git tag ambiguity &&
  12        git tag vagueness HEAD:file &&
  13        test_commit other file
  14'
  15
  16test_expect_success 'checkout ambiguous ref succeeds' '
  17        git checkout ambiguity >stdout 2>stderr
  18'
  19
  20test_expect_success 'checkout produces ambiguity warning' '
  21        grep "warning.*ambiguous" stderr
  22'
  23
  24test_expect_success 'checkout chooses branch over tag' '
  25        echo refs/heads/ambiguity >expect &&
  26        git symbolic-ref HEAD >actual &&
  27        test_cmp expect actual &&
  28        echo branch >expect &&
  29        test_cmp expect file
  30'
  31
  32test_expect_success 'checkout reports switch to branch' '
  33        test_i18ngrep "Switched to branch" stderr &&
  34        test_i18ngrep ! "^HEAD is now at" stderr
  35'
  36
  37test_expect_success 'checkout vague ref succeeds' '
  38        git checkout vagueness >stdout 2>stderr &&
  39        test_set_prereq VAGUENESS_SUCCESS
  40'
  41
  42test_expect_success VAGUENESS_SUCCESS 'checkout produces ambiguity warning' '
  43        grep "warning.*ambiguous" stderr
  44'
  45
  46test_expect_success VAGUENESS_SUCCESS 'checkout chooses branch over tag' '
  47        echo refs/heads/vagueness >expect &&
  48        git symbolic-ref HEAD >actual &&
  49        test_cmp expect actual &&
  50        echo branch >expect &&
  51        test_cmp expect file
  52'
  53
  54test_expect_success VAGUENESS_SUCCESS 'checkout reports switch to branch' '
  55        test_i18ngrep "Switched to branch" stderr &&
  56        test_i18ngrep ! "^HEAD is now at" stderr
  57'
  58
  59test_expect_success 'wildcard ambiguation, paths win' '
  60        git init ambi &&
  61        (
  62                cd ambi &&
  63                echo a >a.c &&
  64                git add a.c &&
  65                echo b >a.c &&
  66                git checkout "*.c" &&
  67                echo a >expect &&
  68                test_cmp expect a.c
  69        )
  70'
  71
  72test_expect_success !MINGW 'wildcard ambiguation, refs lose' '
  73        git init ambi2 &&
  74        (
  75                cd ambi2 &&
  76                echo a >"*.c" &&
  77                git add . &&
  78                test_must_fail git show :"*.c" &&
  79                git show :"*.c" -- >actual &&
  80                echo a >expect &&
  81                test_cmp expect actual
  82        )
  83'
  84
  85test_done