Improve checking for existence of the --prefix directory.

For add, the prefix must *not* already exist.  For all the other commands,
it *must* already exist.
This commit is contained in:
Avery Pennarun 2010-02-08 15:00:42 -05:00
parent ec54f0d9ad
commit 77ba305852
2 changed files with 21 additions and 3 deletions

View File

@ -106,9 +106,12 @@ if [ -z "$prefix" ]; then
die "You must provide the --prefix option." die "You must provide the --prefix option."
fi fi
if [ "$command" = "split" -a """"! -e "$prefix" ]; then case "$command" in
die "$prefix does not exist." add) [ -e "$prefix" ] &&
fi die "prefix '$prefix' already exists." ;;
*) [ -e "$prefix" ] ||
die "'$prefix' does not exist; use 'git subtree add'" ;;
esac
dir="$(dirname "$prefix/.")" dir="$(dirname "$prefix/.")"

15
test.sh
View File

@ -21,6 +21,19 @@ check()
fi fi
} }
check_not()
{
echo
echo "check: NOT " "$@"
if "$@"; then
echo FAILED
exit 1
else
echo ok
return 0
fi
}
check_equal() check_equal()
{ {
echo echo
@ -94,6 +107,8 @@ git fetch ../subproj sub1
git branch sub1 FETCH_HEAD git branch sub1 FETCH_HEAD
# check if --message works for add # check if --message works for add
check_not git subtree merge --prefix=subdir sub1
check_not git subtree pull --prefix=subdir ../subproj sub1
git subtree add --prefix=subdir --message="Added subproject" sub1 git subtree add --prefix=subdir --message="Added subproject" sub1
check_equal "$(last_commit_message)" "Added subproject" check_equal "$(last_commit_message)" "Added subproject"
undo undo