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
7 [ -z "$XDG_CONFIG_HOME" ] && XDG_CONFIG_HOME="$HOME/.config"
8 [ -z "$VCSH_BASE" ] && VCSH_BASE="$XDG_CONFIG_HOME/vcsh/repo.d"
9 for check_directory in "$VCSH_BASE" "$HOME/.gitignore.d"
11 if [ ! -d "$check_directory" ]; then
12 if [ -e "$check_directory" ]; then
13 echo "$SELF: error: $check_directory exists but is not a directory" >&2
16 echo "$SELF: info: attempting to create $check_directory"
17 mkdir -p "$check_directory" || (echo "$SELF: error: could not create $check_directory" >&2; exit 2)
23 [ -n "$VCSH_DEBUG" ] && echo "$SELF: debug: $1"
27 if [ -n "$VCSH_DEBUG" ] || [ -n "$VCSH_VERBOSE" ]; then echo "$SELF: verbose: $1"; fi
30 # use <repo> Use this repository
32 # exit Exit vcsh mode" >&2
34 echo "usage: $SELF <args>
36 help Display this help
41 <command> Use this repository
43 init <repo> Initialize a new repository
45 [<repo>] Clone from an existing repository
47 <repo> Seed .gitignore.d/<repo> from git ls-files" >&2
53 GIT_DIR="$VCSH_BASE/$REPO_NAME.git"
55 if [ ! -d "$GIT_DIR" ]; then
56 echo E: no repository found for "$REPO_NAME" >&2
61 export GIT_WORK_TREE="$(git config --get core.worktree)"
62 export VCSH_DIRECTORY="$REPO_NAME"
67 verbose "init() begin"
69 echo "$SELF: fatal: $GIT_DIR exists" &&
71 export GIT_WORK_TREE="$HOME"
72 mkdir -p "$GIT_WORK_TREE"
73 cd "$GIT_WORK_TREE" ||
74 (echo "$SELF: fatal: could not enter $GIT_WORK_TREE" &&
78 git config core.worktree "$GIT_WORK_TREE"
79 git config core.excludesfile ".gitignore.d/$REPO_NAME"
80 touch "$HOME/.gitignore.d/$REPO_NAME"
81 git add "$HOME/.gitignore.d/$REPO_NAME"
91 if [ "$1" = 'help' ] || [ "$#" -eq 0 ]; then
96 elif [ "$1" = 'list' ]; then
98 for i in "$VCSH_BASE"/*.git; do
99 echo $(basename "$i" .git)
104 elif [ "$1" = 'run' ]; then
113 #elif [ "$1" = 'use' ]; then
114 # verbose "use begin"
115 # if [ -n "$ZSH_VERSION" ]; then
116 # if [ -o NO_IGNORE_EOF ]; then
117 # export VCSH_NO_IGNORE_EOF=1
125 # bindkey '^d' 'vcsh_exit'
128 # [ -n "$ZSH_VERSION" ] && [ "$USER" = richih ] && buildPS1
132 elif [ "$1" = 'clone' ]; then
133 verbose "clone begin"
136 [ -z "$REPO_NAME" ] && REPO_NAME=$(basename "$GIT_REMOTE" .git)
138 export GIT_DIR="$VCSH_BASE/$REPO_NAME.git"
141 git remote add origin "$GIT_REMOTE"
142 git config branch.master.remote origin
143 git config branch.master.merge refs/heads/master
144 git config core.excludesfile ".gitignore.d/$REPO_NAME"
146 for object in $(git ls-tree -r origin/master | awk '{print $4}'); do
148 echo "$SELF: error: $object exists." &&
151 [ "$VCSH_CONFLICT" = '1' ] &&
152 echo "$SELF: fatal: will stop after fetching and not try to merge!\n" &&
153 echo " Once this situation has been resolved, run 'vcsh run <foo> git pull' to finish cloning.\n" &&
155 git merge origin/master
156 # vcsh use $REPO_NAME
159 elif [ "$1" = 'init' ]; then
161 [ -z $2 ] && help && echo && echo "$SELF $1: error: please specify repository to work on" && return 0
162 export REPO_NAME="$2"
163 export GIT_DIR="$VCSH_BASE/$REPO_NAME.git"
165 # vcsh use "$REPO_NAME"
168 #elif [ "$1" = 'exit' ]; then
169 # verbose "exit begin"
170 # if [ -n "$ZSH_VERSION" ] && [ "$VCSH_NO_IGNORE_EOF" = '1' ]; then
171 # unset VCSH_NO_IGNORE_EOF
172 # setopt NO_IGNORE_EOF
175 # [ -n "$ZSH_VERSION" ] && [ "$USER" = richih ] && buildPS1
179 elif [ "$1" = 'seed-gitignore' ]; then
180 verbose "seed-gitignore begin"
181 [ -z $2 ] && help && echo && echo "$SELF $1: error: please specify repository to work on" && return 0
183 git config core.excludesfile ".gitignore.d/$REPO_NAME"
184 files=$(git ls-files)
185 gitignores=$(for file in $(git ls-files); do
187 echo $file; new="${file%/*}"
188 [ "$file" = "$new" ] && break
191 done | sort -u | sed 's/^/!/')
192 [ -e .gitignore.d/$2 ] &&
193 echo "$SELF: info: .gitignore.d/$2 exists, moving it to .gitignore.d/$2.bak" &&
194 mv -f .gitignore.d/$2 .gitignore.d/$2.bak
195 echo '*' > .gitignore.d/$2
196 for gitignore in $gitignores; do
197 echo $gitignore >> .gitignore.d/$2
201 verbose "defaulting to calling help()"