t / t7607-merge-overwrite.shon commit Merge branch 'ja/maint-pull-rebase-doc' into maint (b69fb78)
   1#!/bin/sh
   2
   3test_description='git-merge
   4
   5Do not overwrite changes.'
   6
   7. ./test-lib.sh
   8
   9test_expect_success 'setup' '
  10        echo c0 > c0.c &&
  11        git add c0.c &&
  12        git commit -m c0 &&
  13        git tag c0 &&
  14        echo c1 > c1.c &&
  15        git add c1.c &&
  16        git commit -m c1 &&
  17        git tag c1 &&
  18        git reset --hard c0 &&
  19        echo c2 > c2.c &&
  20        git add c2.c &&
  21        git commit -m c2 &&
  22        git tag c2 &&
  23        git reset --hard c1 &&
  24        echo "c1 a" > c1.c &&
  25        git add c1.c &&
  26        git commit -m "c1 a" &&
  27        git tag c1a &&
  28        echo "VERY IMPORTANT CHANGES" > important
  29'
  30
  31test_expect_success 'will not overwrite untracked file' '
  32        git reset --hard c1 &&
  33        cat important > c2.c &&
  34        test_must_fail git merge c2 &&
  35        test_cmp important c2.c
  36'
  37
  38test_expect_success 'will not overwrite new file' '
  39        git reset --hard c1 &&
  40        cat important > c2.c &&
  41        git add c2.c &&
  42        test_must_fail git merge c2 &&
  43        test_cmp important c2.c
  44'
  45
  46test_expect_success 'will not overwrite staged changes' '
  47        git reset --hard c1 &&
  48        cat important > c2.c &&
  49        git add c2.c &&
  50        rm c2.c &&
  51        test_must_fail git merge c2 &&
  52        git checkout c2.c &&
  53        test_cmp important c2.c
  54'
  55
  56test_expect_success 'will not overwrite removed file' '
  57        git reset --hard c1 &&
  58        git rm c1.c &&
  59        git commit -m "rm c1.c" &&
  60        cat important > c1.c &&
  61        test_must_fail git merge c1a &&
  62        test_cmp important c1.c
  63'
  64
  65test_expect_success 'will not overwrite re-added file' '
  66        git reset --hard c1 &&
  67        git rm c1.c &&
  68        git commit -m "rm c1.c" &&
  69        cat important > c1.c &&
  70        git add c1.c &&
  71        test_must_fail git merge c1a &&
  72        test_cmp important c1.c
  73'
  74
  75test_expect_success 'will not overwrite removed file with staged changes' '
  76        git reset --hard c1 &&
  77        git rm c1.c &&
  78        git commit -m "rm c1.c" &&
  79        cat important > c1.c &&
  80        git add c1.c &&
  81        rm c1.c &&
  82        test_must_fail git merge c1a &&
  83        git checkout c1.c &&
  84        test_cmp important c1.c
  85'
  86
  87cat >expect <<\EOF
  88error: Untracked working tree file 'c0.c' would be overwritten by merge.
  89fatal: read-tree failed
  90EOF
  91
  92test_expect_success 'will not overwrite untracked file on unborn branch' '
  93        git reset --hard c0 &&
  94        git rm -fr . &&
  95        git checkout --orphan new &&
  96        cp important c0.c &&
  97        test_must_fail git merge c0 2>out &&
  98        test_cmp out expect &&
  99        test_path_is_missing .git/MERGE_HEAD &&
 100        test_cmp important c0.c
 101'
 102
 103test_done