From: Richard Hartmann Date: Mon, 13 Feb 2012 01:02:23 +0000 (+0100) Subject: Merge branch 'hook-support' X-Git-Url: https://git.madduck.net/code/vcsh.git/commitdiff_plain/189cb6bd1558c7cb4aabd9fa05624e44ce0afa3d?hp=bd783af3498a856d27eb0aa616dd09f6b2215fda Merge branch 'hook-support' --- diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 0000000..5e52a9d --- /dev/null +++ b/AUTHORS @@ -0,0 +1,8 @@ +Alphabetical list of everyone who ever committed to this repository + +Vincent Demeester +Richard Hartmann +Richard Hartmann +Dieter Plaetinck +Corey Quinn +Gernot Schulz diff --git a/Makefile b/Makefile index 341da78..7c04077 100644 --- a/Makefile +++ b/Makefile @@ -12,6 +12,7 @@ install: all install -m 0644 $(manpages) $(DESTDIR)$(PREFIX)/share/man/man1 install -d $(DESTDIR)$(PREFIX)/share/doc/vcsh install -m 0644 README.md $(DESTDIR)$(PREFIX)/share/doc/vcsh + install -m 0644 doc/hooks $(DESTDIR)$(PREFIX)/share/doc/vcsh install -d $(DESTDIR)$(PREFIX)/share/zsh/vendor-completions install -m 0644 _vcsh $(DESTDIR)$(PREFIX)/share/zsh/vendor-completions diff --git a/README.md b/README.md index bdc26bf..c0585d2 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ community around the general idea of version controlling your (digital) life. * IRC: #vcs-home on irc.oftc.net -* Mailing list: vcs-home@lists.madduck.net +* Mailing list: http://lists.madduck.net/listinfo/vcs-home * Pull requests or issues on https://github.com/RichiH/vcsh @@ -98,7 +98,7 @@ To illustrate, this is what a possible directory structure looks like. ### available.d ### -The files you see in $XDG_CONFIG_HOME/mr/available.d are mr configuration files +The files you see in $XDG\_CONFIG\_HOME/mr/available.d are mr configuration files that contain the commands to manage (checkout, update etc.) a single repository. vcsh repo configs end in .vcsh, git configs end in .git, etc. This is optional and your preference. For example, this is what a zsh.vcsh @@ -116,7 +116,7 @@ this repository and fork your own. ### config.d ### -$XDG_CONFIG_HOME/mr/available.d contains *all available* repositories. Only +$XDG\_CONFIG\_HOME/mr/available.d contains *all available* repositories. Only files/links present in mr/config.d, however, will be used by mr. That means that in this example, only the zsh, gitconfigs, tmux and vim repositories will be checked out. A simple `mr update` run in $HOME will clone or update those @@ -130,11 +130,13 @@ this: [DEFAULT] jobs = 5 - include = cat $XDG_CONFIG_HOME/mr/config.d/* + # Use if your mr does not have vcsh support in mainline, yet + include = cat /usr/share/mr/vcsh + include = cat ${XDG_CONFIG_HOME:-$HOME/.config}/mr/config.d/* ### repo.d ### -$XDG_CONFIG_HOME/vcsh/repo.d is the directory where all git repositories which +$XDG\_CONFIG\_HOME/vcsh/repo.d is the directory where all git repositories which are under vcsh's control are located. Since their working trees are configured to be in $HOME, the files contained in those repositories will be put in $HOME directly. @@ -152,11 +154,13 @@ To illustrate further, the following steps could move your desired configuration to a new host. 1. Clone the mr repository (containing available.d, config.d etc.); for - example: `vcsh clone git://github.com/RichiH/vcsh_mr_template.git` + example: `vcsh clone git://github.com/RichiH/vcsh_mr_template.git mr` 2. Choose your repositories by linking them in config.d (or go with the default you may have already configured by adding symlinks to git). -3. Run mr to clone the repositories: `cd; mr update`. -4. Done. +3. Make sure the line 'include = cat /usr/share/mr/vcsh' in .mrconfig points + to an existing file +4. Run mr to clone the repositories: `cd; mr update`. +5. Done. Hopefully the above could help explain how this approach saves time by @@ -183,10 +187,10 @@ Make sure none of the following files and directories exist for your test * ~/.gitignore.d * ~/.mrconfig -* $XDG_CONFIG_HOME/mr/available.d/mr.vcsh -* $XDG_CONFIG_HOME/mr/available.d/zsh.vcsh -* $XDG_CONFIG_HOME/mr/config.d/mr.vcsh -* $XDG_CONFIG_HOME/vcsh/repo.d/mr.git/ +* $XDG\_CONFIG\_HOME/mr/available.d/mr.vcsh +* $XDG\_CONFIG\_HOME/mr/available.d/zsh.vcsh +* $XDG\_CONFIG\_HOME/mr/config.d/mr.vcsh +* $XDG\_CONFIG\_HOME/vcsh/repo.d/mr.git/ All of the files are part of the template repository, the directory is where the template will be stored. @@ -195,13 +199,15 @@ the template will be stored. #### 4.1.2 Clone the Template #### + cd $HOME mkdir -p ~/work/git - cd !$ git clone git://github.com/RichiH/vcsh.git vcsh + # make sure 'include = cat /usr/share/mr/vcsh' points to an exiting file + vim .mrconfig cd vcsh - ln -s vcsh /usr/local/bin # or add it to your PATH + ln -s vcsh /usr/local/bin # or add it to your PATH cd - vcsh clone git://github.com/RichiH/vcsh_mr_template.git mr.vcsh + vcsh clone git://github.com/RichiH/vcsh_mr_template.git mr #### 4.1.3 Enable Your Test Repository #### @@ -236,7 +242,9 @@ Done! You're welcome to clone the example repository: - vcsh clone git://github.com/RichiH/vcsh_mr_template.git + vcsh clone git://github.com/RichiH/vcsh_mr_template.git mr + # make sure 'include = cat /usr/share/mr/vcsh' points to an exiting file + vim .mrconfig Look around in the clone. It should be reasonably simple to understand. If not, poke me, RichiH, on Freenode (query) or OFTC (#vcs-home). @@ -267,6 +275,8 @@ mr is used to actually retrieve configs, etc ~ % cat ~/.mrconfig [DEFAULT] + # adapt /usr/share/mr/vcsh to your system if needed + include = cat /usr/share/mr/vcsh include = cat $XDG_CONFIG_HOME/mr/config.d/* ~ % echo $XDG_CONFIG_HOME /home/richih/.config diff --git a/TODO b/TODO deleted file mode 100644 index 40cea66..0000000 --- a/TODO +++ /dev/null @@ -1,3 +0,0 @@ -# Undecided # - -* Have an aborted vcsh clone delete the repo it tried to clone? diff --git a/doc/hooks b/doc/hooks new file mode 100644 index 0000000..199123f --- /dev/null +++ b/doc/hooks @@ -0,0 +1,7 @@ +Available hooks are: +pre-enter +post-enter +pre-run +post-run +pre-setup +post-setup diff --git a/doc/vcsh.1.ronn b/doc/vcsh.1.ronn index bcea71c..cc66e07 100644 --- a/doc/vcsh.1.ronn +++ b/doc/vcsh.1.ronn @@ -25,6 +25,8 @@ vcsh(1) - manage config files in $HOME via fake bare git repositories `vcsh` setup +`vcsh` which + `vcsh` write-gitignore `vcsh` @@ -48,7 +50,8 @@ The use of symlinks is not needed in this setup, making for a cleaner setup. vcsh. That being said, you can easily use `vcsh` without `mr` if you prefer. A sample configuration for `vcsh` and `mr` can be found at -*https://github.com/RichiH/vcsh_mr_template* +*https://github.com/RichiH/vcsh_mr_template* and used with `vcsh clone +https://github.com/RichiH/vcsh_mr_template mr`. Please note that you can always use a path instead of a name for . This is needed to support mr and other scripts properly and of no concern to @@ -97,11 +100,14 @@ an interactive user. * setup: Set up repository with recommended settings. +* which : + Find in name of any tracked file. + * write-gitignore: Write .gitignore.d/ via git ls-files. * : - Shortcut to run `vcsh` on a repo. Will prepend `git` to by itself. + Shortcut to run `vcsh` on a repo. Will prepend `git` to . * : Shortcut to run `vcsh enter `. @@ -118,17 +124,21 @@ placed in <$XDG_CONFIG_HOME/vcsh/hooks-available>. From there, they can be soft-linked into <$XDG_CONFIG_HOME/vcsh/hooks-enabled>; `vcsh` will only execute hooks that are in this directory. -Hooks follow a simple format. `pre-run` will be run before anything is run. +Hooks follow a simple format. will be run before anything is run. If you want to have more than one script for a certain hook, just append -any kind of string to order them. A system of `pre-run`, `pre-run.10`, -`pre-run.20` etc is suggested; other options would be `pre-run-10` or -`pre-run.sh`. A dot after the hook name is optional. +any kind of string to order them. A system of , , + etc is suggested; other options would be or +. A dot after the hook name is optional. -If you want to create hooks for a specific `vcsh` repository, simply prepend -the repository's name, followed by a dot, i.e. `zsh.pre-run`. Otherwise, the +If you want to create hooks for a specific repository, simply prepend +the repository's name, followed by a dot, i.e. . Otherwise, the same rules as above apply. The dot between the repository's name and the hook is mandatory, though. +Available hooks are , , , , +, and . If you need more, vcsh is trivial to patch, +but please let upstream know so we can ship them by default. + ## DETAILED HOWTO AND FURTHER READING Man pages are intended to be short and thus often useless to glean best @@ -168,7 +178,7 @@ This manpage and `vcsh` itself were written by Richard "RichiH" Hartmann. ## COPYRIGHT -Copyright 2011 Richard Hartmann +Copyright 2011-2012 Richard Hartmann Licensed under the GNU GPL version 3 or higher. diff --git a/tools/list_AUTHORS b/tools/list_AUTHORS new file mode 100755 index 0000000..2b91ac9 --- /dev/null +++ b/tools/list_AUTHORS @@ -0,0 +1,5 @@ +#!/bin/sh + +echo 'Alphabetical list of everyone who ever committed to this repository +' +git log --all --format='%an <%ae>' | sort -u -k2 diff --git a/vcsh b/vcsh index f922cea..ba0049e 100755 --- a/vcsh +++ b/vcsh @@ -1,7 +1,7 @@ #!/bin/sh # This program is licensed under the GNU GPL version 2 or later. -# (c) Richard "RichiH" Hartmann , 2011 +# (c) Richard "RichiH" Hartmann , 2011-2012 # For details, see LICENSE. To submit patches, you have to agree to # license your code under the GNU GPL version 2 or later. @@ -35,6 +35,7 @@ help() { run \\ Use this repository setup Set up repository with recommended settings + which Find substring in name of any tracked file write-gitignore \\ Write .gitignore.d/ via git ls-files @@ -94,13 +95,13 @@ delete() { $files AGAIN, THIS WILL DELETE YOUR DATA! -To continue, type \"Yes, do as I say\"" +To continue, type 'Yes, do as I say'" read answer - [ "x$answer" = "xYes, do as I say" ] || exit 16 + [ "x$answer" = 'xYes, do as I say' ] || exit 16 for file in $files; do rm -f $file || info "could not delete '$file', continuing with deletion" done - rmdir "$GIT_DIR" || error "could not delete '$GIT_DIR'" + rm -r "$GIT_DIR" || error "could not delete '$GIT_DIR'" } enter() { @@ -117,6 +118,7 @@ git_dir_exists() { hook() { for hook in $VCSH_HOOK_D/$1* $VCSH_HOOK_D/$VCSH_REPO_NAME.$1*; do [ -x "$hook" ] || continue + info "executing '$hook'" "$hook" done } @@ -182,6 +184,14 @@ use() { export VCSH_DIRECTORY="$VCSH_REPO_NAME" } +which() { + for VCSH_REPO_NAME in $(list); do + for VCSH_FILE in $(get_files); do + echo $VCSH_FILE | grep -q "$VCSH_COMMAND_PARAMETER" && echo "$VCSH_REPO_NAME: $VCSH_FILE" + done + done | sort -u +} + write_gitignore() { use cd "$VCSH_BASE" || fatal "could not enter '$VCSH_BASE'" 11 @@ -213,24 +223,29 @@ write_gitignore() { fatal "could not move '$tempfile' to '$VCSH_BASE/.gitignore.d/$VCSH_REPO_NAME'" 53 } -if [ ! x$VCSH_GITIGNORE = x'exact' ] && [ ! x$VCSH_GITIGNORE = x'recursive' ]; then - fatal "\$VCSH_GITIGNORE must be either 'exact' or 'recursive'" 1 +if [ ! "x$VCSH_GITIGNORE" = 'xexact' ] && [ ! "x$VCSH_GITIGNORE" = 'xrecursive' ]; then + fatal "'\$VCSH_GITIGNORE' must be either 'exact' or 'recursive'" 1 fi if [ "$1" = 'clone' ]; then - [ -z $2 ] && fatal "$1: please specify a remote" 1 + [ -z "$2" ] && fatal "$1: please specify a remote" 1 export VCSH_COMMAND="$1" GIT_REMOTE="$2" [ -n "$3" ] && VCSH_REPO_NAME="$3" || VCSH_REPO_NAME=$(basename "$GIT_REMOTE" .git) export VCSH_REPO_NAME export GIT_DIR="$VCSH_REPO_D/$VCSH_REPO_NAME.git" -elif [ "$1" = 'delete' ] || - [ "$1" = 'enter' ] || - [ "$1" = 'init' ] || - [ "$1" = 'list-tracked-by' ] || - [ "$1" = 'rename' ] || - [ "$1" = 'run' ] || - [ "$1" = 'setup' ] || +elif [ "$1" = 'which' ]; then + [ -z "$2" ] && fatal "$1: please specify a filename" 1 + [ -n "$3" ] && fatal "$1: too many parameters" 1 + export VCSH_COMMAND="$1" + export VCSH_COMMAND_PARAMETER="$2" +elif [ "$1" = 'delete' ] || + [ "$1" = 'enter' ] || + [ "$1" = 'init' ] || + [ "$1" = 'list-tracked-by' ] || + [ "$1" = 'rename' ] || + [ "$1" = 'run' ] || + [ "$1" = 'setup' ] || [ "$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 @@ -265,7 +280,7 @@ fi # Mangle the input to fit normal operation. if echo $VCSH_REPO_NAME | grep -q '/'; then export GIT_DIR=$VCSH_REPO_NAME - export VCSH_REPO_NAME=$(basename $VCSH_REPO_NAME .git) + export VCSH_REPO_NAME=$(basename "$VCSH_REPO_NAME" .git) fi