Test for generated patchname with trailing period
[stgit.git] / t / t1000-branch-create.sh
blobeeac5cd771c929882c48664ca66a915229f3aa98
1 #!/bin/sh
3 # Copyright (c) 2006 Yann Dirson
6 test_description='Branch operations.
8 Exercises the "stg branch" commands.
11 . ./test-lib.sh
13 test_expect_success \
14 'Create upstream repo' '
15 test_create_repo upstream &&
17 cd upstream &&
18 test_commit one
19 ) &&
20 git remote add origin upstream &&
21 git fetch origin master &&
22 git branch --set-upstream-to=origin/master &&
23 test "$(git config --get branch.master.remote)" = "origin"
26 test_expect_success \
27 'Create a branch when the current one is not an StGit stack' '
28 git branch regular-branch &&
29 git branch --set-upstream-to=origin/master regular-branch &&
30 stg branch --create new regular-branch &&
31 test "$(stg branch)" = "new"
34 test_expect_success \
35 'Check for various bits of new branch' '
36 git show-ref --verify --quiet refs/heads/new &&
37 git show-ref --verify --quiet refs/stacks/new &&
38 test_path_is_missing .git/patches/new &&
39 test_path_is_missing .git/refs/patches &&
40 test "$(git config --get branch.new.remote)" = "origin" &&
41 test "$(git config --get branch.new.stgit.parentbranch)" = "regular-branch" &&
42 test_must_fail git config branch.new.stgit.stackformatversion &&
43 test "$(git rev-parse HEAD)" = "$(git rev-parse new)"
46 test_expect_success \
47 'Too many args to --create' '
48 command_error stg branch --create aname acommit anextra
51 test_expect_success \
52 'Create branch with worktree changes' '
53 stg new -m p0 &&
54 echo hello > file.txt &&
55 stg add file.txt &&
56 stg refresh &&
57 echo bye > file.txt &&
58 stg branch --create branch-with-change &&
59 test "$(stg branch)" = "branch-with-change" &&
60 test "$(stg status file.txt)" = " M file.txt" &&
61 test "$(stg series --noprefix --all)" = "" &&
62 grep -e bye file.txt &&
63 git checkout file.txt
66 test_expect_success \
67 'Initialize master branch' '
68 stg branch master &&
69 stg init
72 test_expect_success \
73 'Attempt switching to current branch' '
74 command_error stg branch $(stg branch) 2>&1 |
75 grep "is already the current branch"
78 test_expect_success \
79 'Attempt no branch command' '
80 command_error stg branch foo bar 2>&1 |
81 grep "incorrect number of arguments"
84 test_expect_success \
85 'Invalid num arguments to branch list' '
86 command_error stg branch --list new 2>&1 |
87 grep "incorrect number of arguments"
90 test_expect_success \
91 'Create a git branch' '
92 git update-ref refs/heads/foo2 refs/heads/master
95 test_expect_success \
96 'Try to create an stgit branch with an existing git branch by that name' '
97 command_error stg branch -c foo2
100 test_expect_success \
101 'Check that no part of the branch was created' '
102 test $(find .git -name foo2 \
103 | tee /dev/stderr \
104 | grep -v ^\\.git/refs/heads/foo2$ \
105 | grep -v ^\\.git/logs/refs/heads/foo2$ \
106 | wc -l) -eq 0 &&
107 test $(git show-ref | grep foo2 | wc -l) -eq 1 &&
108 test_must_fail git config --get-regexp branch\.foo3 &&
109 test "$(git symbolic-ref HEAD)" = "refs/heads/master"
112 test_expect_success \
113 'Create an invalid refs/heads/ entry' '
114 touch .git/refs/heads/foo3 &&
115 test_when_finished rm .git/refs/heads/foo3 &&
116 command_error stg branch -c foo3
119 test_expect_success \
120 'Check that no part of the branch was created' '
121 # Workaround for the test failure to make the rest of the subtests
122 # succeed. (HEAD was erroneously overwritten with the bad foo3 ref, so
123 # we need to reset it.)
124 test_when_finished git symbolic-ref HEAD refs/heads/master
125 test $(find .git -name foo3 \
126 | tee /dev/stderr \
127 | grep -v ^\\.git/refs/heads/foo3$ \
128 | wc -l) -eq 0 &&
129 test $(git show-ref | grep foo3 | wc -l) -eq 0 &&
130 test_must_fail git config --get-regexp branch\.foo3 &&
131 test "$(git symbolic-ref HEAD)" = "refs/heads/master"
134 test_expect_success \
135 'Setup two commits including removal of generated files' '
136 touch file1 file2 &&
137 stg add file1 file2 &&
138 git commit -m 1 &&
139 stg rm file1 file2 &&
140 git commit -m 2 &&
141 touch file2
144 test_expect_success \
145 'Create branch down the stack, behind the conflict caused by the generated file' '
146 command_error stg branch --create foo4 master^
149 test_expect_success \
150 'Check the branch was not created' '
151 test_path_is_missing file1 &&
152 test $(find .git -name foo4 | tee /dev/stderr | wc -l) -eq 0 &&
153 test $(git show-ref | grep foo4 | wc -l) -eq 0 &&
154 test_must_fail git config --get-regexp branch\.foo4 &&
155 test "$(git symbolic-ref HEAD)" = "refs/heads/master" &&
156 rm file2
159 test_expect_success \
160 'Branch list from detached head' '
161 git checkout HEAD~ &&
162 stg branch --list > list.txt &&
163 test_when_finished rm list.txt &&
164 test "$(cat list.txt | grep -c -e ">")" = "0"
167 test_expect_success \
168 'Branch create from detached head' '
169 stg branch --create from-detached
172 test_expect_success \
173 'Switch branch from detached head' '
174 stg branch new
177 test_done