3 # Copyright (c) 2006 Yann Dirson
6 test_description
='Branch renames.
8 Exercises branch renaming commands.
13 _assert_branch_exists
() {
14 git config
--get-regexp "branch\\.$1\\." &&
15 test_path_is_file
".git/refs/heads/$1" &&
16 test_path_is_file
".git/refs/heads/$1.stgit"
19 _assert_branch_missing
() {
20 test_expect_code
1 git config
--get-regexp "branch\\.$1\\." &&
21 test_path_is_missing
".git/refs/heads/$1" &&
22 test_path_is_missing
".git/refs/heads/$1.stgit"
25 _assert_current_branch_name
() {
26 test "$(stg branch)" = "$1"
27 test "$(git symbolic-ref --short HEAD)" = "$1"
31 'Create an stgit branch from scratch' '
34 echo expected*.txt >> .git/info/exclude &&
35 echo patches.txt >> .git/info/exclude &&
36 echo ids.txt >> .git/info/exclude &&
39 _assert_current_branch_name "foo" &&
41 stg new p0 -m "p0" && # create a patch that will be popped
42 touch "p0.txt" && stg refresh &&
45 stg new h0 -m "h0" && # create a patch that will be popped and hidden
46 touch "h0.txt" && stg refresh &&
47 stg pop h0 && stg hide h0 &&
49 stg new p1 -m "p1" # create a patch that will be left applied
50 touch "p1.txt" && stg refresh
54 'Rename a stgit branch' '
55 _assert_branch_exists foo &&
57 stg branch --clone buz &&
58 _assert_current_branch_name "buz" &&
60 stg branch -r foo bar &&
61 _assert_branch_missing foo &&
62 _assert_branch_exists bar
66 'Rename the current stgit branch' '
68 _assert_current_branch_name "bar" &&
69 _assert_branch_exists bar &&
70 _assert_branch_missing foo &&
73 _assert_current_branch_name "foo" &&
74 _assert_branch_exists foo &&
75 _assert_branch_missing bar &&
77 test "$(stg series --noprefix --applied)" = "p1"
80 cat > expected-patches.txt
<<EOF
86 'Check integrity of hidden/popped patches after rename operations' '
88 _assert_current_branch_name "foo" &&
90 # Check that all three patches are still there.
91 stg series -a > patches.txt &&
92 test_cmp expected-patches.txt patches.txt &&
94 # Record current IDs of patches.
95 ( stg id p1 && stg id h0 && stg id p0 ) > expected-ids.txt &&
97 stg branch -r integrity &&
98 _assert_current_branch_name "integrity" &&
100 # Check that all three patches are still there after rename.
101 stg series -a > patches.txt &&
102 test_cmp expected-patches.txt patches.txt &&
104 # Verify current IDs of patches.
105 ( stg id p1 && stg id h0 && stg id p0 ) > ids.txt &&
106 test_cmp expected-ids.txt ids.txt
110 test_expect_success \
111 'Rename the current stgit branch single arg' '
113 _assert_current_branch_name "xxx"
116 test_expect_success \
117 'Invalid num args to rename' '
118 command_error stg branch --rename bar biz bop 2>&1 |
119 grep "incorrect number of arguments"