-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommit-actions.sh
67 lines (53 loc) · 1.82 KB
/
commit-actions.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/bash
function do_commit () {
message="$1"
complexity=3
i=1
prev_commit_hash=$(git log --format="%H" -1)
commit_hash=$(git log --format="%H" -1)
hash_prefix=${commit_hash:0:$complexity}
while [ $? -ne 0 ] || [ $commit_hash = $prev_commit_hash ] || [ $(( 10#$hash_prefix )) -ne 0 ]; do
echo "Attempt: $i"
i=$((i+1))
git commit -m "$message" -m "Lucky Number: $(date '+%N')"
commit_hash=$(git log --format="%H" -1)
hash_prefix=${commit_hash:0:$complexity}
[ -n "$hash_prefix" ] && [ "$hash_prefix" -eq "$hash_prefix" ] 2>/dev/null
done
}
function do_amend () {
message="$1"
complexity=3
i=1
prev_commit_hash=$(git log --format="%H" -1)
commit_hash=$(git log --format="%H" -1)
hash_prefix=${commit_hash:0:$complexity}
[ -n "$hash_prefix" ] && [ "$hash_prefix" -eq "$hash_prefix" ] 2>/dev/null
while [ $? -ne 0 ] || [ $commit_hash = $prev_commit_hash ] || [ $(( 10#$hash_prefix )) -ne 0 ]; do
echo "Attempt: $i"
i=$((i+1))
git commit --amend -m "$message" -m "Lucky Number: $(date '+%N')"
commit_hash=$(git log --format="%H" -1)
hash_prefix=${commit_hash:0:$complexity}
[ -n "$hash_prefix" ] && [ "$hash_prefix" -eq "$hash_prefix" ] 2>/dev/null
done
}
function do_cherry_pick () {
hash="$1"
message="$2"
prev_commit_hash=$(git log --format="%H" -1)
commit_hash=$(git log --format="%H" -1)
complexity=3
hash_prefix="111"
i=1
while [ $? -ne 0 ] || [ $commit_hash = $prev_commit_hash ] || [ $(( 10#$hash_prefix )) -ne 0 ]; do
echo "Attempt: $i"
i=$((i+1))
git reset --hard
git cherry-pick "$hash" -n
git commit -m "$message" -m "Lucky Number: $(date '+%N')"
commit_hash=$(git log --format="%H" -1)
hash_prefix=${commit_hash:0:$complexity}
[ -n "$hash_prefix" ] && [ "$hash_prefix" -eq "$hash_prefix" ] 2>/dev/null
done
}