+ # ...and parse for a potential parameter afterwards. As we shifted things out of $* in during getops, we need to look at $1
+ VCSH_REPO_NAME=$1; export VCSH_REPO_NAME
+
+ if [ -n "$VCSH_REPO_NAME" ]; then
+ list_untracked_helper $VCSH_REPO_NAME
+ else
+ for VCSH_REPO_NAME in $(list); do
+ list_untracked_helper $VCSH_REPO_NAME
+ done
+ fi
+ cat $temp_file_untracked
+
+ unset directory_opt directory_component
+ rm -f $temp_file_others $temp_file_untracked $temp_file_untracked_copy || fatal 'Could not delete temp files'
+}
+
+list_untracked_helper() {
+ export GIT_DIR="$VCSH_REPO_D/$VCSH_REPO_NAME.git"
+ git ls-files --others "$directory_opt" | (
+ while read line; do
+ echo "$line"
+ directory_component=${line%%/*}
+ [ -d "$directory_component" ] && printf '%s/\n' "$directory_component"
+ done
+ ) | sort -u > $temp_file_others
+ if [ -z "$ran_once" ]; then
+ ran_once=1
+ cp $temp_file_others $temp_file_untracked || fatal 'Could not copy temp file'
+ fi
+ cp $temp_file_untracked $temp_file_untracked_copy || fatal 'Could not copy temp file'
+ comm -12 --nocheck-order $temp_file_others $temp_file_untracked_copy > $temp_file_untracked
+}
+
+pull() {
+ hook pre-pull
+ for VCSH_REPO_NAME in $(list); do
+ printf '%s: ' "$VCSH_REPO_NAME"
+ GIT_DIR=$VCSH_REPO_D/$VCSH_REPO_NAME.git; export GIT_DIR
+ use
+ git pull
+ VCSH_COMMAND_RETURN_CODE=$?
+ echo
+ done
+ hook post-pull
+}
+
+push() {
+ hook pre-push
+ for VCSH_REPO_NAME in $(list); do
+ printf '%s: ' "$VCSH_REPO_NAME"
+ GIT_DIR=$VCSH_REPO_D/$VCSH_REPO_NAME.git; export GIT_DIR
+ use
+ git push
+ VCSH_COMMAND_RETURN_CODE=$?
+ echo
+ done
+ hook post-push
+}
+
+retire() {
+ unset VCSH_DIRECTORY
+}
+
+rename() {
+ git_dir_exists
+ [ -d "$GIT_DIR_NEW" ] && fatal "'$GIT_DIR_NEW' exists" 54
+ mv -f "$GIT_DIR" "$GIT_DIR_NEW" || fatal "Could not mv '$GIT_DIR' '$GIT_DIR_NEW'" 52
+
+ # Now that the repository has been renamed, we need to fix up its configuration
+ # Overwrite old name..
+ GIT_DIR=$GIT_DIR_NEW
+ VCSH_REPO_NAME=$VCSH_REPO_NAME_NEW
+ # ..and clobber all old configuration
+ upgrade
+}
+
+run() {
+ hook pre-run
+ use
+ "$@"
+ VCSH_COMMAND_RETURN_CODE=$?
+ hook post-run
+}
+
+status() {
+ if [ -t 1 ]; then
+ COLORING="-c color.status=always"
+ fi
+ if [ -n "$VCSH_REPO_NAME" ]; then
+ status_helper $VCSH_REPO_NAME
+ else
+ for VCSH_REPO_NAME in $(list); do
+ STATUS=$(status_helper $VCSH_REPO_NAME "$COLORING")
+ [ -n "$STATUS" -o -z "$VCSH_STATUS_TERSE" ] && echo "$VCSH_REPO_NAME:"
+ [ -n "$STATUS" ] && echo "$STATUS"
+ [ -z "$VCSH_STATUS_TERSE" ] && echo
+ done
+ fi
+}
+
+status_helper() {
+ GIT_DIR=$VCSH_REPO_D/$1.git; export GIT_DIR
+ use
+ remote_tracking_branch=$(git rev-parse --abbrev-ref --symbolic-full-name @{u} 2> /dev/null) && {
+ commits_behind=$(git log ..${remote_tracking_branch} --oneline | wc -l)
+ commits_ahead=$(git log ${remote_tracking_branch}.. --oneline | wc -l)
+ [ ${commits_behind} -ne 0 ] && echo "Behind $remote_tracking_branch by $commits_behind commits"
+ [ ${commits_ahead} -ne 0 ] && echo "Ahead of $remote_tracking_branch by $commits_ahead commits"
+ }
+ git $2 status --short --untracked-files='no'
+ VCSH_COMMAND_RETURN_CODE=$?
+}
+
+upgrade() {
+ hook pre-upgrade
+ # fake-bare repositories are not bare, actually. Set this to false
+ # because otherwise Git complains "fatal: core.bare and core.worktree
+ # do not make sense"
+ git config core.bare false
+ # core.worktree may be absolute or relative to $GIT_DIR, depending on
+ # user preference
+ if [ ! "x$VCSH_WORKTREE" = 'xabsolute' ]; then
+ git config core.worktree "$(cd "$GIT_DIR" && GIT_WORK_TREE=$VCSH_BASE git rev-parse --show-cdup)"
+ elif [ ! "x$VCSH_WORKTREE" = 'xrelative' ]; then
+ git config core.worktree "$VCSH_BASE"
+ fi
+ [ ! "x$VCSH_GITIGNORE" = 'xnone' ] && git config core.excludesfile ".gitignore.d/$VCSH_REPO_NAME"
+ [ ! "x$VCSH_GITATTRIBUTES" = 'xnone' ] && git config core.attributesfile ".gitattributes.d/$VCSH_REPO_NAME"
+ git config vcsh.vcsh 'true'
+ use
+ [ -e "$VCSH_BASE/.gitignore.d/$VCSH_REPO_NAME" ] && git add -f "$VCSH_BASE/.gitignore.d/$VCSH_REPO_NAME"
+ [ -e "$VCSH_BASE/.gitattributes.d/$VCSH_REPO_NAME" ] && git add -f "$VCSH_BASE/.gitattributes.d/$VCSH_REPO_NAME"
+ hook post-upgrade
+}
+
+use() {
+ git_dir_exists
+ VCSH_DIRECTORY=$VCSH_REPO_NAME; export VCSH_DIRECTORY
+}
+
+which() {
+ [ -e "$VCSH_COMMAND_PARAMETER" ] || fatal "'$VCSH_COMMAND_PARAMETER' does not exist" 1
+ for VCSH_REPO_NAME in $(list); do
+ for VCSH_FILE in $(get_files); do
+ echo "$VCSH_FILE" | grep -q "$VCSH_COMMAND_PARAMETER" && echo "$VCSH_REPO_NAME: $VCSH_FILE"
+ done
+ done | sort -u
+}
+
+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
+ OLDIFS=$IFS
+ IFS=$(printf '\n\t')