Commit | Line | Data |
---|---|---|
fe847176 YD |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2006 Yann Dirson | |
4 | # | |
5 | ||
6 | test_description='Branch operations. | |
7 | ||
8 | Exercises the "stg branch" commands. | |
9 | ' | |
10 | ||
11 | . ./test-lib.sh | |
12 | ||
ff432158 CM |
13 | test_expect_success \ |
14 | 'Create a branch when the current one is not an StGIT stack' ' | |
15 | git branch origin && | |
16 | stg branch --create new origin && | |
f7a73141 | 17 | test $(stg branch) = "new" |
ff432158 | 18 | ' |
fe847176 | 19 | |
e152aab3 | 20 | test_expect_success \ |
e152aab3 | 21 | 'Create a spurious patches/ entry' ' |
ff432158 CM |
22 | stg branch master && |
23 | stg init && | |
c9804555 | 24 | mkdir -p .git/patches && touch .git/patches/foo1 |
fe847176 YD |
25 | ' |
26 | ||
5f594e90 | 27 | test_expect_success \ |
e152aab3 | 28 | 'Try to create an stgit branch with a spurious patches/ entry' ' |
f03004e2 | 29 | command_error stg branch -c foo1 |
fe847176 YD |
30 | ' |
31 | ||
32 | test_expect_success \ | |
e152aab3 | 33 | 'Check that no part of the branch was created' ' |
c9804555 KH |
34 | test "$(find .git -name foo1 | tee /dev/stderr)" = ".git/patches/foo1" && |
35 | test "$(git show-ref | grep foo1 | wc -l)" = 0 && | |
36 | test "$(git symbolic-ref HEAD)" = "refs/heads/master" | |
e152aab3 KH |
37 | ' |
38 | ||
39 | test_expect_success \ | |
40 | 'Create a git branch' ' | |
c9804555 | 41 | git update-ref refs/heads/foo2 refs/heads/master |
fe847176 YD |
42 | ' |
43 | ||
5f594e90 | 44 | test_expect_success \ |
e152aab3 | 45 | 'Try to create an stgit branch with an existing git branch by that name' ' |
f03004e2 | 46 | command_error stg branch -c foo2 |
fe847176 YD |
47 | ' |
48 | ||
49 | test_expect_success \ | |
e152aab3 | 50 | 'Check that no part of the branch was created' ' |
c9804555 KH |
51 | test "$(find .git -name foo2 | tee /dev/stderr \ |
52 | | grep -v ^\\.git/refs/heads/foo2$ \ | |
53 | | grep -v ^\\.git/logs/refs/heads/foo2$ | wc -l)" = 0 && | |
54 | test "$(git show-ref | grep foo2 | wc -l)" = 1 && | |
55 | test "$(git symbolic-ref HEAD)" = "refs/heads/master" | |
fe847176 YD |
56 | ' |
57 | ||
e152aab3 KH |
58 | test_expect_success \ |
59 | 'Create an invalid refs/heads/ entry' ' | |
c9804555 | 60 | touch .git/refs/heads/foo3 && |
f03004e2 | 61 | command_error stg branch -c foo3 |
91413512 CM |
62 | ' |
63 | ||
c9804555 KH |
64 | test_expect_failure \ |
65 | 'Check that no part of the branch was created' ' | |
66 | test "$(find .git -name foo3 | tee /dev/stderr \ | |
67 | | grep -v ^\\.git/refs/heads/foo3$ | wc -l)" = 0 && | |
68 | test "$(git show-ref | grep foo3 | wc -l)" = 0 && | |
69 | test "$(git symbolic-ref HEAD)" = "refs/heads/master" | |
70 | ' | |
71 | ||
72 | # Workaround for the test failure to make the rest of the subtests | |
73 | # succeed. (HEAD was erroneously overwritten with the bad foo3 ref, so | |
74 | # we need to reset it.) | |
75 | git symbolic-ref HEAD refs/heads/master | |
76 | ||
91413512 CM |
77 | test_expect_success \ |
78 | 'Setup two commits including removal of generated files' ' | |
79 | git init && | |
c9804555 | 80 | touch file1 file2 && |
c7506039 | 81 | stg add file1 file2 && |
91413512 | 82 | git commit -m 1 && |
c7506039 | 83 | stg rm file1 file2 && |
91413512 | 84 | git commit -m 2 && |
c9804555 | 85 | touch file2 |
91413512 CM |
86 | ' |
87 | ||
b6586079 | 88 | test_expect_success \ |
91413512 | 89 | 'Create branch down the stack, behind the conflict caused by the generated file' ' |
f03004e2 | 90 | command_error stg branch --create foo4 master^ |
91413512 CM |
91 | ' |
92 | ||
93 | test_expect_success \ | |
94 | 'Check the branch was not created' ' | |
c9804555 KH |
95 | test ! -e file1 && |
96 | test "$(find .git -name foo4 | tee /dev/stderr | wc -l)" = 0 && | |
97 | test "$(git show-ref | grep foo4 | wc -l)" = 0 && | |
98 | test "$(git symbolic-ref HEAD)" = "refs/heads/master" | |
e152aab3 | 99 | ' |
fe847176 | 100 | |
fe847176 | 101 | test_done |