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 git config core.worktree "$GIT_WORK_TREE"
40 git config core.excludesfile ".gitignore.d/$VCSH_REPO_NAME"
41 git config vcsh.vcsh 'true'
42 touch "$HOME/.gitignore.d/$VCSH_REPO_NAME"
43 git add "$HOME/.gitignore.d/$VCSH_REPO_NAME"
47 verbose "init() begin"
49 echo "$SELF: fatal: $GIT_DIR exists" &&
51 export GIT_WORK_TREE="$HOME"
52 mkdir -p "$GIT_WORK_TREE"
53 cd "$GIT_WORK_TREE" ||
54 { echo "$SELF: fatal: could not enter $GIT_WORK_TREE"; return 11; }
63 if [ ! -d "$GIT_DIR" ]; then
64 echo E: no repository found for "$VCSH_REPO_NAME" >&2
68 export GIT_WORK_TREE="$(git config --get core.worktree)"
69 export VCSH_DIRECTORY="$VCSH_REPO_NAME"
74 if [ "$1" = 'clone' ]; then
75 export VCSH_COMMAND="$1"
79 [ -z "$VCSH_REPO_NAME" ] && VCSH_REPO_NAME=$(basename "$GIT_REMOTE" .git)
81 export GIT_DIR="$VCSH_BASE/$VCSH_REPO_NAME.git"
82 elif [ "$1" = 'delete' ] ||
86 [ "$1" = 'seed-gitignore' ] ||
87 [ "$1" = 'setup' ]; then
88 [ -z $2 ] && echo "$SELF $1: error: please specify repository to work on" && exit 1
89 export VCSH_COMMAND="$1"
90 export VCSH_REPO_NAME="$2"
91 export GIT_DIR="$VCSH_BASE/$VCSH_REPO_NAME.git"
93 export VCSH_EXTERNAL_COMMAND="$*"
94 if [ "$VCSH_COMMAND" = 'run' ]; then
95 [ -z "$VCSH_EXTERNAL_COMMAND" ] && echo "$SELF $1 $2: error: please specify a command" && exit 1
97 elif [ "$1" = 'help' ] ||
98 [ "$1" = 'list' ]; then
99 export VCSH_COMMAND="$1"
101 [ -z $1 ] && help && exit 0
102 export VCSH_COMMAND='run'
103 export VCSH_REPO_NAME="$1"
104 export GIT_DIR="$VCSH_BASE/$VCSH_REPO_NAME.git"
105 [ -d $GIT_DIR ] || { help; exit 1; }
107 export VCSH_EXTERNAL_COMMAND="git $*"
111 for check_directory in "$VCSH_BASE" "$HOME/.gitignore.d"
113 if [ ! -d "$check_directory" ]; then
114 if [ -e "$check_directory" ]; then
115 echo "$SELF: fatal: $check_directory exists but is not a directory" >&2
118 echo "$SELF: info: attempting to create $check_directory"
119 mkdir -p "$check_directory" || { echo "$SELF: fatal: could not create $check_directory" >&2; exit 50; }
125 if [ "$VCSH_COMMAND" = 'clone' ]; then
126 verbose "clone begin"
128 git remote add origin "$GIT_REMOTE"
129 git config branch.master.remote origin
130 git config branch.master.merge refs/heads/master
132 for object in $(git ls-tree -r origin/master | awk '{print $4}'); do
134 echo "$SELF: error: $object exists." &&
137 [ "$VCSH_CONFLICT" = '1' ] &&
138 echo "$SELF: fatal: will stop after fetching and not try to merge!\n" &&
139 echo " Once this situation has been resolved, run 'vcsh run <foo> git pull' to finish cloning.\n" &&
141 git merge origin/master
144 #elif [ "$VCSH_COMMAND" = 'help' ] || [ "$#" -eq 0 ]; then
145 elif [ "$VCSH_COMMAND" = 'help' ]; then
148 elif [ "$VCSH_COMMAND" = 'delete' ]; then
149 verbose "delete begin"
153 echo "$SELF: info: This operation WILL DETROY DATA!"
154 files=$(git ls-files)
155 echo "These files will be deleted:
159 AGAIN, THIS WILL DELETE YOUR DATA!
160 To continue, type \"Yes, do as I say\""
162 [ "x$answer" = "xYes, do as I say" ] || exit 16
163 for file in $files; do
164 rm -f $file || echo "$SELF: info: could not delete '$file', continuing with deletion"
166 rm -rf "$GIT_DIR" || echo "$SELF: info: could not delete '$GIT_DIR'"
170 elif [ "$VCSH_COMMAND" = 'enter' ]; then
171 verbose "enter begin"
176 elif [ "$VCSH_COMMAND" = 'init' ]; then
181 elif [ "$VCSH_COMMAND" = 'list' ]; then
183 for i in "$VCSH_BASE"/*.git; do
184 echo $(basename "$i" .git)
188 elif [ "$VCSH_COMMAND" = 'run' ]; then
191 $VCSH_EXTERNAL_COMMAND
194 elif [ "$VCSH_COMMAND" = 'seed-gitignore' ]; then
195 verbose "seed-gitignore begin"
197 # Switching directory as this has to be executed from $HOME to be of any use.
198 # Going back into old directory at the end in case `vcsh use` is reactivated.
201 gitignores=$(for file in $(git ls-files); do
203 echo $file; new="${file%/*}"
204 [ "$file" = "$new" ] && break
208 tempfile=$(mktemp) ||
209 { echo "$SELF: fatal: could not create tempfile"; exit 51; }
210 echo '*' > "$tempfile"
211 for gitignore in $gitignores; do
212 echo "$gitignore" | sed 's/^/!/' >> "$tempfile"
213 [ -d "$gitignore" ] && echo "$gitignore/*" | sed 's/^/!/'>> "$tempfile"
215 diff -N "$tempfile" "$HOME/.gitignore.d/$VCSH_REPO_NAME" > /dev/null &&
218 if [ -e "$HOME/.gitignore.d/$VCSH_REPO_NAME" ]; then
219 echo "$SELF: info: $HOME/.gitignore.d/$VCSH_REPO_NAME differs from new data, moving it to $HOME/.gitignore.d/$VCSH_REPO_NAME.bak"
220 mv -f "$HOME/.gitignore.d/$VCSH_REPO_NAME" "$HOME/.gitignore.d/$VCSH_REPO_NAME.bak" ||
221 { echo "$SELF: fatal: could not move $HOME/.gitignore.d/$VCSH_REPO_NAME to $HOME/.gitignore.d/$VCSH_REPO_NAME.bak"; exit 53; }
223 mv -f "$tempfile" "$HOME/.gitignore.d/$VCSH_REPO_NAME" ||
224 { echo "$SELF: fatal: could not move $tempfile to $HOME/.gitignore.d/$VCSH_REPO_NAME" && exit 53; }
226 verbose "seed-gitignore end"
228 elif [ "$VCSH_COMMAND" = 'setup' ]; then
229 verbose "seed-gitignore begin"
232 verbose "seed-gitignore end"
235 verbose "defaulting to calling help()"
237 echo "$SELF: fatal: You should never reach this code. File a bug, please."