소스 검색

Custom script to update submodules

- If the submodule doesn't eixst yet, then submodule update is called
- If the submodule points at the right commit then nothing happens.
- If the submodule is pointed at any other commit, this script will attempt to rebase.
  - If the rebase fails (for any reason!) then the local HEAD is used rather than just switching to whatever upstream uses.

All automatic updating is disabled by default.
Set submodule.update=true in private.properties to enable.

Change-Id: I9f370a33001bbfea5079687a41cc9cbfa07eea33
Reviewed-on: http://gerrit.dmdirc.com/326
Reviewed-by: Gregory Holmes <greboid@dmdirc.com>
Tested-by: Gregory Holmes <greboid@dmdirc.com>
tags/0.6.3b1
Chris Smith 14 년 전
부모
커밋
ac7676688c
2개의 변경된 파일89개의 추가작업 그리고 0개의 파일을 삭제
  1. 45
    0
      build.xml
  2. 44
    0
      updateSubModules.sh

+ 45
- 0
build.xml 파일 보기

@@ -12,6 +12,51 @@
12 12
     <import file="build-tests.xml"/>
13 13
     <import file="build-versioning.xml"/>
14 14
 
15
+    <target name="-submodules" depends="-submodules-bash, -submodules-default"/>
16
+
17
+    <target name="-check-use">
18
+        <!-- Use script iff:
19
+               - bash is available
20
+               - submodule.update is set to true
21
+        -->
22
+        <condition property="use.bash.submodule">
23
+            <and>
24
+                <equals arg1="${submodule.update}" arg2="true" />
25
+                <equals arg1="${has.bash}" arg2="true" />
26
+            </and>
27
+        </condition>
28
+        
29
+        <!-- Use git's built in commands iff:
30
+             - submodule.update is set to true
31
+             - bash is not available
32
+        -->
33
+        <condition property="use.default.submodule">
34
+            <and>
35
+                <equals arg1="${submodule.update}" arg2="true" />
36
+                <equals arg1="${has.bash}" arg2="false" />
37
+            </and>
38
+        </condition>
39
+    </target>
40
+
41
+
42
+    <target name="-submodules-bash" depends="-check-use" if="use.bash.submodule">
43
+        <exec executable="/bin/bash">
44
+            <arg value="updateSubModules.sh"/>
45
+        </exec>
46
+    </target>
47
+
48
+    <target name="-submodules-default" depends="-check-use" if="use.default.submodule">
49
+        <exec executable="git">
50
+            <arg value="submodule"/>
51
+            <arg value="init"/>
52
+        </exec>
53
+        <exec executable="git">
54
+            <arg value="submodule"/>
55
+            <arg value="update"/>
56
+        </exec>
57
+    </target>
58
+
59
+    <target name="-pre-init" depends="-submodules"/>
15 60
     <target name="-post-compile" depends="-write-version, build-plugins, -addpluginlibs"/>
16 61
     <target name="-post-test-run" depends="-do-test-reports"/>
17 62
     <target name="-post-jar" depends="-addjarlibs"/>

+ 44
- 0
updateSubModules.sh 파일 보기

@@ -0,0 +1,44 @@
1
+#!/bin/bash
2
+GIT=`which git`
3
+
4
+# Init any new submodules
5
+${GIT} submodule init
6
+
7
+DIR=${PWD}
8
+
9
+# Check every submodule.
10
+${GIT} submodule status | while read -r LINE; do
11
+	MISSING=`echo ${LINE} | grep ^-`
12
+	CHANGED=`echo ${LINE} | grep ^+`
13
+	MODULE=`echo ${LINE} | awk '{print $2}'`
14
+	
15
+	# If the module hasn't been checked out yet, then checkout.
16
+	if [ "${MISSING}" != "" ]; then
17
+		${GIT} submodule update ${MODULE}
18
+		if [ ${?} -ne 0 ]; then
19
+			echo "Error: Unable to update submodule ${MODULE}, aborting."
20
+			exit 1;
21
+		fi;
22
+	# Else, rebase current changes onto the new upstream version.
23
+	#   - If nothing has changed, this will just be a fast forward like normal
24
+	#   - If there are uncommited changes, this will fail and leave the submodule
25
+	#     as it is at the moment.
26
+	#   - If there are commited revisions on top of the submodule, then they will
27
+	#     be rebased onto the revision used upstream,
28
+	elif [ "${CHANGED}" != "" ]; then
29
+		# Get the revision used upstream
30
+		OLDREV=`git diff ${MODULE} | grep -- "-Subproject" | awk '{print $3}'`
31
+		if [ "${OLDREV}" != "" ]; then
32
+			cd ${MODULE}
33
+			${GIT} fetch origin 
34
+			${GIT} rebase ${OLDREV}
35
+			if [ ${?} -ne 0 ]; then
36
+				echo "Error: Rebase failed on ${MODULE}, continuing with current HEAD."
37
+				${GIT} rebase --abort
38
+			fi;
39
+		fi;
40
+	fi;
41
+	
42
+	# Go back to main project directory.
43
+	cd ${DIR}
44
+done;

Loading…
취소
저장