git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Feature request: Limit git-status reports to a directory

From
MMMichel Marti <mma@objectxp.com>
Date
Oct 25, 2007, 13:03 UTC
Message-ID
<ffq477$mji$1@ger.gmane.org>
In-Reply-To
<Pine.LNX.4.64.0710251050390.25221@racer.site>
on 10/25/2007 11:55 AM Johannes Schindelin said the following:
> I am not so sure.  In other SCMs, "git status" may be a way to do "git 
> diff --name-only" or "git ls-files", but not in git.  Here, it strictly 
> means "what would be happening if I were to commit _right_ _now_?".

I somehow agree with your argument, but then again, sometimes I'm still interested in *only* the status for a given directory.

IMHO, answering the question "what would be happening if...?" should be git-commit's task (e.g. git-commit --dry-run). And git-status should behave similar to git-log and git-diff.

For those interested: I have attached a little script that mimics current git-status (except the "dry-run" stuff) but also can take a list of directories/files.

#!/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 <file>..." 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 <file>..." 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 <file>..." to include in what will be committed)'
		echo '#'
		HP=1
	fi
	print_stat_line "X" "$F"
done
Previous: Wincent Colaiuta
Message 5 of 5 in “Feature request: Limit git-status reports to a directory”
  1. Michel MartiOct 24, 2007
  2. Yin PingOct 25, 2007
  3. Johannes SchindelinOct 25, 2007
  4. Wincent ColaiutaOct 25, 2007
  5. Michel MartiOct 25, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.