-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathrepo-cmp
More file actions
executable file
·46 lines (40 loc) · 1.17 KB
/
Copy pathrepo-cmp
File metadata and controls
executable file
·46 lines (40 loc) · 1.17 KB
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
39
40
41
42
43
44
45
46
#!/bin/bash
# Usage warning/message
if [[ "$#" = 0 || "$*" = "--help" || "$*" = "-h" ]]
then
cat <<EOF
Repo Compare script
--------------------
Performs a diff on the contents of a repository directory to a target directory looking for changed files in the target.
Note: Ignores files in the .git directory.
Usage:
repo-cmp <repo_path> <target_compare_path>
EOF
exit 1
fi
# Main
repo_path=$(realpath $1)
tgt_path=$(realpath $2)
echo -e "\nComparing Files:"
echo -e "\033[92mRepository:\033[0m $repo_path"
echo -e "\033[92mCompare to:\033[0m $tgt_path"
echo -e "\n"
readarray -t files < <(find $repo_path -type f -not -path "*/.git/*")
for file in "${files[@]}"
do
file_rel=$(realpath --relative-to=$repo_path $file)
if [ -a "$tgt_path/$file_rel" ]
then
diff_out=$(diff --color=always -u "$tgt_path/$file_rel" "$repo_path/$file_rel")
else
echo -e "\033[91mNot found:\033[0m" $file_rel
echo -e "\033[1;93m=========================================================\033[0m"
continue
fi
if [ "$diff_out" ]
then
echo -e "\033[92m$file_rel\033[0m"
echo -e "$diff_out"
echo -e "\033[1;93m=========================================================\033[0m"
fi
done