chiark / gitweb /
Fix bashism
[stgit] / t / t1000-branch-create.sh
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     find .git -name foo | xargs rm -rf &&
25     mkdir -p .git/patches && touch .git/patches/foo
26 '
27
28 test_expect_success \
29     'Try to create an stgit branch with a spurious patches/ entry' '
30     ! stg branch -c foo
31 '
32
33 test_expect_success \
34     'Check that no part of the branch was created' '
35     test "`find .git -name foo | tee /dev/stderr`" = ".git/patches/foo" &&
36     ( grep foo .git/HEAD; test $? = 1 )
37 '
38
39 test_expect_success \
40     'Create a git branch' '
41     find .git -name foo | xargs rm -rf &&
42     cp .git/refs/heads/master .git/refs/heads/foo
43 '
44
45 test_expect_success \
46     'Try to create an stgit branch with an existing git branch by that name' '
47     ! stg branch -c foo
48 '
49
50 test_expect_success \
51     'Check that no part of the branch was created' '
52     test "`find .git -name foo | tee /dev/stderr`" = ".git/refs/heads/foo" &&
53     ( grep foo .git/HEAD; test $? = 1 )
54 '
55
56 test_expect_success \
57     'Create an invalid refs/heads/ entry' '
58     find .git -name foo | xargs rm -rf &&
59     touch .git/refs/heads/foo &&
60     ! stg branch -c foo
61 '
62
63 test_expect_success \
64     'Setup two commits including removal of generated files' '
65     git init &&
66     touch a.c a.o &&
67     git add a.c a.o &&
68     git commit -m 1 &&
69     git rm a.c a.o &&
70     git commit -m 2 &&
71     touch a.o
72 '
73
74 test_expect_failure \
75     'Create branch down the stack, behind the conflict caused by the generated file' '
76     stg branch --create bar master^
77 '
78
79 test_expect_success \
80     'Check the branch was not created' '
81     test ! -r .git/refs/heads/bar &&
82     test ! -r a.c
83 '
84
85 test_done