Skip to content

Commit

Permalink
Improve checking for existence of the --prefix directory.
Browse files Browse the repository at this point in the history
For add, the prefix must *not* already exist.  For all the other commands,
it *must* already exist.
  • Loading branch information
apenwarr committed Feb 8, 2010
1 parent ec54f0d commit 77ba305
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
9 changes: 6 additions & 3 deletions git-subtree.sh
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,12 @@ if [ -z "$prefix" ]; then
die "You must provide the --prefix option."
fi

if [ "$command" = "split" -a """"! -e "$prefix" ]; then
die "$prefix does not exist."
fi
case "$command" in
add) [ -e "$prefix" ] &&
die "prefix '$prefix' already exists." ;;
*) [ -e "$prefix" ] ||
die "'$prefix' does not exist; use 'git subtree add'" ;;
esac

dir="$(dirname "$prefix/.")"

Expand Down
15 changes: 15 additions & 0 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@ check()
fi
}

check_not()
{
echo
echo "check: NOT " "$@"
if "$@"; then
echo FAILED
exit 1
else
echo ok
return 0
fi
}

check_equal()
{
echo
Expand Down Expand Up @@ -94,6 +107,8 @@ git fetch ../subproj sub1
git branch sub1 FETCH_HEAD

# 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
check_equal "$(last_commit_message)" "Added subproject"
undo
Expand Down

0 comments on commit 77ba305

Please sign in to comment.