From 237f91a9ef116a83b7d92daf8a492721a888829b Mon Sep 17 00:00:00 2001 From: Agathiyan Bragadeesh Date: Thu, 6 Jul 2023 18:00:48 +0100 Subject: [PATCH] Add script to manage gitignore anchors Added scripts which comment and uncomment out patterns relating to generated files. Signed-off-by: Agathiyan Bragadeesh --- scripts/gitignore_add_generated_files.sh | 23 +++++++++++++++++++++ scripts/gitignore_remove_generated_files.sh | 23 +++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 scripts/gitignore_add_generated_files.sh create mode 100644 scripts/gitignore_remove_generated_files.sh diff --git a/scripts/gitignore_add_generated_files.sh b/scripts/gitignore_add_generated_files.sh new file mode 100644 index 000000000..27c348082 --- /dev/null +++ b/scripts/gitignore_add_generated_files.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +set -eu + +GITIGNORES=$(find . -name ".gitignore") + +for GITIGNORE in $GITIGNORES; do + IN_GEN_BLOCK=false + while read -r line; do + if [ "$line" = "###START_COMMENTED_GENERATED_FILES###" ]; then + IN_GEN_BLOCK=true + echo "###START_GENERATED_FILES###" + elif [ "$line" = "###END_COMMENTED_GENERATED_FILES###" ]; then + IN_GEN_BLOCK=false + echo "###END_GENERATED_FILES###" + elif $IN_GEN_BLOCK ; then + echo "${line:1}" + else + echo "$line" + fi + done <$GITIGNORE > "$GITIGNORE.tmp" + mv "$GITIGNORE.tmp" $GITIGNORE +done diff --git a/scripts/gitignore_remove_generated_files.sh b/scripts/gitignore_remove_generated_files.sh new file mode 100644 index 000000000..8314b2c23 --- /dev/null +++ b/scripts/gitignore_remove_generated_files.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +set -eu + +GITIGNORES=$(find . -name ".gitignore") + +for GITIGNORE in $GITIGNORES; do + IN_GEN_BLOCK=false + while read -r line; do + if [ "$line" = "###START_GENERATED_FILES###" ]; then + IN_GEN_BLOCK=true + echo "###START_COMMENTED_GENERATED_FILES###" + elif [ "$line" = "###END_GENERATED_FILES###" ]; then + IN_GEN_BLOCK=false + echo "###END_COMMENTED_GENERATED_FILES###" + elif $IN_GEN_BLOCK ; then + echo "#$line" + else + echo "$line" + fi + done <$GITIGNORE > "$GITIGNORE.tmp" + mv "$GITIGNORE.tmp" $GITIGNORE +done