Skip to content

Commit a3e8267

Browse files
chriscoolgitster
authored andcommitted
replace_object: add a test case
In this patch the setup code is very big, but this will be used in test cases that will be added later. Signed-off-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 0e87c36 commit a3e8267

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

t/t6050-replace.sh

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#!/bin/sh
2+
#
3+
# Copyright (c) 2008 Christian Couder
4+
#
5+
test_description='Tests replace refs functionality'
6+
7+
exec </dev/null
8+
9+
. ./test-lib.sh
10+
11+
add_and_commit_file()
12+
{
13+
_file="$1"
14+
_msg="$2"
15+
16+
git add $_file || return $?
17+
test_tick || return $?
18+
git commit --quiet -m "$_file: $_msg"
19+
}
20+
21+
HASH1=
22+
HASH2=
23+
HASH3=
24+
HASH4=
25+
HASH5=
26+
HASH6=
27+
HASH7=
28+
29+
test_expect_success 'set up buggy branch' '
30+
echo "line 1" >> hello &&
31+
echo "line 2" >> hello &&
32+
echo "line 3" >> hello &&
33+
echo "line 4" >> hello &&
34+
add_and_commit_file hello "4 lines" &&
35+
HASH1=$(git rev-parse --verify HEAD) &&
36+
echo "line BUG" >> hello &&
37+
echo "line 6" >> hello &&
38+
echo "line 7" >> hello &&
39+
echo "line 8" >> hello &&
40+
add_and_commit_file hello "4 more lines with a BUG" &&
41+
HASH2=$(git rev-parse --verify HEAD) &&
42+
echo "line 9" >> hello &&
43+
echo "line 10" >> hello &&
44+
add_and_commit_file hello "2 more lines" &&
45+
HASH3=$(git rev-parse --verify HEAD) &&
46+
echo "line 11" >> hello &&
47+
add_and_commit_file hello "1 more line" &&
48+
HASH4=$(git rev-parse --verify HEAD) &&
49+
sed -e "s/BUG/5/" hello > hello.new &&
50+
mv hello.new hello &&
51+
add_and_commit_file hello "BUG fixed" &&
52+
HASH5=$(git rev-parse --verify HEAD) &&
53+
echo "line 12" >> hello &&
54+
echo "line 13" >> hello &&
55+
add_and_commit_file hello "2 more lines" &&
56+
HASH6=$(git rev-parse --verify HEAD)
57+
echo "line 14" >> hello &&
58+
echo "line 15" >> hello &&
59+
echo "line 16" >> hello &&
60+
add_and_commit_file hello "again 3 more lines" &&
61+
HASH7=$(git rev-parse --verify HEAD)
62+
'
63+
64+
test_expect_success 'replace the author' '
65+
git cat-file commit $HASH2 | grep "author A U Thor" &&
66+
R=$(git cat-file commit $HASH2 | sed -e "s/A U/O/" | git hash-object -t commit --stdin -w) &&
67+
git cat-file commit $R | grep "author O Thor" &&
68+
git update-ref refs/replace/$HASH2 $R &&
69+
git show HEAD~5 | grep "O Thor" &&
70+
git show $HASH2 | grep "O Thor"
71+
'
72+
73+
#
74+
#
75+
test_done

0 commit comments

Comments
 (0)