-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcheckoutAt.sh
executable file
·96 lines (78 loc) · 2.27 KB
/
checkoutAt.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
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
#!/bin/bash
# Script to checkout the client at a given point of time.
# Usage:
#
# checkoutAt.sh <meta|client|parser|util|plugins> <sha1>
#
# This will checkout <sha1> in the given repo, and then checkout the last
# commit in all other repos that happened before the time of requested commit.
REPO="${1}"
SHA1="${2}"
VALID_REPOS=(meta client parser util plugins)
containsElement () {
local e
for e in "${@:2}"; do [[ "$e" == "$1" ]] && return 0; done
return 1
}
containsElement "${REPO}" "${VALID_REPOS[@]}"
RES=${?}
if [ "${SHA1}" = "" -o ${RES} -ne 0 ]; then
echo "Usage:"
echo "${0} <meta|client|parser|util|plugins> <sha1>"
echo ""
echo "This will checkout <sha1> in the given repo, and then checkout the last commit in all other repos that happened before the time of requested commit."
exit 1;
fi;
CHECKOUTDIR="${PWD}"
if [ ! -e "${CHECKOUTDIR}/settings.gradle" -o "$(grep "rootProject.name = 'dmdirc'" settings.gradle 2>&1)" = "" ]; then
echo "'${PWD}' does not look like a DMDirc/meta checkout."
exit 1;
fi;
getRepoDir() {
if [ "${1}" = "meta" ]; then
echo "${CHECKOUTDIR}/"
else
echo "${CHECKOUTDIR}/${1}"
fi;
}
isCommit() {
if [ "$(git cat-file -t "${1}" 2>&1)" = "commit" ]; then
echo "0"
else
echo "1"
fi;
}
cd $(getRepoDir "${REPO}")
if [ $(isCommit ${SHA1}) -eq 1 ]; then
echo "Invalid commit in ${REPO}: ${SHA1}"
exit 1;
fi;
# Get the requested commit.
echo -ne "\e[32m"
echo "In ${REPO}: "
echo -ne "\e[93m"; git show ${SHA1} -s --format=" Checking out: %H - %s"
echo -ne "\e[93m"; git show ${SHA1} -s --format=" Author: %an / Committer: %cn / Date: %cD"
echo -e "\e[39m"
echo -ne "\e[90m"
git reset --hard
git checkout -f ${SHA1}
echo -e "\e[39m"
THISTIME=$(git show ${SHA1} --pretty=format:%ct)
# Now get all the others...
for R in "${VALID_REPOS[@]}"
do
if [ "${R}" != "${REPO}" ]; then
cd $(getRepoDir "${R}")
RSHA1=$(git rev-list -1 --before="${THISTIME}" --all)
echo -ne "\e[32m"
echo "In ${R}: "
echo -ne "\e[93m"; git show ${RSHA1} -s --format=" Checking out: %H - %s"
echo -ne "\e[93m"; git show ${RSHA1} -s --format=" Author: %an / Committer: %cn / Date: %cD"
echo -e "\e[39m"
echo -ne "\e[90m"
git reset --hard
git checkout -f ${RSHA1}
echo -e "\e[39m"
fi;
done;
cd "${CHECKOUTDIR}"