All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@git.madduck.net.
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
3 [ -n "$VCSH_DEBUG" ] && set -x
4 [ -z "$XDG_CONFIG_HOME" ] && XDG_CONFIG_HOME="$HOME/.config"
5 [ -z "$VCSH_BASE" ] && VCSH_BASE="$XDG_CONFIG_HOME/vcsh/repo.d"
8 if [ "$SELF" = 'bash' ] ||
9 [ "$SELF" = 'dash' ] ||
11 [ "$SELF" = 'zsh' ]; then
18 echo "usage: $SELF <args>
21 [<repo>] Clone from an existing repository
22 help Display this help text
23 delete Delete an existing repository
24 enter Enter repository; spawn new $SHELL
25 exit Exit repository; unset ENV
26 init <repo> Initialize a new repository
27 list List all repositories
29 <command> Use this repository
32 <repo> Seed .gitignore.d/<repo> from git ls-files
33 setup Set up repository with recommended settings
34 use <repo> Use repository; set ENV
36 <repo> <git command> Special command that allows you to run git commands
37 directly without having to type so much ;)" >&2
41 [ -n "$VCSH_DEBUG" ] && echo "$SELF: debug: $@"
45 if [ -n "$VCSH_DEBUG" ] || [ -n "$VCSH_VERBOSE" ]; then echo "$SELF: verbose: $@"; fi
49 git config core.worktree "$GIT_WORK_TREE"
50 git config core.excludesfile ".gitignore.d/$VCSH_REPO_NAME"
51 git config vcsh.vcsh 'true'
52 touch "$HOME/.gitignore.d/$VCSH_REPO_NAME"
53 git add "$HOME/.gitignore.d/$VCSH_REPO_NAME"
57 verbose "init() begin"
59 echo "$SELF: fatal: $GIT_DIR exists" &&
61 export GIT_WORK_TREE="$HOME"
62 mkdir -p "$GIT_WORK_TREE"
63 cd "$GIT_WORK_TREE" ||
64 (echo "$SELF: fatal: could not enter $GIT_WORK_TREE" &&
65 return 1) || return $?
80 if [ ! -d "$GIT_DIR" ]; then
81 echo E: no repository found for "$VCSH_REPO_NAME" >&2
85 export GIT_WORK_TREE="$(git config --get core.worktree)"
86 export VCSH_DIRECTORY="$VCSH_REPO_NAME"
91 if [ "$1" = 'clone' ]; then
92 export VCSH_COMMAND="$1"
96 [ -z "$VCSH_REPO_NAME" ] && VCSH_REPO_NAME=$(basename "$GIT_REMOTE" .git)
98 export GIT_DIR="$VCSH_BASE/$VCSH_REPO_NAME.git"
99 elif [ "$1" = 'delete' ] ||
100 [ "$1" = 'enter' ] ||
103 [ "$1" = 'seed-gitignore' ] ||
104 [ "$1" = 'setup' ] ||
105 [ "$1" = 'use' ]; then
106 [ -z $2 ] && echo "$SELF $1: error: please specify repository to work on" && return 1
107 export VCSH_COMMAND="$1"
108 export VCSH_REPO_NAME="$2"
109 export GIT_DIR="$VCSH_BASE/$VCSH_REPO_NAME.git"
111 export VCSH_EXTERNAL_COMMAND="$*"
112 if [ "$VCSH_COMMAND" = 'run' ]; then
113 [ -z "$VCSH_EXTERNAL_COMMAND" ] && echo "$SELF $1 $2: error: please specify a command" && return 1
115 elif [ "$1" = 'exit' ] ||
117 [ "$1" = 'list' ]; then
118 export VCSH_COMMAND="$1"
120 [ -z $1 ] && help && return 0
121 export VCSH_COMMAND='run'
122 export VCSH_REPO_NAME="$1"
123 export GIT_DIR="$VCSH_BASE/$VCSH_REPO_NAME.git"
124 [ -d $GIT_DIR ] || (help && return 1) || return 0
126 export VCSH_EXTERNAL_COMMAND="git $*"
130 for check_directory in "$VCSH_BASE" "$HOME/.gitignore.d"
132 if [ ! -d "$check_directory" ]; then
133 if [ -e "$check_directory" ]; then
134 echo "$SELF: error: $check_directory exists but is not a directory" >&2
137 echo "$SELF: info: attempting to create $check_directory"
138 mkdir -p "$check_directory" || (echo "$SELF: error: could not create $check_directory" >&2; return 2) || return $?
144 if [ "$VCSH_COMMAND" = 'clone' ]; then
145 verbose "clone begin"
147 git remote add origin "$GIT_REMOTE"
148 git config branch.master.remote origin
149 git config branch.master.merge refs/heads/master
151 for object in $(git ls-tree -r origin/master | awk '{print $4}'); do
153 echo "$SELF: error: $object exists." &&
156 [ "$VCSH_CONFLICT" = '1' ] &&
157 echo "$SELF: fatal: will stop after fetching and not try to merge!\n" &&
158 echo " Once this situation has been resolved, run 'vcsh run <foo> git pull' to finish cloning.\n" &&
160 git merge origin/master
164 #elif [ "$VCSH_COMMAND" = 'help' ] || [ "$#" -eq 0 ]; then
165 elif [ "$VCSH_COMMAND" = 'help' ]; then
168 elif [ "$VCSH_COMMAND" = 'delete' ]; then
169 verbose "delete begin"
173 echo "$SELF: info: This operation WILL DETROY DATA!"
174 files=$(git ls-files)
175 echo "These files will be deleted:
179 AGAIN, THIS WILL DELETE YOUR DATA!
180 To continue, type \"Yes, do as I say\""
182 [ "x$answer" = "xYes, do as I say" ] || return 1
183 for file in $files; do
184 rm -f $file || echo "$SELF: info: could not delete '$file', continuing with deletion"
186 rm -rf "$GIT_DIR" || echo "$SELF: info: could not delete '$GIT_DIR'"
190 elif [ "$VCSH_COMMAND" = 'enter' ]; then
191 verbose "enter begin"
197 elif [ "$VCSH_COMMAND" = 'exit' ]; then
199 # if [ -n "$ZSH_VERSION" ] && [ "$VCSH_NO_IGNORE_EOF" = '1' ]; then
200 # unset VCSH_NO_IGNORE_EOF
201 # setopt NO_IGNORE_EOF
203 [ -z "$VCSH_SOURCED" ] && echo "$SELF $VCSH_COMMAND: You need to source vcsh if you want to run in this mode" && return 10
205 # [ -n "$ZSH_VERSION" ] && [ "$USER" = richih ] && buildPS1
209 elif [ "$VCSH_COMMAND" = 'init' ]; then
215 elif [ "$VCSH_COMMAND" = 'list' ]; then
217 for i in "$VCSH_BASE"/*.git; do
218 echo $(basename "$i" .git)
222 elif [ "$VCSH_COMMAND" = 'run' ]; then
225 $VCSH_EXTERNAL_COMMAND
229 elif [ "$VCSH_COMMAND" = 'seed-gitignore' ]; then
230 verbose "seed-gitignore begin"
232 # Switching directory as this has to be executed from $HOME to be of any use.
233 # Going back into old directory at the end in case `vcsh use` is reactivated.
236 gitignores=$(for file in $(git ls-files); do
238 echo $file; new="${file%/*}"
239 [ "$file" = "$new" ] && break
243 tempfile=$(mktemp) ||
244 (echo "$SELF: fatal: could not create tempfile" && return 1) || return $?
245 echo '*' > "$tempfile"
246 for gitignore in $gitignores; do
247 echo "$gitignore" | sed 's/^/!/' >> "$tempfile"
248 [ -d "$gitignore" ] && echo "$gitignore/*" | sed 's/^/!/'>> "$tempfile"
250 diff -N "$tempfile" "$HOME/.gitignore.d/$VCSH_REPO_NAME" > /dev/null &&
253 if [ -e "$HOME/.gitignore.d/$VCSH_REPO_NAME" ]; then
254 echo "$SELF: info: $HOME/.gitignore.d/$VCSH_REPO_NAME differs from new data, moving it to $HOME/.gitignore.d/$VCSH_REPO_NAME.bak"
255 mv -f "$HOME/.gitignore.d/$VCSH_REPO_NAME" "$HOME/.gitignore.d/$VCSH_REPO_NAME.bak" ||
256 (echo "$SELF: fatal: could not move $HOME/.gitignore.d/$VCSH_REPO_NAME to $HOME/.gitignore.d/$VCSH_REPO_NAME.bak" &&
257 return 1) || return $?
259 mv -f "$tempfile" "$HOME/.gitignore.d/$VCSH_REPO_NAME" ||
260 (echo "$SELF: fatal: could not move $tempfile to $HOME/.gitignore.d/$VCSH_REPO_NAME" && return 1) || return $?
262 verbose "seed-gitignore end"
264 elif [ "$VCSH_COMMAND" = 'setup' ]; then
265 verbose "seed-gitignore begin"
269 verbose "seed-gitignore end"
271 elif [ "$VCSH_COMMAND" = 'use' ]; then
273 # if [ -n "$ZSH_VERSION" ]; then
274 # if [ -o NO_IGNORE_EOF ]; then
275 # export VCSH_NO_IGNORE_EOF=1
283 # bindkey '^d' 'vcsh_exit'
285 [ -z "$VCSH_SOURCED" ] && echo "$SELF $VCSH_COMMAND: You need to source vcsh if you want to run in this mode" && return 10
287 # [ -n "$ZSH_VERSION" ] && [ "$USER" = richih ] && buildPS1
291 verbose "defaulting to calling help()"
293 echo "$SELF: fatal: You should never reach this code. File a bug, please."