3 # Copyright (c) 2006 Yann Dirson
6 test_description
='Branch operations.
8 Exercises the "stg branch" commands.
14 'Create a branch when the current one is not an StGIT stack' '
16 stg branch --create new origin &&
17 test $(stg branch) = "new"
21 'Create a spurious patches/ entry' '
24 mkdir -p .git/patches && touch .git/patches/foo1
28 'Try to create an stgit branch with a spurious patches/ entry' '
29 command_error stg branch -c foo1
33 'Check that no part of the branch was created' '
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"
40 'Create a git branch' '
41 git update-ref refs/heads/foo2 refs/heads/master
45 'Try to create an stgit branch with an existing git branch by that name' '
46 command_error stg branch -c foo2
50 'Check that no part of the branch was created' '
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"
59 'Create an invalid refs/heads/ entry' '
60 touch .git/refs/heads/foo3 &&
61 command_error stg branch -c foo3
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"
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
78 'Setup two commits including removal of generated files' '
81 git add file1 file2 &&
89 'Create branch down the stack, behind the conflict caused by the generated file' '
90 command_error stg branch --create foo4 master^
94 'Check the branch was not created' '
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"