| 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 | |
| 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 && |
| 17 | test $(stg branch) = "new" |
| 18 | ' |
| 19 | |
| 20 | test_expect_success \ |
| 21 | 'Create a spurious patches/ entry' ' |
| 22 | stg branch master && |
| 23 | stg init && |
| 24 | mkdir -p .git/patches && touch .git/patches/foo1 |
| 25 | ' |
| 26 | |
| 27 | test_expect_success \ |
| 28 | 'Try to create an stgit branch with a spurious patches/ entry' ' |
| 29 | command_error stg branch -c foo1 |
| 30 | ' |
| 31 | |
| 32 | test_expect_success \ |
| 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" |
| 37 | ' |
| 38 | |
| 39 | test_expect_success \ |
| 40 | 'Create a git branch' ' |
| 41 | git update-ref refs/heads/foo2 refs/heads/master |
| 42 | ' |
| 43 | |
| 44 | test_expect_success \ |
| 45 | 'Try to create an stgit branch with an existing git branch by that name' ' |
| 46 | command_error stg branch -c foo2 |
| 47 | ' |
| 48 | |
| 49 | test_expect_success \ |
| 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" |
| 56 | ' |
| 57 | |
| 58 | test_expect_success \ |
| 59 | 'Create an invalid refs/heads/ entry' ' |
| 60 | touch .git/refs/heads/foo3 && |
| 61 | command_error stg branch -c foo3 |
| 62 | ' |
| 63 | |
| 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 | |
| 77 | test_expect_success \ |
| 78 | 'Setup two commits including removal of generated files' ' |
| 79 | git init && |
| 80 | touch file1 file2 && |
| 81 | git add file1 file2 && |
| 82 | git commit -m 1 && |
| 83 | git rm file1 file2 && |
| 84 | git commit -m 2 && |
| 85 | touch file2 |
| 86 | ' |
| 87 | |
| 88 | test_expect_success \ |
| 89 | 'Create branch down the stack, behind the conflict caused by the generated file' ' |
| 90 | command_error stg branch --create foo4 master^ |
| 91 | ' |
| 92 | |
| 93 | test_expect_success \ |
| 94 | 'Check the branch was not created' ' |
| 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" |
| 99 | ' |
| 100 | |
| 101 | test_done |