+
+if [ "$1" = 'clone' ]; then
+ GIT_REMOTE="$2"
+ export GIT_REMOTE
+ VCSH_REPO_NAME="$3"
+ [ -z "$VCSH_REPO_NAME" ] && VCSH_REPO_NAME=$(basename "$GIT_REMOTE" .git)
+ export VCSH_REPO_NAME
+ export GIT_DIR="$VCSH_BASE/$VCSH_REPO_NAME.git"
+elif [ "$1" = 'delete' ] ||
+ [ "$1" = 'init' ] ||
+ [ "$1" = 'run' ] ||
+ [ "$1" = 'seed-gitignore' ]; then
+ [ -z $2 ] && echo "$SELF $1: error: please specify repository to work on" && return 1
+ export VCSH_COMMAND="$1"
+ export VCSH_REPO_NAME="$2"
+ export GIT_DIR="$VCSH_BASE/$VCSH_REPO_NAME.git"
+ shift 2
+ export VCSH_EXTERNAL_COMMAND="$*"
+ if [ "$VCSH_COMMAND" = 'run' ]; then
+ [ -z "$VCSH_EXTERNAL_COMMAND" ] && echo "$SELF $1 $2: error: please specify a command" && return 1
+ fi
+elif [ "$1" = 'help' ] ||
+ [ "$1" = 'list' ]; then
+ export VCSH_COMMAND="$1"
+else
+ [ -z $1 ] && help && return 0
+ export VCSH_COMMAND='run'
+ export VCSH_REPO_NAME="$1"
+ export GIT_DIR="$VCSH_BASE/$VCSH_REPO_NAME.git"
+ [ -d $GIT_DIR ] || (help && return 1) || return 0
+ shift 1
+ export VCSH_EXTERNAL_COMMAND="git $*"
+fi
+
+
+for check_directory in "$VCSH_BASE" "$HOME/.gitignore.d"
+do
+ if [ ! -d "$check_directory" ]; then
+ if [ -e "$check_directory" ]; then
+ echo "$SELF: error: $check_directory exists but is not a directory" >&2
+ return 2
+ else
+ echo "$SELF: info: attempting to create $check_directory"
+ mkdir -p "$check_directory" || (echo "$SELF: error: could not create $check_directory" >&2; return 2) || return $?
+ fi
+ fi
+done
+
+
+if [ "$VCSH_COMMAND" = 'clone' ]; then
+ verbose "clone begin"
+ init
+ git remote add origin "$GIT_REMOTE"
+ git config branch.master.remote origin
+ git config branch.master.merge refs/heads/master
+ git fetch
+ for object in $(git ls-tree -r origin/master | awk '{print $4}'); do
+ [ -e "$object" ] &&
+ echo "$SELF: error: $object exists." &&
+ VCSH_CONFLICT=1;
+ done
+ [ "$VCSH_CONFLICT" = '1' ] &&
+ echo "$SELF: fatal: will stop after fetching and not try to merge!\n" &&
+ echo " Once this situation has been resolved, run 'vcsh run <foo> git pull' to finish cloning.\n" &&
+ return 3
+ git merge origin/master
+# use || return $?
+ verbose "clone end"
+
+#elif [ "$VCSH_COMMAND" = 'help' ] || [ "$#" -eq 0 ]; then
+elif [ "$VCSH_COMMAND" = 'help' ]; then