tg.sh: handle help -h
[topgit/pro.git] / t / t5000-update-base.sh
blob7a134819f228ae08f8eafd3a1d9ed4086bac6b91
1 #!/bin/sh
3 test_description='tg update --base mode tests'
5 TEST_NO_CREATE_REPO=1
7 . ./test-lib.sh
9 test_clone_repo_cd() {
10 [ -d "r0" ] || die missing setup-created r0 repo
11 ! [ -e "$1" ] || rm -rf "$1"
12 ! [ -e "$1" ] || { chmod -R u+rw "$1"; rm -rf "$1"; }
13 ! [ -e "$1" ] || die
14 cp -pR r0 "$1" &&
15 cd "$1"
18 get_msg() {
19 git --no-pager log --no-color -n 1 --format=format:%B "$@"
22 test_plan 9
24 test_expect_success 'setup' '
25 test_create_repo r0 && cd r0 &&
26 test_commit first &&
27 test_commit second &&
28 git checkout --orphan annie &&
29 git read-tree --empty &&
30 test_commit orphan &&
31 git checkout -f -b alt first &&
32 test_commit third &&
33 tg_test_create_branch tgbase -m "[BASE] tgbase" :first &&
34 git checkout -f tgbase &&
35 git clean -x -d -f
38 test_expect_success 'related update allowed' '
39 test_clone_repo_cd r1 &&
40 EDITOR="echo editor >" && export EDITOR &&
41 tg update -f --base tgbase alt
44 test_expect_success 'non-fast-forward update denied' '
45 test_clone_repo_cd r1 &&
46 EDITOR="echo editor >" && export EDITOR &&
47 test_must_fail tg update --base tgbase orphan
50 test_expect_success 'non-fast-forward allowed with -f' '
51 test_clone_repo_cd r1 &&
52 EDITOR="echo editor >" && export EDITOR &&
53 tg update -f --base tgbase orphan
56 test_expect_success 'related update custom message' '
57 test_clone_repo_cd r1 &&
58 EDITOR="echo editor >" && export EDITOR &&
59 tg update -f --base -m message tgbase alt &&
60 test z"message" = z"$(get_msg tgbase)"
63 test_expect_success 'related update custom message file' '
64 test_clone_repo_cd r1 &&
65 EDITOR="echo editor >" && export EDITOR &&
66 printf "%s" "\
67 merging it in now...
69 yes we are.
70 too.
71 " >expect &&
72 tg update -f --base -F expect tgbase alt &&
73 get_msg tgbase >actual &&
74 test_diff expect actual
77 test_expect_success 'related update --no-edit' '
78 test_clone_repo_cd r1 &&
79 EDITOR="echo editor >" && export EDITOR &&
80 tg update -f --base --no-edit tgbase alt &&
81 test z"tg update --base tgbase alt" = z"$(get_msg tgbase)"
84 test_expect_success 'related update --edit' '
85 test_clone_repo_cd r1 &&
86 EDITOR="f(){ cp \"\$1\" \"$PWD/editmsg\";echo editor >\"\$1\";};f" && export EDITOR &&
87 tg update -f --base --edit tgbase alt &&
88 test z"editor" = z"$(get_msg tgbase)" &&
89 test z"tg update --base tgbase alt" = z"$(git stripspace -s <editmsg)"
92 test_expect_success 'related update --edit --message' '
93 test_clone_repo_cd r1 &&
94 EDITOR="f(){ cp \"\$1\" \"$PWD/editmsg\";echo editor >\"\$1\";};f" && export EDITOR &&
95 tg update -f --base --edit --message "lah dee dah" tgbase alt &&
96 test z"editor" = z"$(get_msg tgbase)" &&
97 test z"lah dee dah" = z"$(git stripspace -s <editmsg)"
100 test_done