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"
10 echo "usage: $SELF <args>
13 [<repo>] Clone from an existing repository
14 help Display this help text
15 delete Delete an existing repository
16 enter Enter repository; spawn new $SHELL
17 init <repo> Initialize a new repository
18 list List all repositories
20 <command> Use this repository
23 <repo> Seed .gitignore.d/<repo> from git ls-files
24 setup Set up repository with recommended settings
26 <repo> <git command> Special command that allows you to run git commands
27 directly without having to type so much ;)" >&2
31 [ -n "$VCSH_DEBUG" ] && echo "$SELF: debug: $@"
35 if [ -n "$VCSH_DEBUG" ] || [ -n "$VCSH_VERBOSE" ]; then echo "$SELF: verbose: $@"; fi
39 echo "$SELF: fatal: $1" >&2
44 echo "$SELF: error: $1" >&2
48 echo "$SELF: info: $1"
52 git config core.worktree "$GIT_WORK_TREE"
53 git config core.excludesfile ".gitignore.d/$VCSH_REPO_NAME"
54 git config vcsh.vcsh 'true'
55 touch "$HOME/.gitignore.d/$VCSH_REPO_NAME"
56 git add "$HOME/.gitignore.d/$VCSH_REPO_NAME"
60 verbose "init() begin"
61 [ ! -e "$GIT_DIR" ] || fatal "'$GIT_DIR' exists" 10
62 export GIT_WORK_TREE="$HOME"
63 mkdir -p "$GIT_WORK_TREE"
64 cd "$GIT_WORK_TREE" || fatal "could not enter '$GIT_WORK_TREE'" 11
73 if [ ! -d "$GIT_DIR" ]; then
74 error "no repository found for '$VCSH_REPO_NAME'"
78 export GIT_WORK_TREE="$(git config --get core.worktree)"
79 export VCSH_DIRECTORY="$VCSH_REPO_NAME"
84 if [ "$1" = 'clone' ]; then
85 export VCSH_COMMAND="$1"
89 [ -z "$VCSH_REPO_NAME" ] && VCSH_REPO_NAME=$(basename "$GIT_REMOTE" .git)
91 export GIT_DIR="$VCSH_BASE/$VCSH_REPO_NAME.git"
92 elif [ "$1" = 'delete' ] ||
96 [ "$1" = 'seed-gitignore' ] ||
97 [ "$1" = 'setup' ]; then
98 [ -z $2 ] && fatal "$1: please specify repository to work on" 1
99 export VCSH_COMMAND="$1"
100 export VCSH_REPO_NAME="$2"
101 export GIT_DIR="$VCSH_BASE/$VCSH_REPO_NAME.git"
103 export VCSH_EXTERNAL_COMMAND="$*"
104 if [ "$VCSH_COMMAND" = 'run' ]; then
105 [ -z "$VCSH_EXTERNAL_COMMAND" ] && fatal "$1 $2: please specify a command" 1
107 elif [ "$1" = 'help' ] ||
108 [ "$1" = 'list' ]; then
109 export VCSH_COMMAND="$1"
111 [ -z $1 ] && help && exit 0
112 export VCSH_COMMAND='run'
113 export VCSH_REPO_NAME="$1"
114 export GIT_DIR="$VCSH_BASE/$VCSH_REPO_NAME.git"
115 [ -d $GIT_DIR ] || { help; exit 1; }
117 export VCSH_EXTERNAL_COMMAND="git $*"
121 for check_directory in "$VCSH_BASE" "$HOME/.gitignore.d"
123 if [ ! -d "$check_directory" ]; then
124 if [ -e "$check_directory" ]; then
125 fatal "'$check_directory' exists but is not a directory" 13
127 info "attempting to create '$check_directory'"
128 mkdir -p "$check_directory" || fatal "could not create '$check_directory'" 50
134 if [ "$VCSH_COMMAND" = 'clone' ]; then
135 verbose "clone begin"
137 git remote add origin "$GIT_REMOTE"
138 git config branch.master.remote origin
139 git config branch.master.merge refs/heads/master
141 for object in $(git ls-tree -r origin/master | awk '{print $4}'); do
143 error "'$object' exists." &&
146 [ "$VCSH_CONFLICT" = '1' ] &&
147 fatal "will stop after fetching and not try to merge!
148 Once this situation has been resolved, run 'vcsh run $VCSH_REPO_NAME git pull' to finish cloning.\n" 17
149 git merge origin/master
152 #elif [ "$VCSH_COMMAND" = 'help' ] || [ "$#" -eq 0 ]; then
153 elif [ "$VCSH_COMMAND" = 'help' ]; then
156 elif [ "$VCSH_COMMAND" = 'delete' ]; then
157 verbose "delete begin"
161 info "This operation WILL DETROY DATA!"
162 files=$(git ls-files)
163 echo "These files will be deleted:
167 AGAIN, THIS WILL DELETE YOUR DATA!
168 To continue, type \"Yes, do as I say\""
170 [ "x$answer" = "xYes, do as I say" ] || exit 16
171 for file in $files; do
172 rm -f $file || info "could not delete '$file', continuing with deletion"
174 rm -rf "$GIT_DIR" || info "could not delete '$GIT_DIR'"
178 elif [ "$VCSH_COMMAND" = 'enter' ]; then
179 verbose "enter begin"
184 elif [ "$VCSH_COMMAND" = 'init' ]; then
189 elif [ "$VCSH_COMMAND" = 'list' ]; then
191 for i in "$VCSH_BASE"/*.git; do
192 echo $(basename "$i" .git)
196 elif [ "$VCSH_COMMAND" = 'run' ]; then
199 $VCSH_EXTERNAL_COMMAND
202 elif [ "$VCSH_COMMAND" = 'seed-gitignore' ]; then
203 verbose "seed-gitignore begin"
205 # Switching directory as this has to be executed from $HOME to be of any use.
206 # Going back into old directory at the end in case `vcsh use` is reactivated.
209 gitignores=$(for file in $(git ls-files); do
211 echo $file; new="${file%/*}"
212 [ "$file" = "$new" ] && break
216 tempfile=$(mktemp) || fatal "could not create tempfile" 51
217 echo '*' > "$tempfile"
218 for gitignore in $gitignores; do
219 echo "$gitignore" | sed 's/^/!/' >> "$tempfile"
220 [ -d "$gitignore" ] && echo "$gitignore/*" | sed 's/^/!/'>> "$tempfile"
222 diff -N "$tempfile" "$HOME/.gitignore.d/$VCSH_REPO_NAME" > /dev/null &&
225 if [ -e "$HOME/.gitignore.d/$VCSH_REPO_NAME" ]; then
226 info "'$HOME/.gitignore.d/$VCSH_REPO_NAME' differs from new data, moving it to '$HOME/.gitignore.d/$VCSH_REPO_NAME.bak'"
227 mv -f "$HOME/.gitignore.d/$VCSH_REPO_NAME" "$HOME/.gitignore.d/$VCSH_REPO_NAME.bak" ||
228 fatal "could not move '$HOME/.gitignore.d/$VCSH_REPO_NAME' to '$HOME/.gitignore.d/$VCSH_REPO_NAME.bak'" 53
230 mv -f "$tempfile" "$HOME/.gitignore.d/$VCSH_REPO_NAME" ||
231 fatal "could not move '$tempfile' to '$HOME/.gitignore.d/$VCSH_REPO_NAME'" 53
233 verbose "seed-gitignore end"
235 elif [ "$VCSH_COMMAND" = 'setup' ]; then
236 verbose "seed-gitignore begin"
239 verbose "seed-gitignore end"
242 verbose "defaulting to calling help()"
244 fatal "You should never reach this code. File a bug, please." 99