1#!/bin/sh
   2test_description='Test git update-ref with D/F conflicts'
   4. ./test-lib.sh
   5test_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}
  25Q="'"
  27test_expect_success 'setup' '
  29        git commit --allow-empty -m Initial &&
  31        C=$(git rev-parse HEAD)
  32'
  34test_expect_success 'existing loose ref is a simple prefix of new' '
  36        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'
  42test_expect_success 'existing packed ref is a simple prefix of new' '
  44        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'
  50test_expect_success 'existing loose ref is a deeper prefix of new' '
  52        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'
  58test_expect_success 'existing packed ref is a deeper prefix of new' '
  60        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'
  66test_expect_success 'new ref is a simple prefix of existing loose' '
  68        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'
  74test_expect_success 'new ref is a simple prefix of existing packed' '
  76        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'
  82test_expect_success 'new ref is a deeper prefix of existing loose' '
  84        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'
  90test_expect_success 'new ref is a deeper prefix of existing packed' '
  92        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'
  98test_expect_success 'one new ref is a simple prefix of another' '
 100        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'
 106test_done