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: error: $1" >&2
43 echo "$SELF: fatal error: $1" >&2
48 git config core.worktree "$GIT_WORK_TREE"
49 git config core.excludesfile ".gitignore.d/$VCSH_REPO_NAME"
50 git config vcsh.vcsh 'true'
51 touch "$HOME/.gitignore.d/$VCSH_REPO_NAME"
52 git add "$HOME/.gitignore.d/$VCSH_REPO_NAME"
56 verbose "init() begin"
57 [ ! -e "$GIT_DIR" ] || fatal "$GIT_DIR exists" 10
58 export GIT_WORK_TREE="$HOME"
59 mkdir -p "$GIT_WORK_TREE"
60 cd "$GIT_WORK_TREE" || fatal "could not enter $GIT_WORK_TREE" 11
69 if [ ! -d "$GIT_DIR" ]; then
70 error "no repository found for '$VCSH_REPO_NAME'"
74 export GIT_WORK_TREE="$(git config --get core.worktree)"
75 export VCSH_DIRECTORY="$VCSH_REPO_NAME"
80 if [ "$1" = 'clone' ]; then
81 export VCSH_COMMAND="$1"
85 [ -z "$VCSH_REPO_NAME" ] && VCSH_REPO_NAME=$(basename "$GIT_REMOTE" .git)
87 export GIT_DIR="$VCSH_BASE/$VCSH_REPO_NAME.git"
88 elif [ "$1" = 'delete' ] ||
92 [ "$1" = 'seed-gitignore' ] ||
93 [ "$1" = 'setup' ]; then
94 [ -z $2 ] && fatal "$1: please specify repository to work on" 1
95 export VCSH_COMMAND="$1"
96 export VCSH_REPO_NAME="$2"
97 export GIT_DIR="$VCSH_BASE/$VCSH_REPO_NAME.git"
99 export VCSH_EXTERNAL_COMMAND="$*"
100 if [ "$VCSH_COMMAND" = 'run' ]; then
101 [ -z "$VCSH_EXTERNAL_COMMAND" ] && fatal "$1 $2: please specify a command" 1
103 elif [ "$1" = 'help' ] ||
104 [ "$1" = 'list' ]; then
105 export VCSH_COMMAND="$1"
107 [ -z $1 ] && help && exit 0
108 export VCSH_COMMAND='run'
109 export VCSH_REPO_NAME="$1"
110 export GIT_DIR="$VCSH_BASE/$VCSH_REPO_NAME.git"
111 [ -d $GIT_DIR ] || { help; exit 1; }
113 export VCSH_EXTERNAL_COMMAND="git $*"
117 for check_directory in "$VCSH_BASE" "$HOME/.gitignore.d"
119 if [ ! -d "$check_directory" ]; then
120 if [ -e "$check_directory" ]; then
121 fatal "$check_directory exists but is not a directory" 13
123 echo "$SELF: info: attempting to create $check_directory"
124 mkdir -p "$check_directory" || fatal "could not create $check_directory" 50
130 if [ "$VCSH_COMMAND" = 'clone' ]; then
131 verbose "clone begin"
133 git remote add origin "$GIT_REMOTE"
134 git config branch.master.remote origin
135 git config branch.master.merge refs/heads/master
137 for object in $(git ls-tree -r origin/master | awk '{print $4}'); do
139 error "$object exists." &&
142 [ "$VCSH_CONFLICT" = '1' ] &&
143 fatal "will stop after fetching and not try to merge!
144 Once this situation has been resolved, run 'vcsh run <foo> git pull' to finish cloning.\n" 17
145 git merge origin/master
148 #elif [ "$VCSH_COMMAND" = 'help' ] || [ "$#" -eq 0 ]; then
149 elif [ "$VCSH_COMMAND" = 'help' ]; then
152 elif [ "$VCSH_COMMAND" = 'delete' ]; then
153 verbose "delete begin"
157 echo "$SELF: info: This operation WILL DETROY DATA!"
158 files=$(git ls-files)
159 echo "These files will be deleted:
163 AGAIN, THIS WILL DELETE YOUR DATA!
164 To continue, type \"Yes, do as I say\""
166 [ "x$answer" = "xYes, do as I say" ] || exit 16
167 for file in $files; do
168 rm -f $file || echo "$SELF: info: could not delete '$file', continuing with deletion"
170 rm -rf "$GIT_DIR" || echo "$SELF: info: could not delete '$GIT_DIR'"
174 elif [ "$VCSH_COMMAND" = 'enter' ]; then
175 verbose "enter begin"
180 elif [ "$VCSH_COMMAND" = 'init' ]; then
185 elif [ "$VCSH_COMMAND" = 'list' ]; then
187 for i in "$VCSH_BASE"/*.git; do
188 echo $(basename "$i" .git)
192 elif [ "$VCSH_COMMAND" = 'run' ]; then
195 $VCSH_EXTERNAL_COMMAND
198 elif [ "$VCSH_COMMAND" = 'seed-gitignore' ]; then
199 verbose "seed-gitignore begin"
201 # Switching directory as this has to be executed from $HOME to be of any use.
202 # Going back into old directory at the end in case `vcsh use` is reactivated.
205 gitignores=$(for file in $(git ls-files); do
207 echo $file; new="${file%/*}"
208 [ "$file" = "$new" ] && break
212 tempfile=$(mktemp) || fatal "could not create tempfile" 51
213 echo '*' > "$tempfile"
214 for gitignore in $gitignores; do
215 echo "$gitignore" | sed 's/^/!/' >> "$tempfile"
216 [ -d "$gitignore" ] && echo "$gitignore/*" | sed 's/^/!/'>> "$tempfile"
218 diff -N "$tempfile" "$HOME/.gitignore.d/$VCSH_REPO_NAME" > /dev/null &&
221 if [ -e "$HOME/.gitignore.d/$VCSH_REPO_NAME" ]; then
222 echo "$SELF: info: $HOME/.gitignore.d/$VCSH_REPO_NAME differs from new data, moving it to $HOME/.gitignore.d/$VCSH_REPO_NAME.bak"
223 mv -f "$HOME/.gitignore.d/$VCSH_REPO_NAME" "$HOME/.gitignore.d/$VCSH_REPO_NAME.bak" ||
224 fatal "could not move $HOME/.gitignore.d/$VCSH_REPO_NAME to $HOME/.gitignore.d/$VCSH_REPO_NAME.bak" 53
226 mv -f "$tempfile" "$HOME/.gitignore.d/$VCSH_REPO_NAME" ||
227 fatal "could not move $tempfile to $HOME/.gitignore.d/$VCSH_REPO_NAME" 53
229 verbose "seed-gitignore end"
231 elif [ "$VCSH_COMMAND" = 'setup' ]; then
232 verbose "seed-gitignore begin"
235 verbose "seed-gitignore end"
238 verbose "defaulting to calling help()"
240 fatal "You should never reach this code. File a bug, please." 99