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.
Avery Pennarun committed
Feb 8, 2010 at 15:00 UTC
77ba30585213ee8e2be21841ba38786fd5bb26a5
2 files changed
+21
-3
git-subtree.sh
+6
-3
@@ -106,9 +106,12 @@ if [ -z "$prefix" ]; then
106
die "You must provide the --prefix option."
107
fi
108
109
-if [ "$command" = "split" -a """"! -e "$prefix" ]; then
110
- die "$prefix does not exist."
111
-fi
109
+case "$command" in
110
+ add) [ -e "$prefix" ] &&
111
+ die "prefix '$prefix' already exists." ;;
112
+ *) [ -e "$prefix" ] ||
113
+ die "'$prefix' does not exist; use 'git subtree add'" ;;
114
+esac
115
116
dir="$(dirname "$prefix/.")"
117
test.sh
+15
@@ -21,6 +21,19 @@ check()
21
fi
22
}
23
24
+check_not()
25
+{
26
+ echo
27
+ echo "check: NOT " "$@"
28
+ if "$@"; then
29
+ echo FAILED
30
+ exit 1
31
+ else
32
+ echo ok
33
+ return 0
34
+ fi
35
+}
36
+
37
check_equal()
38
{
39
echo
@@ -94,6 +107,8 @@ git fetch ../subproj sub1
107
git branch sub1 FETCH_HEAD
108
109
# check if --message works for add
110
+check_not git subtree merge --prefix=subdir sub1
111
+check_not git subtree pull --prefix=subdir ../subproj sub1
112
git subtree add --prefix=subdir --message="Added subproject" sub1
113
check_equal "$(last_commit_message)" "Added subproject"
114
undo