From: Richard Hartmann Date: Wed, 31 Jul 2013 22:19:02 +0000 (+0200) Subject: Merge branch 'feature--vcsh-commit' X-Git-Url: https://git.madduck.net/code/vcsh.git/commitdiff_plain/67b0da790e240f714bdd1c4256957c3261d5533a?ds=inline;hp=-c Merge branch 'feature--vcsh-commit' Conflicts: doc/vcsh.1.ronn vcsh --- 67b0da790e240f714bdd1c4256957c3261d5533a diff --combined doc/vcsh.1.ronn index 9532e65,b7f9725..01cadb5 --- a/doc/vcsh.1.ronn +++ b/doc/vcsh.1.ronn @@@ -29,8 -29,6 +29,8 @@@ vcsh(1) - Version Control System for $H `vcsh` run +`vcsh` status + `vcsh` upgrade `vcsh` version @@@ -83,9 -81,9 +83,12 @@@ an interactive user * clone: Clone an existing repository. + If you need to clone a bundle of repositories, look into the + `post-clone-retired` hook. + + * commit: + Commit in all repositories + * delete: Delete an existing repository. @@@ -127,9 -125,6 +130,9 @@@ This is needed to support mr and other scripts properly and of no concern to an interactive user. +* status: + Show statuses of all vcsh repositories. + * upgrade: Upgrade repository to currently recommended settings. @@@ -169,13 -164,11 +172,13 @@@ executed in the context of your shell Interesting knobs you can turn: * <$VCSH_GITIGNORE>: - Can be either or . + Can be , , or . - will seed the repo-specific <.gitignore> with all file and directory + will seed the repo-specific ignore file with all file and directory names which `git ls-files` returns. + will not write any ignore file. + will descend through all directories recursively additionally to the above. diff --combined vcsh index f2bbd7a,1918af4..85e20d8 --- a/vcsh +++ b/vcsh @@@ -8,7 -8,7 +8,7 @@@ # While the following is not legally binding, the author would like to # explain the choice of GPLv2+ over GPLv3+. # The author prefers GPLv3+ over GPLv2+ but feels it's better to maintain -# full compatibility's with git. In case git ever changes its licensing terms, +# full compatibility's with Git. In case Git ever changes its licensing terms, # which is admittedly extremely unlikely to the point of being impossible, # this software will most likely follow suit. @@@ -24,7 -24,7 +24,7 @@@ basename() } SELF=$(basename $0) -VERSION='1.20130614' +VERSION='1.20130724' fatal() { echo "$SELF: fatal: $1" >&2 @@@ -92,6 -92,7 +92,7 @@@ help() commands: clone \\ [] Clone from an existing repository + commit Commit in all repositories delete Delete an existing repository enter Enter repository; spawn new instance of \$SHELL help Display this help text @@@ -106,7 -107,6 +107,7 @@@ Rename repository run \\ Use this repository + status Show statuses of all vcsh repositories upgrade Upgrade repository to currently recommended settings version Print version information which Find substring in name of any tracked file @@@ -154,10 -154,20 +155,22 @@@ clone() Once this situation has been resolved, run 'vcsh run $VCSH_REPO_NAME git pull' to finish cloning.\n" 17 git merge origin/master hook post-clone + retire + hook post-clone-retired } + commit() { + hook pre-commit + for VCSH_REPO_NAME in $(list); do + echo "$VCSH_REPO_NAME: " + export GIT_DIR="$VCSH_REPO_D/$VCSH_REPO_NAME.git" + use + git commit --untracked-files=no --quiet + echo + done + hook post-commit + } + delete() { cd "$VCSH_BASE" || fatal "could not enter '$VCSH_BASE'" 11 use @@@ -234,7 -244,6 +247,7 @@@ pull() export GIT_DIR="$VCSH_REPO_D/$VCSH_REPO_NAME.git" use git pull + echo done hook post-pull } @@@ -246,27 -255,15 +259,27 @@@ push() export GIT_DIR="$VCSH_REPO_D/$VCSH_REPO_NAME.git" use git push + echo done hook post-push } +retire() { + unset GIT_WORK_TREE + unset VCSH_DIRECTORY +} + rename() { git_dir_exists [ -d "$GIT_DIR_NEW" ] && fatal "'$GIT_DIR_NEW' exists" 54 mv -f "$GIT_DIR" "$GIT_DIR_NEW" || fatal "Could not mv '$GIT_DIR' '$GIT_DIR_NEW'" 52 + # Now that the repository has been renamed, we need to fix up its configuration + # Overwrite old name.. + GIT_DIR="$GIT_DIR_NEW" + $VCSH_REPO_NAME="$VCSH_REPO_NAME_NEW" + # ..and clobber all old configuration + upgrade } run() { @@@ -276,21 -273,11 +289,21 @@@ hook post-run } +status() { + for VCSH_REPO_NAME in $(list); do + echo "$VCSH_REPO_NAME:" + export GIT_DIR="$VCSH_REPO_D/$VCSH_REPO_NAME.git" + use + git status --short --untracked-files='no' + echo + done +} + upgrade() { hook pre-upgrade use git config core.worktree "$GIT_WORK_TREE" - git config core.excludesfile ".gitignore.d/$VCSH_REPO_NAME" + [ ! "x$VCSH_GITIGNORE" = 'xnone' ] && git config core.excludesfile ".gitignore.d/$VCSH_REPO_NAME" git config vcsh.vcsh 'true' [ -e "$VCSH_BASE/.gitignore.d/$VCSH_REPO_NAME" ] && git add -f "$VCSH_BASE/.gitignore.d/$VCSH_REPO_NAME" hook post-upgrade @@@ -311,12 -298,6 +324,12 @@@ which() } write_gitignore() { + # Don't do anything if the user does not want to write gitignore + if [ "x$VCSH_GITIGNORE" = 'xnone' ]; then + info "Not writing gitignore as '\$VCSH_GITIGNORE' is set to 'none'" + exit + fi + use cd "$VCSH_BASE" || fatal "could not enter '$VCSH_BASE'" 11 gitignores=$(for file in $(git ls-files); do @@@ -330,7 -311,7 +343,7 @@@ echo '*' > "$tempfile" || fatal "could not write to '$tempfile'" 57 for gitignore in $gitignores; do echo "$gitignore" | sed 's@^@!/@' >> "$tempfile" || fatal "could not write to '$tempfile'" 57 - if [ x$VCSH_GITIGNORE = x'recursive' ] && [ -d "$gitignore" ]; then + if [ "x$VCSH_GITIGNORE" = 'xrecursive' ] && [ -d "$gitignore" ]; then { echo "$gitignore/*" | sed 's@^@!/@' >> "$tempfile" || fatal "could not write to '$tempfile'" 57; } fi done @@@ -347,8 -328,8 +360,8 @@@ fatal "could not move '$tempfile' to '$VCSH_BASE/.gitignore.d/$VCSH_REPO_NAME'" 53 } -if [ ! "x$VCSH_GITIGNORE" = 'xexact' ] && [ ! "x$VCSH_GITIGNORE" = 'xrecursive' ]; then - fatal "'\$VCSH_GITIGNORE' must be either 'exact' or 'recursive'" 1 +if [ ! "x$VCSH_GITIGNORE" = 'xexact' ] && [ ! "x$VCSH_GITIGNORE" = 'xnone' ] && [ ! "x$VCSH_GITIGNORE" = 'xrecursive' ]; then + fatal "'\$VCSH_GITIGNORE' must equal 'exact', 'none', or 'recursive'" 1 fi if [ "$1" = 'clone' ]; then @@@ -376,18 -357,18 +389,19 @@@ elif [ "$1" = 'delete' ] | [ "$1" = 'write-gitignore' ]; then [ -z $2 ] && fatal "$1: please specify repository to work on" 1 [ "$1" = 'rename' -a -z "$3" ] && fatal "$1: please specify a target name" 1 - [ "$1" = 'run' -a -z "$3" ] && fatal "$1: please specify a command" 1 + [ "$1" = 'run' -a -z "$3" ] && fatal "$1: please specify a command" 1 export VCSH_COMMAND="$1" export VCSH_REPO_NAME="$2" export GIT_DIR="$VCSH_REPO_D/$VCSH_REPO_NAME.git" - [ "$VCSH_COMMAND" = 'rename' ] && export GIT_DIR_NEW="$VCSH_REPO_D/$3.git" - [ "$VCSH_COMMAND" = 'run' ] && shift 2 - [ "$VCSH_COMMAND" = 'write-gitignore' ] + [ "$VCSH_COMMAND" = 'rename' ] && { export VCSH_REPO_NAME_NEW="$3"; + export GIT_DIR_NEW="$VCSH_REPO_D/$VCSH_REPO_NAME_NEW.git"; } + [ "$VCSH_COMMAND" = 'run' ] && shift 2 - elif [ "$1" = 'list' ] || + elif [ "$1" = 'commit' ] || + [ "$1" = 'list' ] || [ "$1" = 'list-tracked' ] || [ "$1" = 'pull' ] || - [ "$1" = 'push' ]; then + [ "$1" = 'push' ] || + [ "$1" = 'status' ]; then export VCSH_COMMAND="$1" elif [ -n "$2" ]; then export VCSH_COMMAND='run' @@@ -413,8 -394,9 +427,8 @@@ if echo $VCSH_REPO_NAME | grep -q '/'; export VCSH_REPO_NAME=$(basename "$VCSH_REPO_NAME" .git) fi - -for check_directory in "$VCSH_REPO_D" "$VCSH_BASE/.gitignore.d" -do +check_dir() { + check_directory="$1" if [ ! -d "$check_directory" ]; then if [ -e "$check_directory" ]; then fatal "'$check_directory' exists but is not a directory" 13 @@@ -423,10 -405,7 +437,10 @@@ mkdir -p "$check_directory" || fatal "could not create '$check_directory'" 50 fi fi -done +} + +check_dir "$VCSH_REPO_D" +[ ! "x$VCSH_GITIGNORE" = 'xnone' ] && check_dir "$VCSH_BASE/.gitignore.d" verbose "$VCSH_COMMAND begin" export VCSH_COMMAND=$(echo $VCSH_COMMAND | sed 's/-/_/g')