-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchange-author.sh
executable file
·53 lines (48 loc) · 1.23 KB
/
change-author.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
49
50
51
52
53
#!/bin/bash
#set -x # echo on
# Usage:
# $ ./change-author.sh -p=~/repo/my -o="Abbas Gussenov" -n="Аббас Гусенов" -e="[email protected]"
# $ ./change-author.sh --projects=~/repo/my --old="Abbas Gussenov" --new="Аббас Гусенов" --email="[email protected]"
# $ ./change-author.sh --default
projects_dir=.
for i in "$@"; do
case $i in
-p=*|--projects=*)
projects_dir="${i#*=}"
eval projects_dir=$projects_dir
shift # past argument=value
;;
-o=*|--old=*)
old_name="${i#*=}"
shift # past argument=value
;;
-n=*|--new=*)
new_name="${i#*=}"
shift # past argument=value
;;
-e=*|--email=*)
email="${i#*=}"
shift # past argument=value
;;
--default)
projects_dir=.
shift # past argument with no value
;;
*)
# unknown option
;;
esac
done
cd "$projects_dir"
pwd
git filter-branch -f --commit-filter '
if [ "$GIT_COMMITTER_NAME" = "'"$old_name"'" ];
then
GIT_COMMITTER_NAME="'"$new_name"'";
GIT_AUTHOR_NAME="'"$new_name"'";
GIT_COMMITTER_EMAIL="'"$email"'";
GIT_AUTHOR_EMAIL="'"$email"'";
git commit-tree "$@";
else
git commit-tree "$@";
fi' HEAD