]> git.madduck.net Git - code/vcsh.git/blobdiff - vcsh

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

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.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Update manpage
[code/vcsh.git] / vcsh
diff --git a/vcsh b/vcsh
index 5d5628e236368e7d11addeedc57c60c8f87fa8a6..4761a5340a6d392b8f3f8feacbf07b886a620d7c 100755 (executable)
--- a/vcsh
+++ b/vcsh
@@ -74,9 +74,10 @@ fi
 
 # Read defaults
 : ${VCSH_REPO_D:=$XDG_CONFIG_HOME/vcsh/repo.d}
 
 # Read defaults
 : ${VCSH_REPO_D:=$XDG_CONFIG_HOME/vcsh/repo.d}
-: ${VCSH_HOOK_D:=$XDH_CONFIG_HOME/vcsh/hooks-enabled}
+: ${VCSH_HOOK_D:=$XDG_CONFIG_HOME/vcsh/hooks-enabled}
 : ${VCSH_BASE:=$HOME}
 : ${VCSH_GITIGNORE:=exact}
 : ${VCSH_BASE:=$HOME}
 : ${VCSH_GITIGNORE:=exact}
+: ${VCSH_GITATTRIBUTES:=none}
 : ${VCSH_WORKTREE:=absolute}
 
 if [ ! "x$VCSH_GITIGNORE" = 'xexact' ] && [ ! "x$VCSH_GITIGNORE" = 'xnone' ] && [ ! "x$VCSH_GITIGNORE" = 'xrecursive' ]; then
 : ${VCSH_WORKTREE:=absolute}
 
 if [ ! "x$VCSH_GITIGNORE" = 'xexact' ] && [ ! "x$VCSH_GITIGNORE" = 'xnone' ] && [ ! "x$VCSH_GITIGNORE" = 'xrecursive' ]; then
@@ -152,15 +153,17 @@ clone() {
                exit
        fi
        git fetch
                exit
        fi
        git fetch
-       for object in $(git ls-tree -r origin/master | awk '{print $4}'); do
+       hook pre-merge
+       git ls-tree -r --name-only origin/master | (while read object; do
                [ -e "$object" ] &&
                        error "'$object' exists." &&
                        VCSH_CONFLICT=1
        done
                [ -e "$object" ] &&
                        error "'$object' exists." &&
                        VCSH_CONFLICT=1
        done
-       [ "$VCSH_CONFLICT" = '1' ] &&
+       [ "$VCSH_CONFLICT" = '1' ]) &&
                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." 17
        git merge origin/master
                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." 17
        git merge origin/master
+       hook post-merge
        hook post-clone
        retire
        hook post-clone-retired
        hook post-clone
        retire
        hook post-clone-retired
@@ -173,6 +176,7 @@ commit() {
                export GIT_DIR="$VCSH_REPO_D/$VCSH_REPO_NAME.git"
                use
                git commit --untracked-files=no --quiet
                export GIT_DIR="$VCSH_REPO_D/$VCSH_REPO_NAME.git"
                use
                git commit --untracked-files=no --quiet
+               VCSH_COMMAND_RETURN_CODE=$?
                echo
        done
        hook post-commit
                echo
        done
        hook post-commit
@@ -221,7 +225,7 @@ init() {
        [ ! -e "$GIT_DIR" ] || fatal "'$GIT_DIR' exists" 10
        mkdir -p "$VCSH_BASE" || fatal "could not create '$VCSH_BASE'" 50
        cd "$VCSH_BASE" || fatal "could not enter '$VCSH_BASE'" 11
        [ ! -e "$GIT_DIR" ] || fatal "'$GIT_DIR' exists" 10
        mkdir -p "$VCSH_BASE" || fatal "could not create '$VCSH_BASE'" 50
        cd "$VCSH_BASE" || fatal "could not enter '$VCSH_BASE'" 11
-       git init
+       git init --shared=0600
        upgrade
        hook post-init
 }
        upgrade
        hook post-init
 }
@@ -255,6 +259,7 @@ pull() {
                export GIT_DIR="$VCSH_REPO_D/$VCSH_REPO_NAME.git"
                use
                git pull
                export GIT_DIR="$VCSH_REPO_D/$VCSH_REPO_NAME.git"
                use
                git pull
+               VCSH_COMMAND_RETURN_CODE=$?
                echo
        done
        hook post-pull
                echo
        done
        hook post-pull
@@ -267,6 +272,7 @@ push() {
                export GIT_DIR="$VCSH_REPO_D/$VCSH_REPO_NAME.git"
                use
                git push
                export GIT_DIR="$VCSH_REPO_D/$VCSH_REPO_NAME.git"
                use
                git push
+               VCSH_COMMAND_RETURN_CODE=$?
                echo
        done
        hook post-push
                echo
        done
        hook post-push
@@ -293,6 +299,7 @@ run() {
        hook pre-run
        use
        "$@"
        hook pre-run
        use
        "$@"
+       VCSH_COMMAND_RETURN_CODE=$?
        hook post-run
 }
 
        hook post-run
 }
 
@@ -301,12 +308,14 @@ status() {
                export GIT_DIR="$VCSH_REPO_D/$VCSH_REPO_NAME.git"
                use
                git status --short --untracked-files='no'
                export GIT_DIR="$VCSH_REPO_D/$VCSH_REPO_NAME.git"
                use
                git status --short --untracked-files='no'
+               VCSH_COMMAND_RETURN_CODE=$?
        else
                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'
        else
                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'
+                       VCSH_COMMAND_RETURN_CODE=$?
                        echo
                done
        fi
                        echo
                done
        fi
@@ -326,9 +335,11 @@ upgrade() {
                git config core.worktree "$VCSH_BASE"
        fi
        [ ! "x$VCSH_GITIGNORE" = 'xnone' ] && git config core.excludesfile ".gitignore.d/$VCSH_REPO_NAME"
                git config core.worktree "$VCSH_BASE"
        fi
        [ ! "x$VCSH_GITIGNORE" = 'xnone' ] && git config core.excludesfile ".gitignore.d/$VCSH_REPO_NAME"
-       git config vcsh.vcsh         'true'
+       [ ! "x$VCSH_GITATTRIBUTES" = 'xnone' ] && git config core.attributesfile ".gitattributes.d/$VCSH_REPO_NAME"
+       git config vcsh.vcsh 'true'
        use
        [ -e "$VCSH_BASE/.gitignore.d/$VCSH_REPO_NAME" ] && git add -f "$VCSH_BASE/.gitignore.d/$VCSH_REPO_NAME"
        use
        [ -e "$VCSH_BASE/.gitignore.d/$VCSH_REPO_NAME" ] && git add -f "$VCSH_BASE/.gitignore.d/$VCSH_REPO_NAME"
+       [ -e "$VCSH_BASE/.gitattributes.d/$VCSH_REPO_NAME" ] && git add -f "$VCSH_BASE/.gitattributes.d/$VCSH_REPO_NAME"
        hook post-upgrade
 }
 
        hook post-upgrade
 }
 
@@ -354,6 +365,8 @@ write_gitignore() {
 
        use
        cd "$VCSH_BASE" || fatal "could not enter '$VCSH_BASE'" 11
 
        use
        cd "$VCSH_BASE" || fatal "could not enter '$VCSH_BASE'" 11
+       OLDIFS="$IFS"
+       IFS=$(printf '\n\t')
        gitignores=$(for file in $(git ls-files); do
                while true; do
                        echo $file; new="${file%/*}"
        gitignores=$(for file in $(git ls-files); do
                while true; do
                        echo $file; new="${file%/*}"
@@ -374,6 +387,7 @@ write_gitignore() {
                        { echo "$gitignore/*" | sed 's@^@!/@' >> "$tempfile" || fatal "could not write to '$tempfile'" 57; }
                fi
        done
                        { echo "$gitignore/*" | sed 's@^@!/@' >> "$tempfile" || fatal "could not write to '$tempfile'" 57; }
                fi
        done
+       IFS="$OLDIFS"
        if diff -N "$tempfile" "$VCSH_BASE/.gitignore.d/$VCSH_REPO_NAME" > /dev/null; then
                rm -f "$tempfile" || error "could not delete '$tempfile'"
                exit
        if diff -N "$tempfile" "$VCSH_BASE/.gitignore.d/$VCSH_REPO_NAME" > /dev/null; then
                rm -f "$tempfile" || error "could not delete '$tempfile'"
                exit
@@ -387,7 +401,7 @@ write_gitignore() {
                fatal "could not move '$tempfile' to '$VCSH_BASE/.gitignore.d/$VCSH_REPO_NAME'" 53
 }
 
                fatal "could not move '$tempfile' to '$VCSH_BASE/.gitignore.d/$VCSH_REPO_NAME'" 53
 }
 
-debug `git version`
+debug $(git version)
 
 if [ ! "x$VCSH_GITIGNORE" = 'xexact' ] && [ ! "x$VCSH_GITIGNORE" = 'xnone' ] && [ ! "x$VCSH_GITIGNORE" = 'xrecursive' ]; then
        fatal "'\$VCSH_GITIGNORE' must equal 'exact', 'none', 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
@@ -490,6 +504,7 @@ check_dir() {
 
 check_dir "$VCSH_REPO_D"
 [ ! "x$VCSH_GITIGNORE" = 'xnone' ] && check_dir "$VCSH_BASE/.gitignore.d"
 
 check_dir "$VCSH_REPO_D"
 [ ! "x$VCSH_GITIGNORE" = 'xnone' ] && check_dir "$VCSH_BASE/.gitignore.d"
+[ ! "x$VCSH_GITATTRIBUTES" = 'xnone' ] && check_dir "$VCSH_BASE/.gitattributes.d"
 
 verbose "$VCSH_COMMAND begin"
 export VCSH_COMMAND=$(echo $VCSH_COMMAND | sed 's/-/_/g')
 
 verbose "$VCSH_COMMAND begin"
 export VCSH_COMMAND=$(echo $VCSH_COMMAND | sed 's/-/_/g')
@@ -497,3 +512,4 @@ hook pre-command
 $VCSH_COMMAND "$@"
 hook post-command
 verbose "$VCSH_COMMAND end, exiting"
 $VCSH_COMMAND "$@"
 hook post-command
 verbose "$VCSH_COMMAND end, exiting"
+exit $VCSH_COMMAND_RETURN_CODE