X-Git-Url: https://git.madduck.net/code/vcsh.git/blobdiff_plain/04836991be4626c60964f77a935d425e41782c9f..fba9277c48c1511a4dbdab22cccc8cd5250621b6:/vcsh

diff --git a/vcsh b/vcsh
index e64ca0b..175a9d1 100755
--- a/vcsh
+++ b/vcsh
@@ -264,7 +264,7 @@ upgrade() {
 	hook pre-upgrade
 	use
 	git config core.worktree     "$GIT_WORK_TREE"
-	git config core.excludesfile ".gitignore.d/$VCSH_REPO_NAME"
+	[ ! "x$VCSH_GITIGNORE" = 'xnone' ] && git config core.excludesfile ".gitignore.d/$VCSH_REPO_NAME"
 	git config vcsh.vcsh         'true'
 	[ -e "$VCSH_BASE/.gitignore.d/$VCSH_REPO_NAME" ] && git add -f "$VCSH_BASE/.gitignore.d/$VCSH_REPO_NAME"
 	hook post-upgrade
@@ -285,6 +285,12 @@ which() {
 }
 
 write_gitignore() {
+	# Don't do anything if the user does not want to write gitignore
+	if [ "x$VCSH_GITIGNORE" = 'xnone' ]; then
+		info "Not writing gitignore as '\$VCSH_GITIGNORE' is set to 'none'"
+		exit
+	fi
+
 	use
 	cd "$VCSH_BASE" || fatal "could not enter '$VCSH_BASE'" 11
 	gitignores=$(for file in $(git ls-files); do
@@ -298,7 +304,7 @@ write_gitignore() {
 	echo '*' > "$tempfile" || fatal "could not write to '$tempfile'" 57
 	for gitignore in $gitignores; do
 		echo "$gitignore" | sed 's@^@!/@' >> "$tempfile" || fatal "could not write to '$tempfile'" 57
-		if [ x$VCSH_GITIGNORE = x'recursive' ] && [ -d "$gitignore" ]; then
+		if [ "x$VCSH_GITIGNORE" = 'xrecursive' ] && [ -d "$gitignore" ]; then
 			{ echo "$gitignore/*" | sed 's@^@!/@' >> "$tempfile" || fatal "could not write to '$tempfile'" 57; }
 		fi
 	done
@@ -315,8 +321,8 @@ write_gitignore() {
 		fatal "could not move '$tempfile' to '$VCSH_BASE/.gitignore.d/$VCSH_REPO_NAME'" 53
 }
 
-if [ ! "x$VCSH_GITIGNORE" = 'xexact' ] && [ ! "x$VCSH_GITIGNORE" = 'xrecursive' ]; then
-	fatal "'\$VCSH_GITIGNORE' must be either 'exact' or 'recursive'" 1
+if [ ! "x$VCSH_GITIGNORE" = 'xexact' ] && [ ! "x$VCSH_GITIGNORE" = 'xrecursive' ] && [ ! "x$VCSH_GITIGNORE" = 'xnone' ]; then
+	fatal "'\$VCSH_GITIGNORE' must equal 'exact', 'recursive', or 'none'" 1
 fi
 
 if [ "$1" = 'clone' ]; then
@@ -380,9 +386,8 @@ if echo $VCSH_REPO_NAME | grep -q '/'; then
 	export VCSH_REPO_NAME=$(basename "$VCSH_REPO_NAME" .git)
 fi
 
-
-for check_directory in "$VCSH_REPO_D" "$VCSH_BASE/.gitignore.d"
-do
+check_dir() {
+	check_directory="$1"
 	if [ ! -d "$check_directory" ]; then
 		if [ -e "$check_directory" ]; then
 			fatal "'$check_directory' exists but is not a directory" 13
@@ -391,7 +396,10 @@ do
 			mkdir -p "$check_directory" || fatal "could not create '$check_directory'" 50
 		fi
 	fi
-done
+}
+
+check_dir "$VCSH_REPO_D"
+[ ! "x$VCSH_GITIGNORE" = 'xnone' ] && check_dir "$VCSH_BASE/.gitignore.d"
 
 verbose "$VCSH_COMMAND begin"
 export VCSH_COMMAND=$(echo $VCSH_COMMAND | sed 's/-/_/g')