[PATCH] git add - recursive directories
From: Joshua T. Corbin <hidden>
Date: 2016-06-15 22:41:54
This patch does two things:
1) git add will now by default recursively add any directories given to it.
2) this can be disabled and the old behavior used instead with the new -n
switch.
Signed-off-by: Joshua T. Corbin <redacted>
Index: git
===================================================================--- 2aaf94eae20acc451553766f3c063bc46cfa75c6/git (mode:100755 sha1:f8f5e0e4e5c50102415cd479619dd7598d3c42e1)
+++ 58dd789846677d8d0848b608e365e9742d2db642/git (mode:100755 sha1:24d8c30383fa11d049aafcd659cefe700afe1cf1)
@@ -25,7 +25,7 @@ Usage: git COMMAND [ARG]... Available commands: - add FILE... + add [-n] FILE... addremote RNAME RSYNC_URL apply < patch on stdin cancel
Index: gitadd.sh ===================================================================
--- 2aaf94eae20acc451553766f3c063bc46cfa75c6/gitadd.sh (mode:100755 sha1:fa77d96198dd7d5ebf47bdedb296995ab7e77cf3)
+++ 58dd789846677d8d0848b608e365e9742d2db642/gitadd.sh (mode:100755 sha1:f0b030e1b4d770d96dabd5350e25f2e8fad5e59d)
@@ -5,10 +5,31 @@ # # Takes a list of file names at the command line, and schedules them # for addition to the GIT repository at the next commit. +# Optional "-n" parameter specifies that you don't want to add directories +# recursively. if [ ! "$1" ]; then - echo "gitadd.sh: usage: git add FILE..." >&2 + echo "gitadd.sh: usage: git add [-n] FILE..." >&2 exit 1; fi -update-cache --add -- "$@" +recur=1 +if [ "$1" = "-n" ]; then + shift + recur= +fi + +if [ $recur ]; then + ADDFILE=$(mktemp -t gitadd.XXXXXX) + while [ "$1" ]; do + if [ -d "$1" ]; then + find $1 -type f -and -not -name '.*' + else + echo "$1" + fi + shift + done > $ADDFILE + update-cache --add -- $(cat $ADDFILE) +else + update-cache --add -- "$@" +fi