-# use $REPO_NAME || return 1
- verbose "clone end"
-
-elif [ "$1" = 'init' ]; then
- verbose "init begin"
- [ -z $2 ] && help && echo && echo "$SELF $1: error: please specify repository to work on" && return 0
- export REPO_NAME="$2"
- export GIT_DIR="$VCSH_BASE/$REPO_NAME.git"
- init
-# use "$REPO_NAME" || return 1
- verbose "init end"
-
-#elif [ "$1" = 'exit' ]; then
-# verbose "exit begin"
-# if [ -n "$ZSH_VERSION" ] && [ "$VCSH_NO_IGNORE_EOF" = '1' ]; then
-# unset VCSH_NO_IGNORE_EOF
-# setopt NO_IGNORE_EOF
-# fi
-# leave
-# [ -n "$ZSH_VERSION" ] && [ "$USER" = richih ] && buildPS1
-# verbose "exit end"
-# exit 0
-
-elif [ "$1" = 'seed-gitignore' ]; then
- verbose "seed-gitignore begin"
- [ -z $2 ] && help && echo && echo "$SELF $1: error: please specify repository to work on" && return 0
- use $2 || return 1
- # Switching directory as this has to be executed from $HOME to be of any use.
- # Going back into old directory at the end in case `vcsh use` is reactivated.
- old_dir="$PWD"
- cd "$HOME"
- git config core.excludesfile ".gitignore.d/$REPO_NAME"
+ hook post-merge
+ hook post-clone
+ retire
+ hook post-clone-retired
+}
+
+commit() {
+ hook pre-commit
+ for VCSH_REPO_NAME in $(list); do
+ echo "$VCSH_REPO_NAME: "
+ GIT_DIR=$VCSH_REPO_D/$VCSH_REPO_NAME.git; export GIT_DIR
+ use
+ git commit --untracked-files=no --quiet
+ VCSH_COMMAND_RETURN_CODE=$?
+ echo
+ done
+ hook post-commit
+}
+
+delete() {
+ cd "$VCSH_BASE" || fatal "could not enter '$VCSH_BASE'" 11
+ use
+ info "This operation WILL DESTROY DATA!"
+ files=$(git ls-files)
+ echo "These files will be deleted:
+
+$files
+
+AGAIN, THIS WILL DELETE YOUR DATA!
+To continue, type 'Yes, do as I say'"
+ read answer
+ [ "x$answer" = 'xYes, do as I say' ] || exit 16
+ for file in $files; do
+ rm -f $file || info "could not delete '$file', continuing with deletion"
+ done
+ rm -rf "$GIT_DIR" || error "could not delete '$GIT_DIR'"
+}
+
+enter() {
+ hook pre-enter
+ use
+ $SHELL
+ hook post-enter
+}
+
+git_dir_exists() {
+ [ -d "$GIT_DIR" ] || fatal "no repository found for '$VCSH_REPO_NAME'" 12
+}
+
+hook() {
+ for hook in "$VCSH_HOOK_D/$1"* "$VCSH_HOOK_D/$VCSH_REPO_NAME.$1"*; do
+ [ -x "$hook" ] || continue
+ verbose "executing '$hook'"
+ "$hook"
+ done
+}
+
+init() {
+ hook pre-init
+ [ ! -e "$GIT_DIR" ] || fatal "'$GIT_DIR' exists" 10
+ mkdir -p "$VCSH_BASE" || fatal "could not create '$VCSH_BASE'" 50
+ cd "$VCSH_BASE" || fatal "could not enter '$VCSH_BASE'" 11
+ git init --shared=0600
+ upgrade
+ hook post-init
+}
+
+list() {
+ for repo in "$VCSH_REPO_D"/*.git; do
+ [ -d "$repo" ] && [ -r "$repo" ] && echo "$(basename "$repo" .git)"
+ done
+}
+
+get_files() {
+ GIT_DIR=$VCSH_REPO_D/$VCSH_REPO_NAME.git; export GIT_DIR
+ git ls-files
+}
+
+list_tracked() {
+ for VCSH_REPO_NAME in $(list); do
+ get_files
+ done | sort -u
+}
+
+list_tracked_by() {
+ use
+ git ls-files | sort -u
+}
+
+pull() {
+ hook pre-pull
+ for VCSH_REPO_NAME in $(list); do
+ printf "$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 "$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 [ -n "$VCSH_REPO_NAME" ]; then
+ GIT_DIR=$VCSH_REPO_D/$VCSH_REPO_NAME.git; export GIT_DIR
+ use
+ git status --short --untracked-files='no'
+ VCSH_COMMAND_RETURN_CODE=$?
+ else
+ for VCSH_REPO_NAME in $(list); do
+ echo "$VCSH_REPO_NAME:"
+ GIT_DIR=$VCSH_REPO_D/$VCSH_REPO_NAME.git; export GIT_DIR
+ use
+ git status --short --untracked-files='no'
+ VCSH_COMMAND_RETURN_CODE=$?
+ echo
+ done
+ fi
+}
+
+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() {
+ 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')