Shell script
What follows isn't a full solution, but it's a start. A more efficient and robust approach would use awk
instead of sed
to compute the three counts in only one pass over the output of git status --porcelain
.
#!/bin/sh
# git-status-perdir.sh
#
# Reports the numbers of modified, added, and deleted files in each
# subdirectory of the current directory
for f in *; do
if [ -d "$f" ]; then # if f is a directory...
out=$(git status --porcelain -- $f)
mod=$(printf "$out" | grep -c '^ M') # count modified
add=$(printf "$out" | grep -c '^A') # count added
del=$(printf "$out" | grep -c '^D') # count deleted
printf "%s : %d modified, %d added, %d deleted\n" \
"$f" "$mod" "$add" "$del"
fi
done
Toy example
# set things up
$ mkdir testgit
$ cd testgit/
$ git init
# create dir1, dir1/foo1.txt and dir1/bar1.txt
$ mkdir dir1
$ touch dir1/foo1.txt
$ touch dir1/bar1.txt
# stage all and commit
$ git add .
$ git commit -m "add foo1 and bar1"
# create and stage dir2 and dir2/foo2.txt
$ mkdir dir2
$ touch dir2/foo2.txt
$ git add test2/
# remove the (tracked) file dir1/foo1.txt
$ git rm dir1/foo1.txt
# modify dir1/bar1.txt
$ printf "Hello, world\n" > dir1/bar1.text
# run the script
$ sh git-status-perdir.sh
dir1 : 1 modified, 0 added, 1 deleted
dir2 : 0 modified, 1 added, 0 deleted