Browse Source

Merge pull request #114 from ShaneMcC/master

Add script to easily checkout all the repos to a given point
pull/116/head
Greg Holmes 7 years ago
parent
commit
e8da1ab382
1 changed files with 96 additions and 0 deletions
  1. 96
    0
      checkoutAt.sh

+ 96
- 0
checkoutAt.sh View File

@@ -0,0 +1,96 @@
1
+#!/bin/bash
2
+
3
+# Script to checkout the client at a given point of time.
4
+# Usage:
5
+#
6
+# checkoutAt.sh <meta|client|parser|util|plugins> <sha1>
7
+#
8
+# This will checkout <sha1> in the given repo, and then checkout the last
9
+# commit in all other repos that happened before the time of requested commit.
10
+
11
+REPO="${1}"
12
+SHA1="${2}"
13
+
14
+VALID_REPOS=(meta client parser util plugins)
15
+containsElement () {
16
+  local e
17
+  for e in "${@:2}"; do [[ "$e" == "$1" ]] && return 0; done
18
+  return 1
19
+}
20
+
21
+containsElement "${REPO}" "${VALID_REPOS[@]}"
22
+RES=${?}
23
+
24
+if [ "${SHA1}" = "" -o ${RES} -ne 0 ]; then
25
+	echo "Usage:"
26
+	echo "${0} <meta|client|parser|util|plugins> <sha1>"
27
+	echo ""
28
+	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."
29
+	exit 1;
30
+fi;
31
+
32
+CHECKOUTDIR="${PWD}"
33
+if [ ! -e "${CHECKOUTDIR}/settings.gradle" -o "$(grep "rootProject.name = 'dmdirc'" settings.gradle 2>&1)" = "" ]; then
34
+	echo "'${PWD}' does not look like a DMDirc/meta checkout."
35
+	exit 1;
36
+fi;
37
+
38
+
39
+getRepoDir() {
40
+	if [ "${1}" = "meta" ]; then
41
+		echo "${CHECKOUTDIR}/"
42
+	else
43
+		echo "${CHECKOUTDIR}/${1}"
44
+	fi;
45
+}
46
+
47
+isCommit() {
48
+	if [ "$(git cat-file -t "${1}" 2>&1)" = "commit" ]; then
49
+		echo "0"
50
+	else
51
+		echo "1"
52
+	fi;
53
+}
54
+
55
+cd $(getRepoDir "${REPO}")
56
+
57
+if [ $(isCommit ${SHA1}) -eq 1 ]; then
58
+	echo "Invalid commit in ${REPO}: ${SHA1}"
59
+	exit 1;
60
+fi;
61
+
62
+# Get the requested commit.
63
+echo -ne "\e[32m"
64
+echo "In ${REPO}: "
65
+echo -ne "\e[93m"; git show ${SHA1} -s --format="     Checking out: %H - %s"
66
+echo -ne "\e[93m"; git show ${SHA1} -s --format="                   Author: %an / Committer: %cn / Date: %cD"
67
+echo -e "\e[39m"
68
+
69
+
70
+echo -ne "\e[90m"
71
+git reset --hard
72
+git checkout -f ${SHA1}
73
+echo -e "\e[39m"
74
+
75
+THISTIME=$(git show ${SHA1} --pretty=format:%ct)
76
+
77
+# Now get all the others...
78
+for R in "${VALID_REPOS[@]}"
79
+do
80
+	if [ "${R}" != "${REPO}" ]; then
81
+		cd $(getRepoDir "${R}")
82
+		RSHA1=$(git rev-list -1 --before="${THISTIME}" --all)
83
+		echo -ne "\e[32m"
84
+		echo "In ${R}: "
85
+		echo -ne "\e[93m"; git show ${RSHA1} -s --format="     Checking out: %H - %s"
86
+		echo -ne "\e[93m"; git show ${RSHA1} -s --format="                   Author: %an / Committer: %cn / Date: %cD"
87
+		echo -e "\e[39m"
88
+
89
+		echo -ne "\e[90m"
90
+		git reset --hard
91
+		git checkout -f ${RSHA1}
92
+		echo -e "\e[39m"
93
+	fi;
94
+done;
95
+
96
+cd "${CHECKOUTDIR}"

Loading…
Cancel
Save