-
Notifications
You must be signed in to change notification settings - Fork 0
/
test
executable file
·134 lines (120 loc) · 3.96 KB
/
test
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/usr/bin/env sh
set -e
die() { echo "Error. $@" 1>&2; exit 1; }
assertOutput () {
command="$1"
expected="$2"
output=`bash -c "$command"` &&
test "$output" = "$expected" ||
echo "FAIL: '$1'. Expected: '$2'. Got: '`$1`'"
}
shouldSucceed () {
command="$1"
bash -c "$command" > /dev/null || die "FAIL: '$command' did not succeed"
}
shouldDie () {
command="$1"
bash -c "$command" > /dev/null && die "FAIL: '$command' did not die" || true
}
shouldDieWith () {
command="$1"
expected="$2"
output=`bash -c "$command" 2>&1 > /dev/null` &&
die "FAIL: '$command' dit not die" 1>&2 ||
test "$output" = "$expected" || die "`cat <<- EOF
FAIL: '$command'
Expected: '$expected'
Got: '$output'
EOF`"
}
# Create testrepo
rm -rf testrepo
mkdir testrepo
cd testrepo
git init -q
cp ../cleanrebase ../cleanup ../cleanupcommit ../cleanupindex .
git add cleanrebase cleanup cleanupcommit cleanupindex
echo 'two spaces--> ' > spaces\ in\ filename
echo 'two spaces--> ' > 'newlines
in
filename'
git add spaces* newlines*
git commit -q -m 'initial commit'
git submodule -q add ../testrepo testsubmodule # Can cause problems with ls-files
git commit -q -m 'second commit'
# Run ui tests
shouldSucceed true
shouldDieWith false ""
git checkout -q -b temp &&
shouldDieWith "./cleanrebase master" \
"Error running cleanrebase. Please run 'git checkout master' first" &&
git checkout -q master && git branch -q -D temp
shouldDie "./cleanrebase" # Help text
shouldSucceed "./cleanrebase --help" # Help text
shouldDieWith "./cleanrebase one two" \
"Error running cleanrebase. Usage: ./cleanrebase [--help] <branch>"
shouldDieWith "./cleanrebase foo" \
"Error running cleanrebase. Branch 'foo' does not exist"
shouldDieWith "MINGIT=1.19.0 ./cleanrebase wip/test" \
"Error running cleanrebase. Please upgrade git to a version >= 1.19.0"
mkdir tmp && cd tmp && shouldDieWith "../cleanrebase wip/test" \
"Error running cleanrebase. File not found: 'cleanupcommit'. Are you in the repo root directory?" &&
cd ../ && rm -rf tmp
# Add some test files and commits
echo 'ptext (sLit "foo")' | tee file.hs file.lhs > /dev/null
git add file.*
git commit -q -m 'file.hs file.lhs'
git tag root
sed -i 's/foo/bar/' file.hs
git commit -q -a -m "s/foo/bar/ file.hs" # Introduce hs-conflict.
git tag hs-bar
# Add a test branch and commits
git checkout -q -b wip/test root
sed -i 's/foo/baz/' file.*
sed -i 's/$/ /' file.hs # Trailing whitespace
git commit -q -a -m "s/foo/baz/"
git merge -q hs-bar -s ours -m 'conflict file.hs' # Branch wip/test wins.
# Cleanup files on master
git checkout -q master
./cleanupindex
git commit -a -m 'run cleanup script'
# Some more commits on master
sed -i 's/foo/bar/' file.lhs
sed -i 's/$/ /' file.lhs # Make sure second cleanup has something to do.
git commit -q -a -m "s/foo/bar/ file.lhs" # Introduce lhs-conflict.
./cleanupindex
git commit -a -m 'run cleanup script' # Test that cleanup commit can be last.
# Rebase test branch onto master
# 1
bash -c "`./cleanrebase wip/test`"
# 2
git checkout -q master
bash -c "`./cleanrebase wip/test`" || true
assertOutput 'cat file.lhs | head -1' '<<<<<<< HEAD'
assertOutput 'cat file.lhs | tail -1' '>>>>>>> s/foo/baz/'
sed -i -n '/bar/p' file.lhs # solve conflict, master wins
git add file.lhs
git rebase --continue
# 3
git checkout -q master
bash -c "`./cleanrebase wip/test`"
# 4
git checkout -q master
shouldDieWith './cleanrebase wip/test' 'cleanrebase is DONE'
# Check final state
# The idea of this test is that file.hs now contains 'baz', and file.lhs
# contains 'bar', because wip/test wins the first merge and master the second.
git checkout -q wip/test
assertOutput 'cat file.hs' 'text "baz"'
assertOutput 'cat file.lhs' 'text "bar"'
assertOutput 'cat spaces*' 'two spaces-->' # Stripped.
assertOutput 'cat newlines*' 'two spaces-->' # Stripped.
assertOutput 'git log --pretty=format:%s' 's/foo/baz/
run cleanup script
s/foo/bar/ file.lhs
run cleanup script
s/foo/bar/ file.hs
file.hs file.lhs
second commit
initial commit'
echo ok