t / t5536-fetch-conflicts.shon commit http-backend: allow empty CONTENT_LENGTH (574c513)
   1#!/bin/sh
   2
   3test_description='fetch handles conflicting refspecs correctly'
   4
   5. ./test-lib.sh
   6
   7D=$(pwd)
   8
   9setup_repository () {
  10        git init "$1" && (
  11                cd "$1" &&
  12                git config remote.origin.url "$D" &&
  13                shift &&
  14                for refspec in "$@"
  15                do
  16                        git config --add remote.origin.fetch "$refspec"
  17                done
  18        )
  19}
  20
  21test_expect_success 'setup' '
  22        git commit --allow-empty -m "Initial" &&
  23        git branch branch1 &&
  24        git tag tag1 &&
  25        git commit --allow-empty -m "First" &&
  26        git branch branch2 &&
  27        git tag tag2
  28'
  29
  30test_expect_success 'fetch with no conflict' '
  31        setup_repository ok "+refs/heads/*:refs/remotes/origin/*" && (
  32                cd ok &&
  33                git fetch origin
  34        )
  35'
  36
  37test_expect_success 'fetch conflict: config vs. config' '
  38        setup_repository ccc \
  39                "+refs/heads/branch1:refs/remotes/origin/branch1" \
  40                "+refs/heads/branch2:refs/remotes/origin/branch1" && (
  41                cd ccc &&
  42                test_must_fail git fetch origin 2>error &&
  43                test_i18ngrep "fatal: Cannot fetch both refs/heads/branch1 and refs/heads/branch2 to refs/remotes/origin/branch1" error
  44        )
  45'
  46
  47test_expect_success 'fetch duplicate: config vs. config' '
  48        setup_repository dcc \
  49                "+refs/heads/*:refs/remotes/origin/*" \
  50                "+refs/heads/branch1:refs/remotes/origin/branch1" && (
  51                cd dcc &&
  52                git fetch origin
  53        )
  54'
  55
  56test_expect_success 'fetch conflict: arg overrides config' '
  57        setup_repository aoc \
  58                "+refs/heads/*:refs/remotes/origin/*" && (
  59                cd aoc &&
  60                git fetch origin refs/heads/branch2:refs/remotes/origin/branch1
  61        )
  62'
  63
  64test_expect_success 'fetch conflict: arg vs. arg' '
  65        setup_repository caa && (
  66                cd caa &&
  67                test_must_fail git fetch origin \
  68                        refs/heads/*:refs/remotes/origin/* \
  69                        refs/heads/branch2:refs/remotes/origin/branch1 2>error &&
  70                test_i18ngrep "fatal: Cannot fetch both refs/heads/branch1 and refs/heads/branch2 to refs/remotes/origin/branch1" error
  71        )
  72'
  73
  74test_expect_success 'fetch conflict: criss-cross args' '
  75        setup_repository xaa \
  76                "+refs/heads/*:refs/remotes/origin/*" && (
  77                cd xaa &&
  78                git fetch origin \
  79                        refs/heads/branch1:refs/remotes/origin/branch2 \
  80                        refs/heads/branch2:refs/remotes/origin/branch1 2>error &&
  81                test_i18ngrep "warning: refs/remotes/origin/branch1 usually tracks refs/heads/branch1, not refs/heads/branch2" error &&
  82                test_i18ngrep "warning: refs/remotes/origin/branch2 usually tracks refs/heads/branch2, not refs/heads/branch1" error
  83        )
  84'
  85
  86test_done