Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit f949209

Browse files
j6tgitster
authored andcommitted
t2020-checkout-detach: check for the number of orphaned commits
Change the test that orphans commits to leave 2 commits behind. Add a test that leaves only one of these behind. The next patch will truncate the list of orphaned commits earlier. With this preliminary update, its effect will become more obvious. Signed-off-by: Johannes Sixt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e8dde3e commit f949209

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

t/t2020-checkout-detach.sh

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,13 @@ check_not_detached () {
1111
git symbolic-ref -q HEAD >/dev/null
1212
}
1313

14-
ORPHAN_WARNING='you are leaving .* commit.*behind'
1514
PREV_HEAD_DESC='Previous HEAD position was'
1615
check_orphan_warning() {
17-
test_i18ngrep "$ORPHAN_WARNING" "$1" &&
16+
test_i18ngrep "you are leaving $2 behind" "$1" &&
1817
test_i18ngrep ! "$PREV_HEAD_DESC" "$1"
1918
}
2019
check_no_orphan_warning() {
21-
test_i18ngrep ! "$ORPHAN_WARNING" "$1" &&
20+
test_i18ngrep ! "you are leaving .* commit.*behind" "$1" &&
2221
test_i18ngrep "$PREV_HEAD_DESC" "$1"
2322
}
2423

@@ -110,12 +109,24 @@ test_expect_success 'checkout warns on orphan commits' '
110109
git checkout --detach two &&
111110
echo content >orphan &&
112111
git add orphan &&
113-
git commit -a -m orphan &&
112+
git commit -a -m orphan1 &&
113+
echo new content >orphan &&
114+
git commit -a -m orphan2 &&
115+
orphan2=$(git rev-parse HEAD) &&
114116
git checkout master 2>stderr
115117
'
116118

117119
test_expect_success 'checkout warns on orphan commits: output' '
118-
check_orphan_warning stderr
120+
check_orphan_warning stderr "2 commits"
121+
'
122+
123+
test_expect_success 'checkout warns orphaning 1 of 2 commits' '
124+
git checkout "$orphan2" &&
125+
git checkout HEAD^ 2>stderr
126+
'
127+
128+
test_expect_success 'checkout warns orphaning 1 of 2 commits: output' '
129+
check_orphan_warning stderr "2 commits"
119130
'
120131

121132
test_expect_success 'checkout does not warn leaving ref tip' '

0 commit comments

Comments
 (0)