Merge branch 'jc/branch-desc-typoavoidance' into maint

* jc/branch-desc-typoavoidance:
  branch --edit-description: protect against mistyped branch name
  tests: add write_script helper function
This commit is contained in:
Junio C Hamano
2012-02-13 11:42:07 -08:00
3 changed files with 61 additions and 4 deletions

View File

@ -3,11 +3,8 @@
# Copyright (c) 2005 Amos Waterland
#
test_description='git branch --foo should not create bogus branch
test_description='git branch assorted tests'
This test runs git branch --help and checks that the argument is properly
handled. Specifically, that a bogus branch is not created.
'
. ./test-lib.sh
test_expect_success \
@ -620,4 +617,40 @@ test_expect_success 'use set-upstream on the current branch' '
'
test_expect_success 'use --edit-description' '
write_script editor <<-\EOF &&
echo "New contents" >"$1"
EOF
EDITOR=./editor git branch --edit-description &&
write_script editor <<-\EOF &&
git stripspace -s <"$1" >"EDITOR_OUTPUT"
EOF
EDITOR=./editor git branch --edit-description &&
echo "New contents" >expect &&
test_cmp EDITOR_OUTPUT expect
'
test_expect_success 'detect typo in branch name when using --edit-description' '
write_script editor <<-\EOF &&
echo "New contents" >"$1"
EOF
(
EDITOR=./editor &&
export EDITOR &&
test_must_fail git branch --edit-description no-such-branch
)
'
test_expect_success 'refuse --edit-description on unborn branch for now' '
write_script editor <<-\EOF &&
echo "New contents" >"$1"
EOF
git checkout --orphan unborn &&
(
EDITOR=./editor &&
export EDITOR &&
test_must_fail git branch --edit-description
)
'
test_done

View File

@ -381,11 +381,20 @@ test_config () {
git config "$@"
}
test_config_global () {
test_when_finished "test_unconfig --global '$1'" &&
git config --global "$@"
}
write_script () {
{
echo "#!${2-"$SHELL_PATH"}" &&
cat
} >"$1" &&
chmod +x "$1"
}
# Use test_set_prereq to tell that a particular prerequisite is available.
# The prerequisite can later be checked for in two ways:
#