]>
Commit | Line | Data |
---|---|---|
d00d2ed1 PW |
1 | #!/bin/sh |
2 | ||
6ab1d76c | 3 | test_description='git p4 tests' |
d00d2ed1 | 4 | |
fc002330 | 5 | . ./lib-git-p4.sh |
d00d2ed1 | 6 | |
fc002330 PW |
7 | test_expect_success 'start p4d' ' |
8 | start_p4d | |
d00d2ed1 PW |
9 | ' |
10 | ||
11 | test_expect_success 'add p4 files' ' | |
fc002330 PW |
12 | ( |
13 | cd "$cli" && | |
14 | echo file1 >file1 && | |
15 | p4 add file1 && | |
16 | p4 submit -d "file1" && | |
17 | echo file2 >file2 && | |
18 | p4 add file2 && | |
19 | p4 submit -d "file2" | |
20 | ) | |
d00d2ed1 PW |
21 | ' |
22 | ||
6ab1d76c PW |
23 | test_expect_success 'basic git p4 clone' ' |
24 | git p4 clone --dest="$git" //depot && | |
f40ae5ce | 25 | test_when_finished cleanup_git && |
fc002330 PW |
26 | ( |
27 | cd "$git" && | |
28 | git log --oneline >lines && | |
29 | test_line_count = 1 lines | |
30 | ) | |
f0c9fe05 PW |
31 | ' |
32 | ||
6ab1d76c PW |
33 | test_expect_success 'git p4 clone @all' ' |
34 | git p4 clone --dest="$git" //depot@all && | |
f40ae5ce | 35 | test_when_finished cleanup_git && |
fc002330 PW |
36 | ( |
37 | cd "$git" && | |
38 | git log --oneline >lines && | |
39 | test_line_count = 2 lines | |
40 | ) | |
d00d2ed1 PW |
41 | ' |
42 | ||
6ab1d76c | 43 | test_expect_success 'git p4 sync uninitialized repo' ' |
27c6000b | 44 | test_create_repo "$git" && |
f40ae5ce | 45 | test_when_finished cleanup_git && |
fc002330 PW |
46 | ( |
47 | cd "$git" && | |
4256397a PW |
48 | test_must_fail git p4 sync 2>errs && |
49 | test_i18ngrep "Perhaps you never did" errs | |
fc002330 | 50 | ) |
27c6000b PW |
51 | ' |
52 | ||
53 | # | |
54 | # Create a git repo by hand. Add a commit so that HEAD is valid. | |
55 | # Test imports a new p4 repository into a new git branch. | |
56 | # | |
6ab1d76c | 57 | test_expect_success 'git p4 sync new branch' ' |
27c6000b | 58 | test_create_repo "$git" && |
f40ae5ce | 59 | test_when_finished cleanup_git && |
fc002330 PW |
60 | ( |
61 | cd "$git" && | |
62 | test_commit head && | |
6ab1d76c | 63 | git p4 sync --branch=refs/remotes/p4/depot //depot@all && |
fc002330 PW |
64 | git log --oneline p4/depot >lines && |
65 | test_line_count = 2 lines | |
66 | ) | |
27c6000b PW |
67 | ' |
68 | ||
da191d15 PW |
69 | test_expect_success 'clone two dirs' ' |
70 | ( | |
71 | cd "$cli" && | |
72 | mkdir sub1 sub2 && | |
73 | echo sub1/f1 >sub1/f1 && | |
74 | echo sub2/f2 >sub2/f2 && | |
75 | p4 add sub1/f1 && | |
76 | p4 submit -d "sub1/f1" && | |
77 | p4 add sub2/f2 && | |
78 | p4 submit -d "sub2/f2" | |
79 | ) && | |
6ab1d76c | 80 | git p4 clone --dest="$git" //depot/sub1 //depot/sub2 && |
da191d15 PW |
81 | test_when_finished cleanup_git && |
82 | ( | |
83 | cd "$git" && | |
84 | git ls-files >lines && | |
85 | test_line_count = 2 lines && | |
86 | git log --oneline p4/master >lines && | |
87 | test_line_count = 1 lines | |
88 | ) | |
89 | ' | |
90 | ||
91 | test_expect_success 'clone two dirs, @all' ' | |
92 | ( | |
93 | cd "$cli" && | |
94 | echo sub1/f3 >sub1/f3 && | |
95 | p4 add sub1/f3 && | |
96 | p4 submit -d "sub1/f3" | |
97 | ) && | |
6ab1d76c | 98 | git p4 clone --dest="$git" //depot/sub1@all //depot/sub2@all && |
da191d15 PW |
99 | test_when_finished cleanup_git && |
100 | ( | |
101 | cd "$git" && | |
102 | git ls-files >lines && | |
103 | test_line_count = 3 lines && | |
104 | git log --oneline p4/master >lines && | |
105 | test_line_count = 3 lines | |
106 | ) | |
107 | ' | |
108 | ||
109 | test_expect_success 'clone two dirs, @all, conflicting files' ' | |
110 | ( | |
111 | cd "$cli" && | |
112 | echo sub2/f3 >sub2/f3 && | |
113 | p4 add sub2/f3 && | |
114 | p4 submit -d "sub2/f3" | |
115 | ) && | |
6ab1d76c | 116 | git p4 clone --dest="$git" //depot/sub1@all //depot/sub2@all && |
da191d15 PW |
117 | test_when_finished cleanup_git && |
118 | ( | |
119 | cd "$git" && | |
120 | git ls-files >lines && | |
121 | test_line_count = 3 lines && | |
122 | git log --oneline p4/master >lines && | |
123 | test_line_count = 4 lines && | |
124 | echo sub2/f3 >expected && | |
125 | test_cmp expected f3 | |
126 | ) | |
127 | ' | |
128 | ||
68b28593 | 129 | test_expect_success 'exit when p4 fails to produce marshaled output' ' |
08c5eb7a PW |
130 | mkdir badp4dir && |
131 | test_when_finished "rm badp4dir/p4 && rmdir badp4dir" && | |
132 | cat >badp4dir/p4 <<-EOF && | |
68b28593 PW |
133 | #!$SHELL_PATH |
134 | exit 1 | |
135 | EOF | |
08c5eb7a PW |
136 | chmod 755 badp4dir/p4 && |
137 | PATH="$TRASH_DIRECTORY/badp4dir:$PATH" git p4 clone --dest="$git" //depot >errs 2>&1 ; retval=$? && | |
68b28593 PW |
138 | test $retval -eq 1 && |
139 | test_must_fail grep -q Traceback errs | |
140 | ' | |
141 | ||
38200076 | 142 | test_expect_success 'clone bare' ' |
23a2666c | 143 | rm -rf "$git" && |
6ab1d76c | 144 | git p4 clone --dest="$git" --bare //depot && |
f40ae5ce | 145 | test_when_finished cleanup_git && |
fc002330 PW |
146 | ( |
147 | cd "$git" && | |
148 | test ! -d .git && | |
149 | bare=`git config --get core.bare` && | |
150 | test "$bare" = true | |
151 | ) | |
38200076 PW |
152 | ' |
153 | ||
4e2e6ce4 PW |
154 | marshal_dump() { |
155 | what=$1 | |
fc002330 | 156 | "$PYTHON_PATH" -c 'import marshal, sys; d = marshal.load(sys.stdin); print d["'$what'"]' |
4e2e6ce4 PW |
157 | } |
158 | ||
159 | # Sleep a bit so that the top-most p4 change did not happen "now". Then | |
160 | # import the repo and make sure that the initial import has the same time | |
161 | # as the top-most change. | |
162 | test_expect_success 'initial import time from top change time' ' | |
163 | p4change=$(p4 -G changes -m 1 //depot/... | marshal_dump change) && | |
164 | p4time=$(p4 -G changes -m 1 //depot/... | marshal_dump time) && | |
165 | sleep 3 && | |
6ab1d76c | 166 | git p4 clone --dest="$git" //depot && |
4e2e6ce4 | 167 | test_when_finished cleanup_git && |
fc002330 PW |
168 | ( |
169 | cd "$git" && | |
170 | gittime=$(git show -s --raw --pretty=format:%at HEAD) && | |
171 | echo $p4time $gittime && | |
172 | test $p4time = $gittime | |
173 | ) | |
4e2e6ce4 | 174 | ' |
848de9c3 | 175 | |
fc002330 PW |
176 | test_expect_success 'kill p4d' ' |
177 | kill_p4d | |
d00d2ed1 PW |
178 | ' |
179 | ||
180 | test_done |