1#!/bin/sh
2
3test_description='git rebase tests for -Xsubtree
4
5This test runs git rebase and tests the subtree strategy.
6'
7. ./test-lib.sh
8. "$TEST_DIRECTORY"/lib-rebase.sh
9
10commit_message() {
11 git log --pretty=format:%s -1 "$1"
12}
13
14test_expect_success 'setup' '
15 test_commit README &&
16 mkdir files &&
17 (
18 cd files &&
19 git init &&
20 test_commit master1 &&
21 test_commit master2 &&
22 test_commit master3
23 ) &&
24 git fetch files master &&
25 git branch files-master FETCH_HEAD &&
26 git read-tree --prefix=files_subtree files-master &&
27 git checkout -- files_subtree &&
28 tree=$(git write-tree) &&
29 head=$(git rev-parse HEAD) &&
30 rev=$(git rev-parse --verify files-master^0) &&
31 commit=$(git commit-tree -p $head -p $rev -m "Add subproject master" $tree) &&
32 git update-ref HEAD $commit &&
33 (
34 cd files_subtree &&
35 test_commit master4
36 ) &&
37 test_commit files_subtree/master5
38'
39
40# FAILURE: Does not preserve master4.
41test_expect_failure REBASE_P \
42 'Rebase -Xsubtree --preserve-merges --onto commit 4' '
43 reset_rebase &&
44 git checkout -b rebase-preserve-merges-4 master &&
45 git filter-branch --prune-empty -f --subdirectory-filter files_subtree &&
46 git commit -m "Empty commit" --allow-empty &&
47 git rebase -Xsubtree=files_subtree --preserve-merges --onto files-master master &&
48 verbose test "$(commit_message HEAD~)" = "files_subtree/master4"
49'
50
51# FAILURE: Does not preserve master5.
52test_expect_failure REBASE_P \
53 'Rebase -Xsubtree --preserve-merges --onto commit 5' '
54 reset_rebase &&
55 git checkout -b rebase-preserve-merges-5 master &&
56 git filter-branch --prune-empty -f --subdirectory-filter files_subtree &&
57 git commit -m "Empty commit" --allow-empty &&
58 git rebase -Xsubtree=files_subtree --preserve-merges --onto files-master master &&
59 verbose test "$(commit_message HEAD)" = "files_subtree/master5"
60'
61
62# FAILURE: Does not preserve master4.
63test_expect_failure REBASE_P \
64 'Rebase -Xsubtree --keep-empty --preserve-merges --onto commit 4' '
65 reset_rebase &&
66 git checkout -b rebase-keep-empty-4 master &&
67 git filter-branch --prune-empty -f --subdirectory-filter files_subtree &&
68 git commit -m "Empty commit" --allow-empty &&
69 git rebase -Xsubtree=files_subtree --keep-empty --preserve-merges --onto files-master master &&
70 verbose test "$(commit_message HEAD~2)" = "files_subtree/master4"
71'
72
73# FAILURE: Does not preserve master5.
74test_expect_failure REBASE_P \
75 'Rebase -Xsubtree --keep-empty --preserve-merges --onto commit 5' '
76 reset_rebase &&
77 git checkout -b rebase-keep-empty-5 master &&
78 git filter-branch --prune-empty -f --subdirectory-filter files_subtree &&
79 git commit -m "Empty commit" --allow-empty &&
80 git rebase -Xsubtree=files_subtree --keep-empty --preserve-merges --onto files-master master &&
81 verbose test "$(commit_message HEAD~)" = "files_subtree/master5"
82'
83
84# FAILURE: Does not preserve Empty.
85test_expect_failure REBASE_P \
86 'Rebase -Xsubtree --keep-empty --preserve-merges --onto empty commit' '
87 reset_rebase &&
88 git checkout -b rebase-keep-empty-empty master &&
89 git filter-branch --prune-empty -f --subdirectory-filter files_subtree &&
90 git commit -m "Empty commit" --allow-empty &&
91 git rebase -Xsubtree=files_subtree --keep-empty --preserve-merges --onto files-master master &&
92 verbose test "$(commit_message HEAD)" = "Empty commit"
93'
94
95# FAILURE: fatal: Could not parse object
96test_expect_failure 'Rebase -Xsubtree --onto commit 4' '
97 reset_rebase &&
98 git checkout -b rebase-onto-4 master &&
99 git filter-branch --prune-empty -f --subdirectory-filter files_subtree &&
100 git commit -m "Empty commit" --allow-empty &&
101 git rebase -Xsubtree=files_subtree --onto files-master master &&
102 verbose test "$(commit_message HEAD~2)" = "files_subtree/master4"
103'
104
105# FAILURE: fatal: Could not parse object
106test_expect_failure 'Rebase -Xsubtree --onto commit 5' '
107 reset_rebase &&
108 git checkout -b rebase-onto-5 master &&
109 git filter-branch --prune-empty -f --subdirectory-filter files_subtree &&
110 git commit -m "Empty commit" --allow-empty &&
111 git rebase -Xsubtree=files_subtree --onto files-master master &&
112 verbose test "$(commit_message HEAD~)" = "files_subtree/master5"
113'
114# FAILURE: fatal: Could not parse object
115test_expect_failure 'Rebase -Xsubtree --onto empty commit' '
116 reset_rebase &&
117 git checkout -b rebase-onto-empty master &&
118 git filter-branch --prune-empty -f --subdirectory-filter files_subtree &&
119 git commit -m "Empty commit" --allow-empty &&
120 git rebase -Xsubtree=files_subtree --onto files-master master &&
121 verbose test "$(commit_message HEAD)" = "Empty commit"
122'
123
124test_done