@@ -79,27 +79,8 @@ class MakePatchesTask extends PatchTask {
79
79
80
80
didWork = false
81
81
for (def patch : patches) {
82
- def diff = git. diff(' --no-color' , ' -U1' , ' --staged' , patch. absolutePath). text. readLines()
83
-
84
- boolean upToDate = false
85
-
86
- if (diff. empty) {
87
- upToDate = true
88
- } else if (! diff. contains(' --- /dev/null' )) {
89
- def first = diff. findIndexOf(HUNK )
90
- if (first >= 0 && diff[first + 1 ]. startsWith(' From' , 1 )) {
91
- def last = diff. findLastIndexOf(HUNK )
92
- if (first == last) { // There is just one hunk, so probably just the hash changed
93
- upToDate = true
94
- } else if (last >= 0 && diff[last + 1 ]. startsWith(' --' , 1 )) {
95
- if (! diff. subList(first + 4 , last). find(HUNK )) {
96
- upToDate = true
97
- }
98
- }
99
- }
100
- }
101
-
102
- if (upToDate) {
82
+ List<String > diff = git. diff(' --no-color' , ' -U1' , ' --staged' , patch. absolutePath). text. readLines()
83
+ if (isUpToDate(diff)) {
103
84
logger. lifecycle ' Skipping {} (up-to-date)' , patch. name
104
85
git. reset(' HEAD' , patch. absolutePath) >> null
105
86
git. checkout(' --' , patch. absolutePath) >> null
@@ -110,4 +91,35 @@ class MakePatchesTask extends PatchTask {
110
91
}
111
92
}
112
93
94
+ private static boolean isUpToDate (List<String > diff ) {
95
+ if (diff. empty) {
96
+ return true
97
+ }
98
+
99
+ if (diff. contains(' --- /dev/null' )) {
100
+ return false
101
+ }
102
+
103
+ // Check if there are max. 2 diff hunks (once for the hash, and once for the Git version)
104
+ def count = diff. count(HUNK )
105
+ if (count == 0 ) {
106
+ return true
107
+ }
108
+
109
+ if (count > 2 ) {
110
+ return false
111
+ }
112
+
113
+ for (def i = 0 ; i < diff. size(); i++ ) {
114
+ if (HUNK (diff[i])) {
115
+ def change = diff[i + 1 ]
116
+ if (! change. startsWith(' From' , 1 ) && ! change. startsWith(' --' , 1 )) {
117
+ return false
118
+ }
119
+ }
120
+ }
121
+
122
+ return true
123
+ }
124
+
113
125
}
0 commit comments