diff --git a/.mailmap b/.mailmap index bf0849747acfe4687d71d559c5a39af6380c690d..1e66b4db2c319380410828aa4a5e91530e4775c3 100644 --- a/.mailmap +++ b/.mailmap @@ -1 +1,2 @@ Richard Hartmann <richih.mailinglist@gmail.com> <richih+github.com@richih.org> +Alexander Skurikhin <a.skurihin@gmail.com> <a.skurihin@gmail.com> diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 76741599431da3da7b45a26a2af09ada3ecd7960..abea9e09c8fa72f4120dd75aa764ac3fcecdb478 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -1,12 +1,15 @@ Alphabetical list of everyone who ever committed to this repository Vincent Demeester <vincent@demeester.fr> +Thomas Ferris Nicolaisen <tfnico@gmail.com> martin f. krafft <madduck@madduck.net> +Alessandro Ghedini <alessandro@ghedini.me> Valentin Haenel <valentin.haenel@gmx.de> Richard Hartmann <richih.mailinglist@gmail.com> mek-apelsin <mek@pels.in> Dieter Plaetinck <dieter@plaetinck.be> Corey Quinn <corey@sequestered.net> Gernot Schulz <post@gernot-schulz.com> +Alexander Skurikhin <a.skurihin@gmail.com> Jonathan Sternberg <jonathansternberg@gmail.com> Frank Terbeck <ft@bewatermyfriend.org> diff --git a/README.md b/README.md index 68031ff877ef0dd23dfb7733e0efbdedd350b421..a83325d979ee4482a828111802d7882a4dbe141c 100644 --- a/README.md +++ b/README.md @@ -56,8 +56,9 @@ Let's say you want to version control your `vim` configuration: vcsh vim commit -m 'Initial commit of my Vim configuration' # optionally push your files to a remote vcsh vim remote add origin <remote> - vcsh vim push origin master:master - vcsh vim branch --track master origin/master + vcsh vim push -u origin master + # from now on you can push additional commits like this + vcsh vim push If all that looks a _lot_ like standard `git`, that's no coincidence; it's a design feature. @@ -365,7 +366,7 @@ ignore this fact for now and follow the examples. ## Initialize a new repository "vim" - vcsh init vcsh + vcsh init vim ## Clone an existing repository diff --git a/_vcsh b/_vcsh index 2367fb44c9f513741ae9776fc62f3c3e0bf952e2..47dbd9e69a9582540c563cfc27c0362fc046d453 100644 --- a/_vcsh +++ b/_vcsh @@ -43,6 +43,14 @@ function _vcsh-list-tracked-by () { (( CURRENT == 2 )) && __vcsh_repositories } +function _vcsh-pull () { + _nothing +} + +function _vcsh-push () { + _nothing +} + function _vcsh-rename () { (( CURRENT == 2 )) && __vcsh_repositories (( CURRENT == 3 )) && _message "new repository name" @@ -88,6 +96,7 @@ function _vcsh () { "list:list all local vcsh repositories" "list-tracked:list all files tracked by vcsh" "list-tracked-by:list files tracked by a repository" + "pull:pull from all vcsh remotes" "rename:rename a repository" "run:run command with <\$GIT_DIR> and <\$GIT_WORK_TREE> set" "upgrade:upgrade repository to currently recommended settings" @@ -114,8 +123,7 @@ function _vcsh () { if ! (( ${+functions[_vcsh-$vcshcommand]} )); then # There is no handler function, so this is probably the name # of a repository. Act accordingly. - _message "git sub-command" - #TODO and now we need to complete on git subcommands + _dispatch git git else curcontext="${curcontext%:*:*}:vcsh-${vcshcommand}:" _call_function ret _vcsh-${vcshcommand} diff --git a/changelog b/changelog index c835962e1bc7345b85f3de5ab8287ea979a73aef..0dd7c3f0314956acda80f724461390dfcf16f36a 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,17 @@ +2013-07-23 Richard Hartmann <richih.mailinglist@gmail.com> + + * Release 1.20130723 + * Support $VCSH_GITIGNORE == none + * Documentation improvements, + * Improved zsh completion + * Add support for `vcsh pull` + * Add support for `vcsh push` + * Add retire() to tear down vcsh ENV + * Add clone hooks, including one witout vcsh ENV to + allow subsequent cloning of other repos + * Fix `vcsh rename` + * Improve general code robustness + 2013-06-14 Richard Hartmann <richih.mailinglist@gmail.com> * Release 1.20130614 diff --git a/doc/hooks b/doc/hooks index 5547131cddc8c625e095bf13789833ac403a7fd6..3c72ef88e336f6eb8f109a6871aa7f2068eee469 100644 --- a/doc/hooks +++ b/doc/hooks @@ -1,9 +1,25 @@ Available hooks are: -pre-command -post-command -pre-enter -post-enter -pre-run -post-run -pre-upgrade -post-upgrade + +* pre-clone +* post-clone +* post-clone-retired + Use this if you need to operate on different git repositories after cloning. + This hook can be useful if your configuration needs some remote + repositories, but you do not want to include it into your vcsh + repository. For instance, if you use vim plugins manager (vundle, + NeoBundle), zsh configuration frameworks (oh-my-zsh, prezto), etc. +* pre-command +* post-command +* pre-enter +* post-enter +* pre-pull +* post-pull +* pre-push +* post-push +* pre-run +* post-run +* pre-upgrade +* post-upgrade + +If you write any interesting or useful hooks, please send them upstream +so they can be included in an examples section. diff --git a/doc/vcsh.1.ronn b/doc/vcsh.1.ronn index 08e8c04a08df4964e64a224714c47f9e02d815ee..b1957078400381993313762d03449e68b1128790 100644 --- a/doc/vcsh.1.ronn +++ b/doc/vcsh.1.ronn @@ -21,6 +21,10 @@ vcsh(1) - Version Control System for $HOME - multiple Git repositories in $HOME `vcsh` list-tracked-by <repo> +`vcsh` pull + +`vcsh` push + `vcsh` rename <repo> <newname> `vcsh` run <repo> <shell command> @@ -77,6 +81,9 @@ an interactive user. * clone: Clone an existing repository. + If you need to clone a bundle of repositories, look into the + `post-clone-retired` hook. + * delete: Delete an existing repository. @@ -98,6 +105,12 @@ an interactive user. * list-tracked-by: List files tracked by a repository. +* pull: + Pull from all vcsh remotes. + +* push: + Push to all vcsh remotes. + * rename: Rename a repository. @@ -151,14 +164,16 @@ executed in the context of your shell. Interesting knobs you can turn: * <$VCSH_GITIGNORE>: - Can be either <exact> or <recursive>. + Can be <exact>, <recursive>, or <none>. - <exact> will seed the repo-specific <.gitignore> with all file and directory + <exact> will seed the repo-specific ignore file with all file and directory names which `git ls-files` returns. <recursive> will descend through all directories recursively additionally to the above. + <none> will not write any ignore file. + Defaults to <exact>. Less interesting knobs you could turn: @@ -259,7 +274,7 @@ This manpage and `vcsh` itself were written by Richard "RichiH" Hartmann. ## COPYRIGHT -Copyright 2011-2012 Richard Hartmann <richih.mailinglist@gmail.com> +Copyright 2011-2013 Richard Hartmann <richih.mailinglist@gmail.com> Licensed under the GNU GPL version 2 or higher. diff --git a/vcsh b/vcsh index 71789fa6572a327832df49e390209b394e5793cc..ea889318796f40217aff83f34941ceaf233025a2 100755 --- a/vcsh +++ b/vcsh @@ -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 @@ basename() { } SELF=$(basename $0) -VERSION='1.20130614' +VERSION='1.20130723' fatal() { echo "$SELF: fatal: $1" >&2 @@ -100,6 +100,8 @@ help() { list-tracked List all files tracked by vcsh list-tracked-by \\ <repo> List files tracked by a repository + pull Pull from all vcsh remotes + push Push to vcsh remotes rename <repo> \\ <newname> Rename repository run <repo> \\ @@ -131,6 +133,7 @@ info() { } clone() { + hook pre-clone init git remote add origin "$GIT_REMOTE" git config branch.master.remote origin @@ -149,6 +152,9 @@ clone() { fatal "will stop after fetching and not try to merge! 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 } delete() { @@ -220,11 +226,44 @@ list_tracked_by() { git ls-files | sort -u } +pull() { + hook pre-pull + for VCSH_REPO_NAME in $(list); do + echo -n "$VCSH_REPO_NAME: " + export GIT_DIR="$VCSH_REPO_D/$VCSH_REPO_NAME.git" + use + git pull + done + hook post-pull +} + +push() { + hook pre-push + for VCSH_REPO_NAME in $(list); do + echo -n "$VCSH_REPO_NAME: " + export GIT_DIR="$VCSH_REPO_D/$VCSH_REPO_NAME.git" + use + git push + 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() { @@ -238,7 +277,7 @@ 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 @@ -259,6 +298,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 @@ -272,7 +317,7 @@ write_gitignore() { 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 @@ -289,8 +334,8 @@ write_gitignore() { 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 @@ -318,15 +363,17 @@ 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' ] || - [ "$1" = 'list-tracked' ]; then + [ "$1" = 'list-tracked' ] || + [ "$1" = 'pull' ] || + [ "$1" = 'push' ]; then export VCSH_COMMAND="$1" elif [ -n "$2" ]; then export VCSH_COMMAND='run' @@ -352,9 +399,8 @@ if echo $VCSH_REPO_NAME | grep -q '/'; then 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 @@ -363,7 +409,10 @@ do 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')