#!/bin/sh USAGE='[--staged] [--changed] [--untracked]' SUBDIRECTORY_OK=1 . git-sh-setup require_work_tree print_stat_line() { case "$1" in M) echo "# modified: $2";; A) echo "# new file: $2";; R*) echo "# renamed: $2 -> $3";; D) echo "# deleted: $2";; U) echo "# unmerged: $2";; X) echo "# $2";; *) echo "# [$S]: $2";; esac } STAGED= CHANGED= UNTRACKED= HP= while test $# != 0 do case "$1" in -s|--staged) STAGED=1; shift;; -c|--changed) CHANGED=1; shift;; -u|--untracked) UNTRACKED=1; shift;; --) shift; break;; -*) usage;; *) break;; esac done if BRANCH_NAME=$(git symbolic-ref -q HEAD) then BRANCH_NAME="On branch $(expr "z$BRANCH_NAME" : 'zrefs/heads/\(.*\)')" else BRANCH_NAME="Not currently on any branch" fi [ "$#" = 0 ] && cd_to_toplevel if [ -z "$STAGED$CHANGED$UNTRACKED" ]; then STAGED=1; CHANGED=1; UNTRACKED=1 fi SP=$(echo _/$(git rev-parse --show-cdup)|tr '/' ' '|wc -w) echo "# $BRANCH_NAME" # Changes to be commited [ "$STAGED" ] && git-diff --name-status --cached -M -- "$@"|while read S F R do if [ -z "$HP" ]; then echo '# Changes to be committed:' echo '# (use "git reset HEAD ..." to unstage)' echo '#' HP=1 fi F=$(echo $F|cut -d'/' -f$SP-) print_stat_line "$S" "$F" "$R" done # Changed but not updated [ "$CHANGED" ] && git-diff --name-status -- "$@"|while read S F do if [ -z "$HP" ]; then echo '#' echo '# Changed but not updated:' echo '# (use "git add ..." to update what will be committed)' echo '#' HP=1 fi F=$(echo $F|cut -d'/' -f$SP-) print_stat_line "$S" "$F" done # Untracked files [ "$UNTRACKED" ] && git-ls-files --exclude-per-directory=.gitignore -o --directory -- "$@"|while read F do if [ -z "$HP" ]; then echo '#' echo '# Untracked files:' echo '# (use "git add ..." to include in what will be committed)' echo '#' HP=1 fi print_stat_line "X" "$F" done