t / t1404-update-ref-df-conflicts.shon commit Merge branch 'po/doc-branch-desc' (a265435)
   1#!/bin/sh
   2
   3test_description='Test git update-ref with D/F conflicts'
   4. ./test-lib.sh
   5
   6test_update_rejected () {
   7        prefix="$1" &&
   8        before="$2" &&
   9        pack="$3" &&
  10        create="$4" &&
  11        error="$5" &&
  12        printf "create $prefix/%s $C\n" $before |
  13        git update-ref --stdin &&
  14        git for-each-ref $prefix >unchanged &&
  15        if $pack
  16        then
  17                git pack-refs --all
  18        fi &&
  19        printf "create $prefix/%s $C\n" $create >input &&
  20        test_must_fail git update-ref --stdin <input 2>output.err &&
  21        grep -F "$error" output.err &&
  22        git for-each-ref $prefix >actual &&
  23        test_cmp unchanged actual
  24}
  25
  26Q="'"
  27
  28test_expect_success 'setup' '
  29
  30        git commit --allow-empty -m Initial &&
  31        C=$(git rev-parse HEAD)
  32
  33'
  34
  35test_expect_success 'existing loose ref is a simple prefix of new' '
  36
  37        prefix=refs/1l &&
  38        test_update_rejected $prefix "a c e" false "b c/x d" \
  39                "$Q$prefix/c$Q exists; cannot create $Q$prefix/c/x$Q"
  40
  41'
  42
  43test_expect_success 'existing packed ref is a simple prefix of new' '
  44
  45        prefix=refs/1p &&
  46        test_update_rejected $prefix "a c e" true "b c/x d" \
  47                "$Q$prefix/c$Q exists; cannot create $Q$prefix/c/x$Q"
  48
  49'
  50
  51test_expect_success 'existing loose ref is a deeper prefix of new' '
  52
  53        prefix=refs/2l &&
  54        test_update_rejected $prefix "a c e" false "b c/x/y d" \
  55                "$Q$prefix/c$Q exists; cannot create $Q$prefix/c/x/y$Q"
  56
  57'
  58
  59test_expect_success 'existing packed ref is a deeper prefix of new' '
  60
  61        prefix=refs/2p &&
  62        test_update_rejected $prefix "a c e" true "b c/x/y d" \
  63                "$Q$prefix/c$Q exists; cannot create $Q$prefix/c/x/y$Q"
  64
  65'
  66
  67test_expect_success 'new ref is a simple prefix of existing loose' '
  68
  69        prefix=refs/3l &&
  70        test_update_rejected $prefix "a c/x e" false "b c d" \
  71                "$Q$prefix/c/x$Q exists; cannot create $Q$prefix/c$Q"
  72
  73'
  74
  75test_expect_success 'new ref is a simple prefix of existing packed' '
  76
  77        prefix=refs/3p &&
  78        test_update_rejected $prefix "a c/x e" true "b c d" \
  79                "$Q$prefix/c/x$Q exists; cannot create $Q$prefix/c$Q"
  80
  81'
  82
  83test_expect_success 'new ref is a deeper prefix of existing loose' '
  84
  85        prefix=refs/4l &&
  86        test_update_rejected $prefix "a c/x/y e" false "b c d" \
  87                "$Q$prefix/c/x/y$Q exists; cannot create $Q$prefix/c$Q"
  88
  89'
  90
  91test_expect_success 'new ref is a deeper prefix of existing packed' '
  92
  93        prefix=refs/4p &&
  94        test_update_rejected $prefix "a c/x/y e" true "b c d" \
  95                "$Q$prefix/c/x/y$Q exists; cannot create $Q$prefix/c$Q"
  96
  97'
  98
  99test_expect_success 'one new ref is a simple prefix of another' '
 100
 101        prefix=refs/5 &&
 102        test_update_rejected $prefix "a e" false "b c c/x d" \
 103                "cannot process $Q$prefix/c$Q and $Q$prefix/c/x$Q at the same time"
 104
 105'
 106
 107test_done