Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/sh
- print_usage_and_exit() {
- echo "Usage: $0 [-d <date>] [-p <path>]"
- echo ""
- echo "Searches for DM files never edited since a threshold date."
- echo ""
- echo "Arguments:"
- echo " -d, --date <date> Threshold date to use, defaults to 2013-01-01."
- echo " -p, --path <path> Path inside the git repository to search in."
- echo " -h, --help Show this help message."
- exit 0
- }
- # Parse arguments
- THRESHOLD_DATE="2013-01-01"
- FOLDER_TO_SEARCH="$PWD"
- while [[ $# > 0 ]]; do
- arg="$1"
- case $arg in
- -d|--date)
- THRESHOLD_DATE="$2"
- shift
- ;;
- -p|--path)
- FOLDER_TO_SEARCH="$2"
- shift
- ;;
- -h|--help)
- print_usage_and_exit
- ;;
- *) # default
- echo "Unknown argument found: $arg"
- print_usage_and_exit
- ;;
- esac
- shift
- done
- # Check whether $FOLDER_TO_SEARCH is a git repository and get the root directory
- FOLDER_TO_SEARCH=$(git -C "$FOLDER_TO_SEARCH" rev-parse --show-toplevel)
- [[ $? -ne 0 ]] && exit 0 # return code is non-zero on failure
- # Do stuff
- TMP_GITLOG=$(mktemp)
- TMP_FIND=$(mktemp)
- git -C "$FOLDER_TO_SEARCH" log --name-only --after="$THRESHOLD_DATE" --pretty='tformat:' | grep -E '\.dm$' | sort | uniq > "$TMP_GITLOG"
- ( cd "$FOLDER_TO_SEARCH" && find . -iname '*.dm' -type f ) | sed 's/^\.\///' | sort > "$TMP_FIND"
- # Supress files only in $TMP_GITLOG (i.e. files that no longer exist) and in both $TMP_GITLOG
- # and $TMP_FIND (i.e. changed after $THRESHOLD_DATE)
- comm -1 -3 "$TMP_GITLOG" "$TMP_FIND"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement