Merge branch 'sb/pull-rebase-submodule'
[git] / t / t9832-unshelve.sh
1 #!/bin/sh
2
3 last_shelved_change () {
4         p4 changes -s shelved -m1 | cut -d " " -f 2
5 }
6
7 test_description='git p4 unshelve'
8
9 . ./lib-git-p4.sh
10
11 test_expect_success 'start p4d' '
12         start_p4d
13 '
14
15 test_expect_success 'init depot' '
16         (
17                 cd "$cli" &&
18                 echo file1 >file1 &&
19                 p4 add file1 &&
20                 p4 submit -d "change 1" &&
21                 : >file_to_delete &&
22                 p4 add file_to_delete &&
23                 p4 submit -d "file to delete"
24         )
25 '
26
27 test_expect_success 'initial clone' '
28         git p4 clone --dest="$git" //depot/@all
29 '
30
31 test_expect_success 'create shelved changelist' '
32         (
33                 cd "$cli" &&
34                 p4 edit file1 &&
35                 echo "a change" >>file1 &&
36                 echo "new file" >file2 &&
37                 p4 add file2 &&
38                 p4 delete file_to_delete &&
39                 p4 opened &&
40                 p4 shelve -i <<EOF
41 Change: new
42 Description:
43         Test commit
44
45         Further description
46 Files:
47         //depot/file1
48         //depot/file2
49         //depot/file_to_delete
50 EOF
51
52         ) &&
53         (
54                 cd "$git" &&
55                 change=$(last_shelved_change) &&
56                 git p4 unshelve $change &&
57                 git show refs/remotes/p4/unshelved/$change | grep -q "Further description" &&
58                 git cherry-pick refs/remotes/p4/unshelved/$change &&
59                 test_path_is_file file2 &&
60                 test_cmp file1 "$cli"/file1 &&
61                 test_cmp file2 "$cli"/file2 &&
62                 test_path_is_missing file_to_delete
63         )
64 '
65
66 test_expect_success 'update shelved changelist and re-unshelve' '
67         test_when_finished cleanup_git &&
68         (
69                 cd "$cli" &&
70                 change=$(last_shelved_change) &&
71                 echo "file3" >file3 &&
72                 p4 add -c $change file3 &&
73                 p4 shelve -i -r <<EOF &&
74 Change: $change
75 Description:
76         Test commit
77
78         Further description
79 Files:
80         //depot/file1
81         //depot/file2
82         //depot/file3
83         //depot/file_to_delete
84 EOF
85                 p4 describe $change
86         ) &&
87         (
88                 cd "$git" &&
89                 change=$(last_shelved_change) &&
90                 git p4 unshelve $change &&
91                 git diff refs/remotes/p4/unshelved/$change.0 refs/remotes/p4/unshelved/$change | grep -q file3
92         )
93 '
94
95 # This is the tricky case where the shelved changelist base revision doesn't
96 # match git-p4's idea of the base revision
97 #
98 # We will attempt to unshelve a change that is based on a change one commit
99 # ahead of p4/master
100
101 test_expect_success 'create shelved changelist based on p4 change ahead of p4/master' '
102         git p4 clone --dest="$git" //depot/@all &&
103         (
104                 cd "$cli" &&
105                 p4 revert ... &&
106                 p4 edit file1 &&
107                 echo "foo" >>file1 &&
108                 p4 submit -d "change:foo" &&
109                 p4 edit file1 &&
110                 echo "bar" >>file1 &&
111                 p4 shelve -i <<EOF &&
112 Change: new
113 Description:
114         Change to be unshelved
115 Files:
116         //depot/file1
117 EOF
118                 change=$(last_shelved_change) &&
119                 p4 describe -S $change | grep -q "Change to be unshelved"
120         )
121 '
122
123 # Now try to unshelve it. git-p4 should refuse to do so.
124 test_expect_success 'try to unshelve the change' '
125         test_when_finished cleanup_git &&
126         (
127                 change=$(last_shelved_change) &&
128                 cd "$git" &&
129                 test_must_fail git p4 unshelve $change 2>out.txt &&
130                 grep -q "cannot unshelve" out.txt
131         )
132 '
133
134 test_expect_success 'kill p4d' '
135         kill_p4d
136 '
137
138 test_done