t / t1402-check-ref-format.shon commit t4018 (funcname patterns): make configuration easier to track (f792a0b)
   1#!/bin/sh
   2
   3test_description='Test git check-ref-format'
   4
   5. ./test-lib.sh
   6
   7valid_ref() {
   8        test_expect_success "ref name '$1' is valid" \
   9                "git check-ref-format '$1'"
  10}
  11invalid_ref() {
  12        test_expect_success "ref name '$1' is not valid" \
  13                "test_must_fail git check-ref-format '$1'"
  14}
  15
  16valid_ref 'heads/foo'
  17invalid_ref 'foo'
  18valid_ref 'foo/bar/baz'
  19valid_ref 'refs///heads/foo'
  20invalid_ref 'heads/foo/'
  21invalid_ref './foo'
  22invalid_ref '.refs/foo'
  23invalid_ref 'heads/foo..bar'
  24invalid_ref 'heads/foo?bar'
  25valid_ref 'foo./bar'
  26invalid_ref 'heads/foo.lock'
  27valid_ref 'heads/foo@bar'
  28invalid_ref 'heads/v@{ation'
  29invalid_ref 'heads/foo\bar'
  30
  31test_expect_success "check-ref-format --branch @{-1}" '
  32        T=$(git write-tree) &&
  33        sha1=$(echo A | git commit-tree $T) &&
  34        git update-ref refs/heads/master $sha1 &&
  35        git update-ref refs/remotes/origin/master $sha1 &&
  36        git checkout master &&
  37        git checkout origin/master &&
  38        git checkout master &&
  39        refname=$(git check-ref-format --branch @{-1}) &&
  40        test "$refname" = "$sha1" &&
  41        refname2=$(git check-ref-format --branch @{-2}) &&
  42        test "$refname2" = master'
  43
  44test_expect_success 'check-ref-format --branch from subdir' '
  45        mkdir subdir &&
  46
  47        T=$(git write-tree) &&
  48        sha1=$(echo A | git commit-tree $T) &&
  49        git update-ref refs/heads/master $sha1 &&
  50        git update-ref refs/remotes/origin/master $sha1 &&
  51        git checkout master &&
  52        git checkout origin/master &&
  53        git checkout master &&
  54        refname=$(
  55                cd subdir &&
  56                git check-ref-format --branch @{-1}
  57        ) &&
  58        test "$refname" = "$sha1"
  59'
  60
  61valid_ref_normalized() {
  62        test_expect_success "ref name '$1' simplifies to '$2'" "
  63                refname=\$(git check-ref-format --print '$1') &&
  64                test \"\$refname\" = '$2'"
  65}
  66invalid_ref_normalized() {
  67        test_expect_success "check-ref-format --print rejects '$1'" "
  68                test_must_fail git check-ref-format --print '$1'"
  69}
  70
  71valid_ref_normalized 'heads/foo' 'heads/foo'
  72valid_ref_normalized 'refs///heads/foo' 'refs/heads/foo'
  73invalid_ref_normalized 'foo'
  74invalid_ref_normalized 'heads/foo/../bar'
  75invalid_ref_normalized 'heads/./foo'
  76invalid_ref_normalized 'heads\foo'
  77
  78test_done