This repository has been archived by the owner on Feb 2, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathscrub.sh
executable file
·48 lines (40 loc) · 1.51 KB
/
scrub.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
39
40
41
42
43
44
45
46
47
48
#!/bin/sh
take_out_trash () {
rm -rf .git/refs/original/
git reflog expire --expire=now --all
git gc --prune=now
git gc --aggressive --prune=now
}
git_log_output_source=$(git --no-pager log -S$GHE_URL --all; git --no-pager log -G$GHE_URL --all)
if [ "$git_log_output_source" = "" ]; then
echo "Success! No GHE references found in your source code."
else
echo "Found GHE references in source code. Scrubbing..."
git filter-branch --force --tree-filter "find . -type f -exec grep -I -l -q . {} \; -print0 | LC_ALL=C xargs -0 sed -i '' 's/$GHE_URL/fake.ghe.domain/g'" --tag-name-filter cat -- --all
take_out_trash
fi
git_log_output_commits=$(git --no-pager log --grep=$GHE_URL --all)
edit_commit_messages () {
git filter-branch -f --msg-filter 'LC_ALL=C sed "s/'$GHE_URL'/fake.ghe.domain/g"' --tag-name-filter cat -- --all
}
confirm_continue () {
read -r -p "Do you want to continue and edit commit messages? [y/n] " response
case $response in
[yY][eE][sS]|[yY])
edit_commit_messages
take_out_trash
;;
*)
echo "Goodbye."
;;
esac
}
if [ "$git_log_output_commits" = "" ]; then
echo "Success! No GHE references found in commit messages."
else
commit_sha=$(echo $git_log_output_commits | grep -E -o 'commit [0-9a-z]{40}' | cut -d ' ' -f 2)
commit_count=$(echo $((${#commit_sha} / 40)) )
echo "Found $commit_count commit messages with GHE references to scrub:"
echo $commit_sha
confirm_continue
fi