{"thread":{"id":"3337","subject":"[PATCH 2/2] Workaround git < 1.2.0 ignoring .gitignore in parent directories","startedAt":"2006-02-14T18:05:20Z","lastAt":"2006-02-14T18:05:22Z","messageCount":2,"participants":["Pavel Roskin"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"16122","messageId":"20060214180520.13766.78172.stgit@dv.roinet.com","threadId":"3337","inReplyTo":null,"subject":"[PATCH 1/2] cg-clean shouldn't clean untracked directories without -d","fromName":"Pavel Roskin","fromEmail":"proski@gnu.org","sentAt":"2006-02-14T18:05:20Z","receivedAt":"2006-02-14T18:05:20Z","isPatch":true,"sender":{"key":"proski@gnu.org","avatar":null},"body":"Use the new squashdirs argument in list_untracked_files() to treat\nuntracked directories and their contents as a whole.  Remove a separate\npass to find untracked directories.  Adjust the testsuite accordingly.\n\nDon't change IFS - it's no longer needed.\n\nSigned-off-by: Pavel Roskin <proski@gnu.org>\n---\n\n cg-clean         |   99 ++++++++++--------------------------------------------\n t/t9400-clean.sh |    3 +-\n 2 files changed, 20 insertions(+), 82 deletions(-)\n\ndiff --git a/cg-clean b/cg-clean\nindex b40b41b..5c27a26 100755\n--- a/cg-clean\n+++ b/cg-clean\n@@ -53,88 +53,27 @@ done\n \n [ ${#ARGS[*]} = 0 ] || usage\n \n-\n-clean_dirs()\n-{\n-\tdirlist=\"$(mktemp -t gitlsfiles.XXXXXX)\"\n-\tgit-ls-files --cached |\n-\t\tsed -n 's|/[^/]*$||p' |\n-\t\twhile IFS=$'\\n' read -r dir; do\n-\t\t\twhile true; do\n-\t\t\t\techo \"$dir\"\n-\t\t\t\tupdir=\"${dir%/*}\"\n-\t\t\t\t[ \"$dir\" = \"$updir\" ] && break\n-\t\t\t\tdir=\"$updir\"\n-\t\t\tdone\n-\t\tdone |\n-\t\tsort -u >\"$dirlist\"\n-\n-\tsave_IFS=\"$IFS\"\n-\tIFS=$'\\n'\n-\n-\tfind ./ -type d -print |\n-\t\tsed 's/^\\.\\///;/^$/d;/^\\.git$/d;/^\\.git\\//d' |\n-\t\tcat - \"$dirlist\" | sort -u |\n-\t\tdiff - \"$dirlist\" |\n-\t\tsed -n 's/< //p' |\n-\twhile read -r dir; do\n-\t\tif [ ! -d \"$dir\" ]; then\n-\t\t\t# Perhaps directory was removed with its parent\n-\t\t\tcontinue\n-\t\tfi\n+cd \"${_git_relpath-.}\"\n+list_untracked_files \"$noexclude\" squashdirs | tr '\\0' '\\n' |\n+while read -r file; do\n+\tif [ -d \"$file\" -a ! -L \"$file\" ]; then\n \t\tif [ -z \"$cleandir\" ]; then\n-\t\t\techo \"Not removing $dir/\"\n+\t\t\techo \"Not removing $file\"\n \t\t\tcontinue\n \t\tfi\n-\t\t[ \"$quiet\" ] || echo \"Removing $dir/\"\n+\t\t[ \"$quiet\" ] || echo \"Removing $file\"\n \t\tif [ \"$cleandirhard\" ]; then\n-\t\t\tchmod -R 700 \"$dir\"\n+\t\t\tchmod -R 700 \"$file\"\n \t\tfi\n-\t\t$rm -rf \"$dir\"\n-\t\tif [ -e \"$dir\" -o -L \"$dir\" ]; then\n-\t\t\techo \"Cannot remove $dir/\"\n-\t\tfi\n-\tdone\n-\n-\tIFS=\"$save_IFS\"\n-\trm \"$dirlist\"\n-}\n-\n-clean_files()\n-{\n-\tsave_IFS=\"$IFS\"\n-\tIFS=$'\\n'\n-\n-\tlist_untracked_files \"$noexclude\" nosquashdirs | tr '\\0' '\\n' |\n-\t(cd \"${_git_relpath-.}\" &&\n-\twhile read -r file; do\n-\t\tif [ -z \"$_git_relpath\" ] || [ x\"${file#$_git_relpath}\" != x\"$file\" ]; then\n-\t\t\tfile=\"${file#$_git_relpath}\"\n-\t\telse\n-\t\t\tcontinue\n-\t\tfi\n-\n-\t\tif [ -d \"$file\" -a ! -L \"$file\" ]; then\n-\t\t\t# Sanity check, shouldn't happen\n-\t\t\techo \"FATAL: cg-status reports directories (internal error)\" >&2\n-\t\t\texit 1\n-\t\telif [ -e \"$file\" -o -L \"$file\" ]; then\n-\t\t\t[ \"$quiet\" ] || echo \"Removing $file\"\n-\t\t\t\"$rm\" -f \"$file\"\n-\t\t\t# rm would complain itself on failure\n-\t\telse\n-\t\t\techo \"File $file has disappeared!\"\n-\t\tfi\n-\tdone)\n-\n-\tIFS=\"$save_IFS\"\n-}\n-\n-\n-# Even if -d or -D is not specified, we want to tell user about\n-# directories that are not removed\n-if [ -z \"$quiet\" -o \"$cleandir\" ]; then\n-\t( cd \"${_git_relpath-.}\" && clean_dirs )\n-fi\n-\n-clean_files\n+\t\t$rm -rf \"$file\"\n+\t\tif [ -e \"$file\" -o -L \"$file\" ]; then\n+\t\t\techo \"Cannot remove $file\"\n+\t\tfi\n+\telif [ -e \"$file\" -o -L \"$file\" ]; then\n+\t\t[ \"$quiet\" ] || echo \"Removing $file\"\n+\t\t\"$rm\" -f \"$file\"\n+\t\t# rm would complain itself on failure\n+\telse\n+\t\techo \"File $file has disappeared!\"\n+\tfi\n+done\ndiff --git a/t/t9400-clean.sh b/t/t9400-clean.sh\nindex 47ae0dc..98801c5 100755\n--- a/t/t9400-clean.sh\n+++ b/t/t9400-clean.sh\n@@ -84,10 +84,8 @@ echo \"ign file 3\" >\"repo dir/ign file 3.\n echo \"ign file 4\" >\"repo dir/ign file 4.ign1\"\n mklist init\n \n-# FIXME: cg-clean shouldn't clean unknown directories without \"-d\"\n loss='extra file 1\n ign file 2.ign1\n-extra dir 1/extra file 3\n repo dir/extra file 2'\n test_expect_success 'cg-clean in top-level dir' \\\n \t\"(cg-clean && check_loss)\"\n@@ -99,6 +97,7 @@ test_expect_success 'cg-clean -x in top-\n \t\"(cg-clean -x && check_loss)\"\n \n loss='extra dir 1\n+extra dir 1/extra file 3\n repo dir/extra dir 2'\n test_expect_success 'cg-clean -d in top-level dir' \\\n \t\"(cg-clean -d && check_loss)\"\n"},{"id":"16121","messageId":"20060214180522.13766.22633.stgit@dv.roinet.com","threadId":"3337","inReplyTo":"20060214180520.13766.78172.stgit@dv.roinet.com","subject":"[PATCH 2/2] Workaround git < 1.2.0 ignoring .gitignore in parent directories","fromName":"Pavel Roskin","fromEmail":"proski@gnu.org","sentAt":"2006-02-14T18:05:22Z","receivedAt":"2006-02-14T18:05:22Z","isPatch":true,"sender":{"key":"proski@gnu.org","avatar":null},"body":"Add --exclude-from for all existing .gitignore files in parent\ndirectories up to the repository root.  This is not needed for git 1.2.0\nand newer.\n\nSigned-off-by: Pavel Roskin <proski@gnu.org>\n---\n\n cg-Xlib |   16 ++++++++++++++++\n 1 files changed, 16 insertions(+), 0 deletions(-)\n\ndiff --git a/cg-Xlib b/cg-Xlib\nindex 85a21c2..af278b6 100644\n--- a/cg-Xlib\n+++ b/cg-Xlib\n@@ -230,6 +230,22 @@ list_untracked_files()\n \t\t\tEXCLUDE[${#EXCLUDE[@]}]=\"--exclude-from=$EXCLUDEFILE\"\n \t\tfi\n \t\tEXCLUDE[${#EXCLUDE[@]}]=\"--exclude-per-directory=.gitignore\"\n+\t\t# Workaround for git < 1.2.0\n+\t\tif [ -n \"$_git_relpath\" ]; then\n+\t\t\tlocal dir=\"${_git_relpath%/}\"\n+\t\t\tlocal reldir=\"..\"\n+\t\t\twhile [ \"$dir\" != \".\" ]; do\n+\t\t\t\tif [ \"${dir%/*}\" = \"$dir\" ]; then\n+\t\t\t\t\tdir=\".\"\n+\t\t\t\telse\n+\t\t\t\t\tdir=\"${dir%/*}\"\n+\t\t\t\tfi\n+\t\t\t\tif [ -f \"$reldir/.gitignore\" ]; then\n+\t\t\t\t\tEXCLUDE[${#EXCLUDE[@]}]=\"--exclude-from=$dir/.gitignore\"\n+\t\t\t\tfi\n+\t\t\t\treldir=\"../$reldir\"\n+\t\t\tdone\n+\t\tfi\n \tfi\n \tlocal listdirs=\n \t[ \"$squashflag\" = \"squashdirs\" ] && listdirs=--directory\n"}]}