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 -vx
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
19 list-tracked List all files tracked by vcsh
21 <repo> List files tracked by a repository
23 <newname> Rename repository
25 <command> Use this repository
28 <repo> Seed .gitignore.d/<repo> from git ls-files
29 setup Set up repository with recommended settings
31 <repo> <git command> Special command that allows you to run git commands
32 directly without having to type so much ;)" >&2
36 [ -n "$VCSH_DEBUG" ] && echo "$SELF: debug: $@"
40 if [ -n "$VCSH_DEBUG" ] || [ -n "$VCSH_VERBOSE" ]; then echo "$SELF: verbose: $@"; fi
44 echo "$SELF: fatal: $1" >&2
49 echo "$SELF: error: $1" >&2
53 echo "$SELF: info: $1"
58 git remote add origin "$GIT_REMOTE"
59 git config branch.master.remote origin
60 git config branch.master.merge refs/heads/master
62 for object in $(git ls-tree -r origin/master | awk '{print $4}'); do
64 error "'$object' exists." &&
67 [ "$VCSH_CONFLICT" = '1' ] &&
68 fatal "will stop after fetching and not try to merge!
69 Once this situation has been resolved, run 'vcsh run $VCSH_REPO_NAME git pull' to finish cloning.\n" 17
70 git merge origin/master
74 cd "$HOME" || fatal "could not enter '$HOME'" 11
76 info "This operation WILL DETROY DATA!"
78 echo "These files will be deleted:
82 AGAIN, THIS WILL DELETE YOUR DATA!
83 To continue, type \"Yes, do as I say\""
85 [ "x$answer" = "xYes, do as I say" ] || exit 16
86 for file in $files; do
87 rm -f $file || info "could not delete '$file', continuing with deletion"
89 rmdir "$GIT_DIR" || error "could not delete '$GIT_DIR'"
98 [ -d "$GIT_DIR" ] || fatal "no repository found for '$VCSH_REPO_NAME'" 12
102 [ ! -e "$GIT_DIR" ] || fatal "'$GIT_DIR' exists" 10
103 export GIT_WORK_TREE="$HOME"
104 mkdir -p "$GIT_WORK_TREE" || fatal "could not create '$GIT_WORK_TREE'" 50
105 cd "$GIT_WORK_TREE" || fatal "could not enter '$GIT_WORK_TREE'" 11
111 for i in "$VCSH_BASE"/*.git; do
112 echo $(basename "$i" .git)
117 export GIT_DIR="$VCSH_BASE/$VCSH_REPO_NAME.git"
122 for VCSH_REPO_NAME in $(list); do
129 git ls-files | sort -u
134 [ -d "$GIT_DIR_NEW" ] && fatal "'$GIT_DIR_NEW' exists" 54
135 mv -f "$GIT_DIR" "$GIT_DIR_NEW" || fatal "Could not mv '$GIT_DIR' '$GIT_DIR_NEW'" 52
141 $VCSH_EXTERNAL_COMMAND
146 cd "$HOME" || fatal "could not enter '$HOME'" 11
147 gitignores=$(for file in $(git ls-files); do
149 echo $file; new="${file%/*}"
150 [ "$file" = "$new" ] && break
154 tempfile=$(mktemp) || fatal "could not create tempfile" 51
155 echo '*' > "$tempfile" || fatal "could not write to '$tempfile'" 57
156 for gitignore in $gitignores; do
157 echo "$gitignore" | sed 's/^/!/' >> "$tempfile" || fatal "could not write to '$tempfile'" 57
158 [ -d "$gitignore" ] && { echo "$gitignore/*" | sed 's/^/!/' >> "$tempfile" || fatal "could not write to '$tempfile'" 57; }
160 if diff -N "$tempfile" "$HOME/.gitignore.d/$VCSH_REPO_NAME" > /dev/null; then
161 rm -f "$tempfile" || error "could not delete '$tempfile'"
164 if [ -e "$HOME/.gitignore.d/$VCSH_REPO_NAME" ]; then
165 info "'$HOME/.gitignore.d/$VCSH_REPO_NAME' differs from new data, moving it to '$HOME/.gitignore.d/$VCSH_REPO_NAME.bak'"
166 mv -f "$HOME/.gitignore.d/$VCSH_REPO_NAME" "$HOME/.gitignore.d/$VCSH_REPO_NAME.bak" ||
167 fatal "could not move '$HOME/.gitignore.d/$VCSH_REPO_NAME' to '$HOME/.gitignore.d/$VCSH_REPO_NAME.bak'" 53
169 mv -f "$tempfile" "$HOME/.gitignore.d/$VCSH_REPO_NAME" ||
170 fatal "could not move '$tempfile' to '$HOME/.gitignore.d/$VCSH_REPO_NAME'" 53
175 git config core.worktree "$GIT_WORK_TREE"
176 git config core.excludesfile ".gitignore.d/$VCSH_REPO_NAME"
177 git config vcsh.vcsh 'true'
178 [ -e "$HOME/.gitignore.d/$VCSH_REPO_NAME" ] && git add -f "$HOME/.gitignore.d/$VCSH_REPO_NAME"
183 export GIT_WORK_TREE="$(git config --get core.worktree)"
184 export VCSH_DIRECTORY="$VCSH_REPO_NAME"
187 if [ "$1" = 'clone' ]; then
188 [ -z $2 ] && fatal "$1: please specify a remote" 1
189 export VCSH_COMMAND="$1"
191 [ -n "$3" ] && VCSH_REPO_NAME="$3" || VCSH_REPO_NAME=$(basename "$GIT_REMOTE" .git)
192 export VCSH_REPO_NAME
193 export GIT_DIR="$VCSH_BASE/$VCSH_REPO_NAME.git"
194 elif [ "$1" = 'delete' ] ||
195 [ "$1" = 'enter' ] ||
197 [ "$1" = 'list-tracked-by' ] ||
198 [ "$1" = 'rename' ] ||
200 [ "$1" = 'seed-gitignore' ] ||
201 [ "$1" = 'setup' ]; then
202 [ -z $2 ] && fatal "$1: please specify repository to work on" 1
203 [ "$1" = 'rename' -a -z "$3" ] && fatal "$1: please specify a target name" 1
204 [ "$1" = 'run' -a -z "$3" ] && fatal "$1: please specify a command" 1
205 export VCSH_COMMAND="$1"
206 export VCSH_REPO_NAME="$2"
207 export GIT_DIR="$VCSH_BASE/$VCSH_REPO_NAME.git"
208 [ "$VCSH_COMMAND" = 'rename' ] && export GIT_DIR_NEW="$VCSH_BASE/$3.git"
209 [ "$VCSH_COMMAND" = 'run' ] && shift 2 && export VCSH_EXTERNAL_COMMAND="$*"
210 [ "$VCSH_COMMAND" = 'seed-gitignore' ]
211 elif [ "$1" = 'list' ] ||
212 [ "$1" = 'list-tracked' ]; then
213 export VCSH_COMMAND="$1"
214 elif [ -n "$1" -a -n "$2" ]; then
215 export VCSH_COMMAND='run'
216 export VCSH_REPO_NAME="$1"
217 export GIT_DIR="$VCSH_BASE/$VCSH_REPO_NAME.git"
218 [ -d $GIT_DIR ] || { help; exit 1; }
220 export VCSH_EXTERNAL_COMMAND="git $*"
221 elif [ -n "$1" ]; then
222 export VCSH_COMMAND='enter'
223 export VCSH_REPO_NAME="$1"
224 export GIT_DIR="$VCSH_BASE/$VCSH_REPO_NAME.git"
225 [ -d $GIT_DIR ] || { help; exit 1; }
227 # $1 is empty, or 'help'
231 # Did we receive a directory instead of a name?
232 # Mangle the input to fit normal operation.
233 if echo $VCSH_REPO_NAME | grep -q '/'; then
234 export GIT_DIR=$VCSH_REPO_NAME
235 export VCSH_REPO_NAME=$(basename $VCSH_REPO_NAME .git)
239 for check_directory in "$VCSH_BASE" "$HOME/.gitignore.d"
241 if [ ! -d "$check_directory" ]; then
242 if [ -e "$check_directory" ]; then
243 fatal "'$check_directory' exists but is not a directory" 13
245 info "attempting to create '$check_directory'"
246 mkdir -p "$check_directory" || fatal "could not create '$check_directory'" 50
251 verbose "$VCSH_COMMAND begin"
252 export VCSH_COMMAND=$(echo $VCSH_COMMAND | sed 's/-/_/g')
254 verbose "$VCSH_COMMAND end, exiting"