blob: 5bfb027099a6d22849739075de82f3c0af7ca513 [file] [log] [blame]
Diane Gasseline935e622010-08-11 10:38:08 +02001#!/bin/sh
2
3test_description='unpack-trees error messages'
4
Johannes Schindelin5902f5f2020-11-18 23:44:38 +00005GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
Johannes Schindelin334afbc2020-11-18 23:44:19 +00006export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
Diane Gasseline935e622010-08-11 10:38:08 +02008. ./test-lib.sh
9
10
11test_expect_success 'setup' '
12 echo one >one &&
13 git add one &&
14 git commit -a -m First &&
15
16 git checkout -b branch &&
17 echo two >two &&
18 echo three >three &&
19 echo four >four &&
20 echo five >five &&
21 git add two three four five &&
22 git commit -m Second &&
23
Johannes Schindelin5902f5f2020-11-18 23:44:38 +000024 git checkout main &&
Diane Gasseline935e622010-08-11 10:38:08 +020025 echo other >two &&
26 echo other >three &&
27 echo other >four &&
28 echo other >five
29'
30
31cat >expect <<\EOF
32error: The following untracked working tree files would be overwritten by merge:
Diane Gasseline935e622010-08-11 10:38:08 +020033 five
Clemens Buchacher79808722010-11-15 20:52:19 +010034 four
35 three
36 two
Alex Henriec2691e22016-06-25 00:34:04 -060037Please move or remove them before you merge.
Michael J Gruber6f909692011-09-21 09:48:36 +020038Aborting
Diane Gasseline935e622010-08-11 10:38:08 +020039EOF
40
Matthieu Moyc5978a52010-09-03 17:25:33 +020041test_expect_success 'untracked files overwritten by merge (fast and non-fast forward)' '
Diane Gasseline935e622010-08-11 10:38:08 +020042 test_must_fail git merge branch 2>out &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +010043 test_cmp out expect &&
Matthieu Moyc5978a52010-09-03 17:25:33 +020044 git commit --allow-empty -m empty &&
45 (
46 GIT_MERGE_VERBOSITY=0 &&
47 export GIT_MERGE_VERBOSITY &&
48 test_must_fail git merge branch 2>out2
49 ) &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +010050 test_cmp out2 expect &&
Matthieu Moyc5978a52010-09-03 17:25:33 +020051 git reset --hard HEAD^
Diane Gasseline935e622010-08-11 10:38:08 +020052'
53
54cat >expect <<\EOF
55error: Your local changes to the following files would be overwritten by merge:
Diane Gasseline935e622010-08-11 10:38:08 +020056 four
Clemens Buchacher79808722010-11-15 20:52:19 +010057 three
58 two
Alex Henriec2691e22016-06-25 00:34:04 -060059Please commit your changes or stash them before you merge.
Diane Gasseline935e622010-08-11 10:38:08 +020060error: The following untracked working tree files would be overwritten by merge:
61 five
Alex Henriec2691e22016-06-25 00:34:04 -060062Please move or remove them before you merge.
Michael J Gruber6f909692011-09-21 09:48:36 +020063Aborting
Diane Gasseline935e622010-08-11 10:38:08 +020064EOF
65
66test_expect_success 'untracked files or local changes ovewritten by merge' '
67 git add two &&
68 git add three &&
69 git add four &&
70 test_must_fail git merge branch 2>out &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +010071 test_cmp out expect
Diane Gasseline935e622010-08-11 10:38:08 +020072'
73
74cat >expect <<\EOF
75error: Your local changes to the following files would be overwritten by checkout:
Diane Gasseline935e622010-08-11 10:38:08 +020076 rep/one
Clemens Buchacher79808722010-11-15 20:52:19 +010077 rep/two
Alex Henriec2691e22016-06-25 00:34:04 -060078Please commit your changes or stash them before you switch branches.
Michael J Gruber6f909692011-09-21 09:48:36 +020079Aborting
Diane Gasseline935e622010-08-11 10:38:08 +020080EOF
81
82test_expect_success 'cannot switch branches because of local changes' '
83 git add five &&
84 mkdir rep &&
85 echo one >rep/one &&
86 echo two >rep/two &&
87 git add rep/one rep/two &&
88 git commit -m Fourth &&
Johannes Schindelin5902f5f2020-11-18 23:44:38 +000089 git checkout main &&
Diane Gasseline935e622010-08-11 10:38:08 +020090 echo uno >rep/one &&
91 echo dos >rep/two &&
92 test_must_fail git checkout branch 2>out &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +010093 test_cmp out expect
Diane Gasseline935e622010-08-11 10:38:08 +020094'
95
96cat >expect <<\EOF
97error: Your local changes to the following files would be overwritten by checkout:
Diane Gasseline935e622010-08-11 10:38:08 +020098 rep/one
Clemens Buchacher79808722010-11-15 20:52:19 +010099 rep/two
Alex Henriec2691e22016-06-25 00:34:04 -0600100Please commit your changes or stash them before you switch branches.
Michael J Gruber6f909692011-09-21 09:48:36 +0200101Aborting
Diane Gasseline935e622010-08-11 10:38:08 +0200102EOF
103
104test_expect_success 'not uptodate file porcelain checkout error' '
105 git add rep/one rep/two &&
106 test_must_fail git checkout branch 2>out &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +0100107 test_cmp out expect
Diane Gasseline935e622010-08-11 10:38:08 +0200108'
109
110cat >expect <<\EOF
Stefan Beller584f99c2016-12-02 11:17:41 -0800111error: Updating the following directories would lose untracked files in them:
Diane Gasseline935e622010-08-11 10:38:08 +0200112 rep
Clemens Buchacher79808722010-11-15 20:52:19 +0100113 rep2
Diane Gasseline935e622010-08-11 10:38:08 +0200114
Michael J Gruber6f909692011-09-21 09:48:36 +0200115Aborting
Diane Gasseline935e622010-08-11 10:38:08 +0200116EOF
117
118test_expect_success 'not_uptodate_dir porcelain checkout error' '
119 git init uptodate &&
120 cd uptodate &&
121 mkdir rep &&
122 mkdir rep2 &&
123 touch rep/foo &&
124 touch rep2/foo &&
125 git add rep/foo rep2/foo &&
126 git commit -m init &&
127 git checkout -b branch &&
128 git rm rep -r &&
129 git rm rep2 -r &&
130 >rep &&
131 >rep2 &&
Andrei Rybak64d10222020-03-22 22:14:22 +0100132 git add rep rep2 &&
Diane Gasseline935e622010-08-11 10:38:08 +0200133 git commit -m "added test as a file" &&
Johannes Schindelin5902f5f2020-11-18 23:44:38 +0000134 git checkout main &&
Diane Gasseline935e622010-08-11 10:38:08 +0200135 >rep/untracked-file &&
136 >rep2/untracked-file &&
137 test_must_fail git checkout branch 2>out &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +0100138 test_cmp out ../expect
Diane Gasseline935e622010-08-11 10:38:08 +0200139'
140
141test_done