-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit-miner.sh
executable file
·53 lines (45 loc) · 1.1 KB
/
git-miner.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/sh
GIT_AMEND=''
MESSAGE=''
GIT_HEAD='HEAD'
# parse flags
while [[ $# -ge 1 ]] ; do
key="$1"
case $key in
--amend )
GIT_AMEND='--amend'
GIT_HEAD='HEAD^'
;;
-m | --message )
MESSAGE="$2"
shift
;;
-l | --leader )
LEADER="$2"
shift
;;
* )
echo "Unknown flag: $key"
exit 1
;;
esac
shift
done
DATE=$(date +"%s")
TIMEZONE=$(date +"%z")
GIT_TREE=$(git write-tree)
GIT_AUTHOR="$(git config --get user.name) <$(git config --get user.email)>"
if (git --no-pager show $GIT_HEAD > /dev/null 2> /dev/null); then
GIT_PARENT="parent $(git --no-pager show --quiet --format='%H' $GIT_HEAD)\n"
else
GIT_PARENT=""
fi
while true
do
NONCE=$(openssl rand -hex 8)
GIT_FILE="tree $GIT_TREE\n${GIT_PARENT}author $GIT_AUTHOR $DATE $TIMEZONE\ncommitter $GIT_AUTHOR $DATE $TIMEZONE\n\n$MESSAGE\n\nNONCE=0x$NONCE"
HASH=$(echo "commit $(echo $GIT_FILE | wc -c | xargs)\0$GIT_FILE" | sha1sum)
[[ $HASH == ${LEADER}* ]] && break
done
export GIT_COMMITTER_DATE=$DATE
git commit $GIT_AMEND --no-gpg-sign -m "$MESSAGE" -m "NONCE=0x${NONCE}" --date $DATE --allow-empty