-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcsv-last-commit.sh
executable file
·38 lines (30 loc) · 1.18 KB
/
csv-last-commit.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/bin/bash
# Avital Pinnick, Jan. 10, 2023
# This script generates a CSV file showing the last commit date for files.
# Useful for identifying files that might be abandoned or obsolete.
# This script is not recursive. It only searches the specified directory.
#
# Usage: $ ./csv-last-commit.sh </directory> OPT:<file_name_string>
if [ -z "$1" ];
then
printf '\nYou must specify a target directory. Optional: file name string.\n\nExamples:\n$ ./csv-last-commit.sh ../openshift-docs/modules virt- (for file names containing "virt-")\n$ ./csv-last-commit.sh ../openshift-docs/virt/install (all files in directory)\n\nExiting...\n\n'
exit 2
fi
if [ -z "$2" ];
then
STRING=*
fi
DIR=$1
STRING=$2
LAST_COMMIT=last-commit.csv
TOTAL=$(ls -l $DIR/*$STRING* | grep 'adoc\|md' | wc -l )
rm $LAST_COMMIT &>/dev/null
echo -e "\nGenerating './$LAST_COMMIT' with last Git commit for $TOTAL files in $DIR."
echo "File,Date,Name,Hash,Message" > $LAST_COMMIT
for file in $DIR/*$STRING*; do
if [ ! -d "$file" ]; then
echo -e $(basename $file), | tr -d \\n >> $LAST_COMMIT
git -C "$DIR" log -n 1 --date=short --pretty=format:"%cd,%cn,%h,%s%n" $(basename $file) >> $LAST_COMMIT
fi
done
echo -e "Done\n"