This repository has been archived by the owner on Sep 23, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit-timeline.bash
131 lines (108 loc) · 2.72 KB
/
git-timeline.bash
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/bin/bash
fuzzy () {
mkdir -p fuzzy/
cd fuzzy/
days=${1:-731}
daily=${2:-2}
# Initialize
git init
echo "0" > FILE
git add FILE
git commit -m 'Initial commit'
export INITIAL_DATE='2019-01-01 19:50:42 -0400'
for i in $(seq 1 $days)
do
commits=$((RANDOM % $daily))
for d in $(seq 1 $commits)
do
hour=$((18 + RANDOM % 5))
minute=$((RANDOM % 60))
second=$((RANDOM % 60))
NEXT_DATE=$(date "+%Y-%m-%d ${hour}:${minute}:${second} %z" -d "$INITIAL_DATE + $i day")
echo "$i:$d times" > FILE
git add FILE
set GIT_COMMITTER_DATE="${NEXT_DATE}"
set GIT_AUTHOR_DATE="${NEXT_DATE}"
GIT_AUTHOR_DATE="${NEXT_DATE}" GIT_COMMITTER_DATE="${NEXT_DATE}" git commit -m "[peon] work $i:$d"
done
done
}
clone () {
mkdir -p clone/
cd clone/
# Initialize
git init
echo "0" > FILE
git add FILE
git commit -m 'Initial commit'
# Set the items
for i in {1..15}
do
echo "$i times" > FILE
git add FILE
git commit -m "Changed to $i"
sleep 2s
done
}
working () {
rm -rf working/
cp -r clone/ working/
}
history () {
cd working/
commit_file=
git log --oneline --pretty=format:"%ad|%s" | awk '{print NR-1 "|" $s}' > "../COMMITS"
tac "../COMMITS" > "../HISTORY"
sed -i '1d;$d' "../HISTORY"
touch "../LATEST"
touch "../FIRST"
}
show () {
cd working/
git log --pretty=fuller
}
apply () {
cd working/
commit_first "$(cat ../FIRST)"
while read p; do
counter=$(echo "$p" | cut -d'|' -f1)
datetime=$(echo "$p" | cut -d'|' -f2)
msg=$(echo "$p" | cut -d'|' -f3)
git-rebase-custom "$counter" "$datetime"
done <"../HISTORY"
commit_latest "$(cat ../LATEST)"
}
git-rebase-custom() {
datetime="$2"
(
export GIT_COMMITTER_DATE="$datetime"
GIT_SEQUENCE_EDITOR="sed -i -ze 's/^pick/e/'" git rebase "HEAD~$1^" -i
git commit --amend --no-edit --date="$datetime"
GIT_SEQUENCE_EDITOR=touch git rebase --continue
unset GIT_COMMITTER_DATE
)
}
commit_latest () {
datetime="$@"
(
export GIT_COMMITTER_DATE="$datetime"
git commit --amend --no-edit --date="$datetime"
unset GIT_COMMITTER_DATE
)
}
commit_first () {
datetime="$@"
(
export GIT_COMMITTER_DATE="$datetime"
GIT_SEQUENCE_EDITOR="sed -i -ze 's/^pick/e/'" git rebase -i --root
git commit --amend --no-edit --date="$datetime"
GIT_SEQUENCE_EDITOR=touch git rebase --continue
unset GIT_COMMITTER_DATE
)
}
cycle () {
( working )
( apply )
( show )
}
$@