Fix problems in t1000-branch-create
[stgit] / t / t1000-branch-create.sh
CommitLineData
fe847176
YD
1#!/bin/sh
2#
3# Copyright (c) 2006 Yann Dirson
4#
5
6test_description='Branch operations.
7
8Exercises the "stg branch" commands.
9'
10
11. ./test-lib.sh
12
ff432158
CM
13test_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 20test_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 27test_expect_success \
e152aab3 28 'Try to create an stgit branch with a spurious patches/ entry' '
c9804555 29 ! stg branch -c foo1
fe847176
YD
30'
31
32test_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
39test_expect_success \
40 'Create a git branch' '
c9804555 41 git update-ref refs/heads/foo2 refs/heads/master
fe847176
YD
42'
43
5f594e90 44test_expect_success \
e152aab3 45 'Try to create an stgit branch with an existing git branch by that name' '
c9804555 46 ! stg branch -c foo2
fe847176
YD
47'
48
49test_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
58test_expect_success \
59 'Create an invalid refs/heads/ entry' '
c9804555
KH
60 touch .git/refs/heads/foo3 &&
61 ! stg branch -c foo3
91413512
CM
62'
63
c9804555
KH
64test_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.)
75git symbolic-ref HEAD refs/heads/master
76
91413512
CM
77test_expect_success \
78 'Setup two commits including removal of generated files' '
79 git init &&
c9804555
KH
80 touch file1 file2 &&
81 git add file1 file2 &&
91413512 82 git commit -m 1 &&
c9804555 83 git rm file1 file2 &&
91413512 84 git commit -m 2 &&
c9804555 85 touch file2
91413512
CM
86'
87
b6586079 88test_expect_success \
91413512 89 'Create branch down the stack, behind the conflict caused by the generated file' '
c9804555 90 ! stg branch --create foo4 master^
91413512
CM
91'
92
93test_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 101test_done