t / t7607-merge-overwrite.shon commit Merge branch 'maint-1.6.0' into maint (9b27ea9)
   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        ! 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        ! 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        ! 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        ! 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        ! 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        ! git merge c1a &&
  83        git checkout c1.c &&
  84        test_cmp important c1.c
  85'
  86
  87test_done