]> 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:

Add test for terse status output
[code/vcsh.git] / vcsh
diff --git a/vcsh b/vcsh
index cf7d1a7178d71ce1f34c46aaf09838ae7ac7c459..2f5026199476026554e6a44bca551d36551863b1 100755 (executable)
--- a/vcsh
+++ b/vcsh
 # If '.git-HEAD' is appended to the version, you are seeing an unreleased
 # version of vcsh; the master branch is supposed to be clean at all times
 # so you can most likely just use it nonetheless
 # If '.git-HEAD' is appended to the version, you are seeing an unreleased
 # version of vcsh; the master branch is supposed to be clean at all times
 # so you can most likely just use it nonetheless
-VERSION='1.20141025'
+VERSION='1.20141026'
 SELF=$(basename $0)
 
 fatal() {
        echo "$SELF: fatal: $1" >&2
 SELF=$(basename $0)
 
 fatal() {
        echo "$SELF: fatal: $1" >&2
-       [ -z $2] && exit 1
+       [ -z $2 ] && exit 1
        exit $2
 }
 
        exit $2
 }
 
@@ -100,7 +100,8 @@ help() {
    -v                   Enable verbose mode
 
    commands:
    -v                   Enable verbose mode
 
    commands:
-   clone <remote> \\
+   clone [-b <branch>] \\
+         <remote> \\
          [<repo>]       Clone from an existing repository
    commit               Commit in all repositories
    delete <repo>        Delete an existing repository
          [<repo>]       Clone from an existing repository
    commit               Commit in all repositories
    delete <repo>        Delete an existing repository
@@ -118,7 +119,8 @@ help() {
           <newname>     Rename repository
    run <repo> \\
        <command>        Use this repository
           <newname>     Rename repository
    run <repo> \\
        <command>        Use this repository
-   status [<repo>]      Show statuses of all/one vcsh repositories
+   status \\
+     [--terse] [<repo>] Show statuses of all/one vcsh repositories
    upgrade <repo>       Upgrade repository to currently recommended settings
    version              Print version information
    which <substring>    Find substring in name of any tracked file
    upgrade <repo>       Upgrade repository to currently recommended settings
    version              Print version information
    which <substring>    Find substring in name of any tracked file
@@ -149,16 +151,17 @@ clone() {
        hook pre-clone
        init
        git remote add origin "$GIT_REMOTE"
        hook pre-clone
        init
        git remote add origin "$GIT_REMOTE"
-       git config branch.master.remote origin
-       git config branch.master.merge  refs/heads/master
-       VCSH_CLONE_ERROR=$(git ls-remote origin master 2>&1)
-       if [ -n "$VCSH_CLONE_ERROR" ]; then
-               rm -rf "$GIT_DIR"
-               fatal "$VCSH_CLONE_ERROR" 1
+       git checkout -b "$VCSH_BRANCH" || return $?
+       git config branch."$VCSH_BRANCH".remote origin
+       git config branch."$VCSH_BRANCH".merge  refs/heads/"$VCSH_BRANCH"
+       if [ $(git ls-remote origin "$VCSH_BRANCH" 2> /dev/null | wc -l ) -lt 1 ]; then
+               info "remote is empty, not merging anything.
+  You should add files to your new repository."
+               exit
        fi
        fi
-       git fetch
+       git fetch origin "$VCSH_BRANCH"
        hook pre-merge
        hook pre-merge
-       git ls-tree -r --name-only origin/master | (while read object; do
+       git ls-tree -r --name-only origin/"$VCSH_BRANCH" | (while read object; do
                [ -e "$object" ] &&
                        error "'$object' exists." &&
                        VCSH_CONFLICT=1
                [ -e "$object" ] &&
                        error "'$object' exists." &&
                        VCSH_CONFLICT=1
@@ -166,7 +169,7 @@ clone() {
        [ x"$VCSH_CONFLICT" = x'1' ]) &&
                fatal "will stop after fetching and not try to merge!
   Once this situation has been resolved, run 'vcsh $VCSH_REPO_NAME pull' to finish cloning." 17
        [ x"$VCSH_CONFLICT" = x'1' ]) &&
                fatal "will stop after fetching and not try to merge!
   Once this situation has been resolved, run 'vcsh $VCSH_REPO_NAME pull' to finish cloning." 17
-       git merge origin/master
+       git merge origin/"$VCSH_BRANCH"
        hook post-merge
        hook post-clone
        retire
        hook post-merge
        hook post-clone
        retire
@@ -365,19 +368,23 @@ run() {
 }
 
 status() {
 }
 
 status() {
+       if [ -t 1 ]; then
+               COLORING="-c color.status=always"
+       fi
        if [ -n "$VCSH_REPO_NAME" ]; then
                status_helper $VCSH_REPO_NAME
        else
                for VCSH_REPO_NAME in $(list); do
        if [ -n "$VCSH_REPO_NAME" ]; then
                status_helper $VCSH_REPO_NAME
        else
                for VCSH_REPO_NAME in $(list); do
-                       echo "$VCSH_REPO_NAME:"
-                       status_helper $VCSH_REPO_NAME
-                       echo
+                       STATUS=$(status_helper $VCSH_REPO_NAME "$COLORING")
+                       [ -n "$STATUS" -o -z "$VCSH_STATUS_TERSE" ] && echo "$VCSH_REPO_NAME:"
+                       [ -n "$STATUS" ] && echo "$STATUS"
+                       [ -z "$VCSH_STATUS_TERSE" ] && echo
                done
        fi
 }
 
 status_helper() {
                done
        fi
 }
 
 status_helper() {
-       GIT_DIR=$VCSH_REPO_D/$VCSH_REPO_NAME.git; export GIT_DIR
+       GIT_DIR=$VCSH_REPO_D/$1.git; export GIT_DIR
        use
        remote_tracking_branch=$(git rev-parse --abbrev-ref --symbolic-full-name @{u} 2> /dev/null) && {
                commits_behind=$(git log ..${remote_tracking_branch} --oneline | wc -l)
        use
        remote_tracking_branch=$(git rev-parse --abbrev-ref --symbolic-full-name @{u} 2> /dev/null) && {
                commits_behind=$(git log ..${remote_tracking_branch} --oneline | wc -l)
@@ -385,7 +392,7 @@ status_helper() {
                [ ${commits_behind} -ne 0 ] && echo "Behind $remote_tracking_branch by $commits_behind commits"
                [ ${commits_ahead} -ne 0 ] && echo "Ahead of $remote_tracking_branch by $commits_ahead commits"
        }
                [ ${commits_behind} -ne 0 ] && echo "Behind $remote_tracking_branch by $commits_behind commits"
                [ ${commits_ahead} -ne 0 ] && echo "Ahead of $remote_tracking_branch by $commits_ahead commits"
        }
-       git status --short --untracked-files='no'
+       git $2 status --short --untracked-files='no'
        VCSH_COMMAND_RETURN_CODE=$?
 }
 
        VCSH_COMMAND_RETURN_CODE=$?
 }
 
@@ -497,11 +504,28 @@ case $VCSH_COMMAND in
 esac    
 
 if [ x"$VCSH_COMMAND" = x'clone' ]; then
 esac    
 
 if [ x"$VCSH_COMMAND" = x'clone' ]; then
+       VCSH_BRANCH=
+       if [ "$2" = -b ]; then
+               VCSH_BRANCH=$3
+               shift
+               shift
+       fi
        [ -z "$2" ] && fatal "$VCSH_COMMAND: please specify a remote" 1
        GIT_REMOTE="$2"
        [ -z "$2" ] && fatal "$VCSH_COMMAND: please specify a remote" 1
        GIT_REMOTE="$2"
-       [ -n "$3" ] && VCSH_REPO_NAME=$3 || VCSH_REPO_NAME=$(basename "${GIT_REMOTE#*:}" .git)
+       [ -n "$VCSH_BRANCH" ] || if [ "$3" = -b ]; then
+               VCSH_BRANCH=$4
+               shift
+               shift
+       fi
+       if [ -n "$3" ]; then
+               VCSH_REPO_NAME=$3
+               [ -z "$VCSH_BRANCH" ] && [ "$4" = -b ] && VCSH_BRANCH=$5
+       else
+               VCSH_REPO_NAME=$(basename "${GIT_REMOTE#*:}" .git)
+       fi
        [ -z "$VCSH_REPO_NAME" ] && fatal "$VCSH_COMMAND: could not determine repository name" 1
        export VCSH_REPO_NAME
        [ -z "$VCSH_REPO_NAME" ] && fatal "$VCSH_COMMAND: could not determine repository name" 1
        export VCSH_REPO_NAME
+       [ -n "$VCSH_BRANCH" ] || VCSH_BRANCH=master
        GIT_DIR=$VCSH_REPO_D/$VCSH_REPO_NAME.git; export GIT_DIR
 elif [ "$VCSH_COMMAND" = 'version' ]; then
        echo "$SELF $VERSION"
        GIT_DIR=$VCSH_REPO_D/$VCSH_REPO_NAME.git; export GIT_DIR
 elif [ "$VCSH_COMMAND" = 'version' ]; then
        echo "$SELF $VERSION"
@@ -535,6 +559,11 @@ elif [ x"$VCSH_COMMAND" = x'commit' ] ||
      [ x"$VCSH_COMMAND" = x'push'   ]; then
        :
 elif [ x"$VCSH_COMMAND" = x'status' ]; then
      [ x"$VCSH_COMMAND" = x'push'   ]; then
        :
 elif [ x"$VCSH_COMMAND" = x'status' ]; then
+       if [ x"$2" = x'--terse' ]; then
+               VCSH_STATUS_TERSE=1
+               export VCSH_STATUS_TERSE
+               shift
+       fi
        VCSH_REPO_NAME=$2; export VCSH_REPO_NAME
 elif [ -n "$2" ]; then
        VCSH_COMMAND='run'; export VCSH_COMMAND
        VCSH_REPO_NAME=$2; export VCSH_REPO_NAME
 elif [ -n "$2" ]; then
        VCSH_COMMAND='run'; export VCSH_COMMAND