1#!/bin/sh
2#
3# Copyright (c) 2013 Ramkumar Ramachandra
4#
5
6test_description='git rebase --autostash tests'
7. ./test-lib.sh
8
9test_expect_success setup '
10 echo hello-world >file0 &&
11 git add . &&
12 test_tick &&
13 git commit -m "initial commit" &&
14 git checkout -b feature-branch &&
15 echo another-hello >file1 &&
16 echo goodbye >file2 &&
17 git add . &&
18 test_tick &&
19 git commit -m "second commit" &&
20 echo final-goodbye >file3 &&
21 git add . &&
22 test_tick &&
23 git commit -m "third commit" &&
24 git checkout -b unrelated-onto-branch master &&
25 echo unrelated >file4 &&
26 git add . &&
27 test_tick &&
28 git commit -m "unrelated commit" &&
29 git checkout -b related-onto-branch master &&
30 echo conflicting-change >file2 &&
31 git add . &&
32 test_tick &&
33 git commit -m "related commit"
34'
35
36testrebase() {
37 type=$1
38 dotest=$2
39
40 test_expect_success "rebase$type: dirty worktree, non-conflicting rebase" '
41 test_config rebase.autostash true &&
42 git reset --hard &&
43 git checkout -b rebased-feature-branch feature-branch &&
44 test_when_finished git branch -D rebased-feature-branch &&
45 echo dirty >>file3 &&
46 git rebase$type unrelated-onto-branch &&
47 grep unrelated file4 &&
48 grep dirty file3 &&
49 git checkout feature-branch
50 '
51
52 test_expect_success "rebase$type: dirty index, non-conflicting rebase" '
53 test_config rebase.autostash true &&
54 git reset --hard &&
55 git checkout -b rebased-feature-branch feature-branch &&
56 test_when_finished git branch -D rebased-feature-branch &&
57 echo dirty >>file3 &&
58 git add file3 &&
59 git rebase$type unrelated-onto-branch &&
60 grep unrelated file4 &&
61 grep dirty file3 &&
62 git checkout feature-branch
63 '
64
65 test_expect_success "rebase$type: conflicting rebase" '
66 test_config rebase.autostash true &&
67 git reset --hard &&
68 git checkout -b rebased-feature-branch feature-branch &&
69 test_when_finished git branch -D rebased-feature-branch &&
70 echo dirty >>file3 &&
71 test_must_fail git rebase$type related-onto-branch &&
72 test_path_is_file $dotest/autostash &&
73 ! grep dirty file3 &&
74 rm -rf $dotest &&
75 git reset --hard &&
76 git checkout feature-branch
77 '
78
79 test_expect_success "rebase$type: --continue" '
80 test_config rebase.autostash true &&
81 git reset --hard &&
82 git checkout -b rebased-feature-branch feature-branch &&
83 test_when_finished git branch -D rebased-feature-branch &&
84 echo dirty >>file3 &&
85 test_must_fail git rebase$type related-onto-branch &&
86 test_path_is_file $dotest/autostash &&
87 ! grep dirty file3 &&
88 echo "conflicting-plus-goodbye" >file2 &&
89 git add file2 &&
90 git rebase --continue &&
91 test_path_is_missing $dotest/autostash &&
92 grep dirty file3 &&
93 git checkout feature-branch
94 '
95
96 test_expect_success "rebase$type: --skip" '
97 test_config rebase.autostash true &&
98 git reset --hard &&
99 git checkout -b rebased-feature-branch feature-branch &&
100 test_when_finished git branch -D rebased-feature-branch &&
101 echo dirty >>file3 &&
102 test_must_fail git rebase$type related-onto-branch &&
103 test_path_is_file $dotest/autostash &&
104 ! grep dirty file3 &&
105 git rebase --skip &&
106 test_path_is_missing $dotest/autostash &&
107 grep dirty file3 &&
108 git checkout feature-branch
109 '
110
111 test_expect_success "rebase$type: --abort" '
112 test_config rebase.autostash true &&
113 git reset --hard &&
114 git checkout -b rebased-feature-branch feature-branch &&
115 test_when_finished git branch -D rebased-feature-branch &&
116 echo dirty >>file3 &&
117 test_must_fail git rebase$type related-onto-branch &&
118 test_path_is_file $dotest/autostash &&
119 ! grep dirty file3 &&
120 git rebase --abort &&
121 test_path_is_missing $dotest/autostash &&
122 grep dirty file3 &&
123 git checkout feature-branch
124 '
125
126 test_expect_success "rebase$type: non-conflicting rebase, conflicting stash" '
127 test_config rebase.autostash true &&
128 git reset --hard &&
129 git checkout -b rebased-feature-branch feature-branch &&
130 test_when_finished git branch -D rebased-feature-branch &&
131 echo dirty >file4 &&
132 git add file4 &&
133 git rebase$type unrelated-onto-branch &&
134 test_path_is_missing $dotest &&
135 git reset --hard &&
136 grep unrelated file4 &&
137 ! grep dirty file4 &&
138 git checkout feature-branch &&
139 git stash pop &&
140 grep dirty file4
141 '
142}
143
144testrebase "" .git/rebase-apply
145testrebase " --merge" .git/rebase-merge
146testrebase " --interactive" .git/rebase-merge
147
148test_done