#!/usr/bin/env bash
#
# Show status of entries in your working tree.
# Copyright (c) Petr Baudis, 2005
#
# Print of files in the working tree.
#
# The output has the following format:
#
#	<status flag> <file>
#
# where '<status flag>' can be one of the following:
#
# ?::
#	'<file>' is unknown.
# M::
#	'<file>' has been touched or modified.
#
# FILES
# -----
# $GIT_DIR/exclude::
#	If the file exists it will be used to prune which files to
#	show status for. The format is similar to the `dontdiff` file;
#	each line contains a pattern for a file or group of files
#	to exclude.

USAGE="cg-status"

. ${COGITO_LIB}cg-Xlib

[ 0 -eq $# ] || die "no arguments allowed"

EXCLUDEFILE=$_git/exclude
EXCLUDE=
if [ -f $EXCLUDEFILE ]; then
	EXCLUDE="--exclude-from=$EXCLUDEFILE"
fi

git-update-cache --refresh > /dev/null

git-ls-files --others --exclude='*.[ao]' --exclude='.*' --exclude=tags \
	--exclude='*~' --exclude='#*' \
	--exclude=',,merge*' $EXCLUDE | sed 's,^,? ,'

git-diff-cache HEAD | cut -f5- -d' ' | 
while IFS=$'\t' read -r mode file; do
	if [ "$mode" = D ]; then
		[ "$(git-diff-files "$file")" ] && mode=!
	fi
	echo "$mode $file"
done
