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"
53 git remote add origin "$GIT_REMOTE"
54 git config branch.master.remote origin
55 git config branch.master.merge refs/heads/master
57 for object in $(git ls-tree -r origin/master | awk '{print $4}'); do
59 error "'$object' exists." &&
62 [ "$VCSH_CONFLICT" = '1' ] &&
63 fatal "will stop after fetching and not try to merge!
64 Once this situation has been resolved, run 'vcsh run $VCSH_REPO_NAME git pull' to finish cloning.\n" 17
65 git merge origin/master
72 info "This operation WILL DETROY DATA!"
74 echo "These files will be deleted:
78 AGAIN, THIS WILL DELETE YOUR DATA!
79 To continue, type \"Yes, do as I say\""
81 [ "x$answer" = "xYes, do as I say" ] || exit 16
82 for file in $files; do
83 rm -f $file || info "could not delete '$file', continuing with deletion"
85 rm -rf "$GIT_DIR" || info "could not delete '$GIT_DIR'"
95 [ ! -e "$GIT_DIR" ] || fatal "'$GIT_DIR' exists" 10
96 export GIT_WORK_TREE="$HOME"
97 mkdir -p "$GIT_WORK_TREE"
98 cd "$GIT_WORK_TREE" || fatal "could not enter '$GIT_WORK_TREE'" 11
104 for i in "$VCSH_BASE"/*.git; do
105 echo $(basename "$i" .git)
111 $VCSH_EXTERNAL_COMMAND
116 # Switching directory as this has to be executed from $HOME to be of any use.
117 # Going back into old directory at the end in case `vcsh use` is reactivated.
120 gitignores=$(for file in $(git ls-files); do
122 echo $file; new="${file%/*}"
123 [ "$file" = "$new" ] && break
127 tempfile=$(mktemp) || fatal "could not create tempfile" 51
128 echo '*' > "$tempfile"
129 for gitignore in $gitignores; do
130 echo "$gitignore" | sed 's/^/!/' >> "$tempfile"
131 [ -d "$gitignore" ] && echo "$gitignore/*" | sed 's/^/!/'>> "$tempfile"
133 diff -N "$tempfile" "$HOME/.gitignore.d/$VCSH_REPO_NAME" > /dev/null &&
136 if [ -e "$HOME/.gitignore.d/$VCSH_REPO_NAME" ]; then
137 info "'$HOME/.gitignore.d/$VCSH_REPO_NAME' differs from new data, moving it to '$HOME/.gitignore.d/$VCSH_REPO_NAME.bak'"
138 mv -f "$HOME/.gitignore.d/$VCSH_REPO_NAME" "$HOME/.gitignore.d/$VCSH_REPO_NAME.bak" ||
139 fatal "could not move '$HOME/.gitignore.d/$VCSH_REPO_NAME' to '$HOME/.gitignore.d/$VCSH_REPO_NAME.bak'" 53
141 mv -f "$tempfile" "$HOME/.gitignore.d/$VCSH_REPO_NAME" ||
142 fatal "could not move '$tempfile' to '$HOME/.gitignore.d/$VCSH_REPO_NAME'" 53
148 git config core.worktree "$GIT_WORK_TREE"
149 git config core.excludesfile ".gitignore.d/$VCSH_REPO_NAME"
150 git config vcsh.vcsh 'true'
151 touch "$HOME/.gitignore.d/$VCSH_REPO_NAME"
152 git add "$HOME/.gitignore.d/$VCSH_REPO_NAME"
156 if [ ! -d "$GIT_DIR" ]; then
157 fatal "no repository found for '$VCSH_REPO_NAME'" 12
159 export GIT_WORK_TREE="$(git config --get core.worktree)"
160 export VCSH_DIRECTORY="$VCSH_REPO_NAME"
163 if [ "$1" = 'clone' ]; then
164 [ -z $2 ] && fatal "$1: please specify a remote" 1
165 export VCSH_COMMAND="$1"
167 [ -n "$3" ] && VCSH_REPO_NAME="$3" || VCSH_REPO_NAME=$(basename "$GIT_REMOTE" .git)
168 export VCSH_REPO_NAME
169 export GIT_DIR="$VCSH_BASE/$VCSH_REPO_NAME.git"
170 elif [ "$1" = 'delete' ] ||
171 [ "$1" = 'enter' ] ||
174 [ "$1" = 'seed-gitignore' ] ||
175 [ "$1" = 'setup' ]; then
176 [ -z $2 ] && fatal "$1: please specify repository to work on" 1
177 [ "$1" = 'run' -a -z "$3" ] && fatal "$1: please specify a command" 1
178 export VCSH_COMMAND="$1"
179 export VCSH_REPO_NAME="$2"
180 export GIT_DIR="$VCSH_BASE/$VCSH_REPO_NAME.git"
181 [ "$VCSH_COMMAND" = 'run' ] && shift 2 && export VCSH_EXTERNAL_COMMAND="$@"
182 [ "$VCSH_COMMAND" = 'seed-gitignore' ] && export VCSH_COMMAND='seed_gitignore'
183 elif [ "$1" = 'list' ]; then
184 export VCSH_COMMAND="$1"
185 elif [ -n "$1" ]; then
186 export VCSH_COMMAND=run
187 export VCSH_REPO_NAME="$1"
188 export GIT_DIR="$VCSH_BASE/$VCSH_REPO_NAME.git"
189 [ -d $GIT_DIR ] || { help; exit 1; }
191 export VCSH_EXTERNAL_COMMAND="git $*"
193 # $1 is empty, or 'help'
197 for check_directory in "$VCSH_BASE" "$HOME/.gitignore.d"
199 if [ ! -d "$check_directory" ]; then
200 if [ -e "$check_directory" ]; then
201 fatal "'$check_directory' exists but is not a directory" 13
203 info "attempting to create '$check_directory'"
204 mkdir -p "$check_directory" || fatal "could not create '$check_directory'" 50
209 verbose "$VCSH_COMMAND begin"
211 verbose "$VCSH_COMMAND end, exiting"