diff --git a/ci/README.md b/ci/README.md index 73962f80a..52a8925cc 100644 --- a/ci/README.md +++ b/ci/README.md @@ -349,6 +349,12 @@ This was deemed to be error prone and not worth the effort. ## `fix_gitignore.sh` -This script makes sure that git ignores the sql files and expected output files -that are generated from `.source` template files. If you created or deleted a -`.source` file in a commit, git ignore rules should be updated. +This script checks and fixes issues with `.gitignore` rules: + +1. Makes sure git ignores the `.sql` files and expected output files that are generated + from `.source` template files. If you created or deleted a `.source` file in a commit, + git ignore rules should be updated to reflect this change. + +2. Makes sure we do not commit any generated files that should be ignored. If there is an + ignored file in the git tree, the user is expected to review the files that are removed + from the git tree and commit them. diff --git a/ci/fix_gitignore.sh b/ci/fix_gitignore.sh index c8d6b29ac..a2258c472 100755 --- a/ci/fix_gitignore.sh +++ b/ci/fix_gitignore.sh @@ -18,3 +18,17 @@ ls -1 src/test/regress/input | sed -E "s#(.*)\.source#/\1.sql#" > src/test/regre # e.g. multi_copy.source -> /multi_copy.out ls -1 src/test/regress/output | sed -E "s#(.*)\.source#/\1.out#" > src/test/regress/expected/.gitignore + +# Remove all the ignored files from git tree, and error out +# find all ignored files in git tree, and use quotation marks to prevent word splitting on filenames with spaces in them +ignored_lines_in_git_tree=$(git ls-files --ignored --exclude-standard | sed 's/.*/"&"/') + +if [[ -n $ignored_lines_in_git_tree ]] +then + echo "Ignored files should not be in git tree!" + echo "${ignored_lines_in_git_tree}" + + echo "Removing these files from git tree, please review and commit" + echo "$ignored_lines_in_git_tree" | xargs git rm -r --cached + exit 1 +fi