Preserve picked patch name when possible
[stgit.git] / t / t1001-branch-rename.sh
blobc4503a2bd81caef2b25ef3d3568c0a2df29fc38a
1 #!/bin/sh
3 # Copyright (c) 2006 Yann Dirson
6 test_description='Branch renames.
8 Exercises branch renaming commands.
11 . ./test-lib.sh
13 _assert_branch_exists() {
14 git config --get-regexp "branch\\.$1\\." &&
15 git show-ref --verify --quiet "refs/heads/$1" &&
16 git show-ref --verify --quiet "refs/stacks/$1"
19 _assert_branch_missing() {
20 test_expect_code 1 git config --get-regexp "branch\\.$1\\." &&
21 ! git show-ref --verify --quiet "refs/heads/$1" &&
22 ! git show-ref --verify --quiet "refs/stacks/$1"
25 _assert_current_branch_name() {
26 test "$(stg branch)" = "$1"
27 test "$(git symbolic-ref --short HEAD)" = "$1"
30 test_expect_success \
31 'Create an stgit branch from scratch' '
32 stg init &&
34 echo expected*.txt >> .git/info/exclude &&
35 echo patches.txt >> .git/info/exclude &&
36 echo ids.txt >> .git/info/exclude &&
38 stg branch -c foo &&
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 &&
43 stg pop p0 &&
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
53 test_expect_success \
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
65 test_expect_success \
66 'Rename the current stgit branch' '
67 stg branch bar &&
68 _assert_current_branch_name "bar" &&
69 _assert_branch_exists bar &&
70 _assert_branch_missing foo &&
72 stg branch -r 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
81 > p1
82 - p0
83 ! h0
84 EOF
85 test_expect_success \
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' '
112 stg branch -r xxx &&
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>err &&
119 grep "incorrect number of arguments" err
122 test_done