Skip to content

Commit f33772a

Browse files
committed
Detect git grafted shallow clones.
1 parent 16b0814 commit f33772a

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/main/java/org/glassfish/copyright/AbstractCopyright.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ public abstract class AbstractCopyright {
9999
protected static final String thisYear =
100100
"" + Calendar.getInstance().get(Calendar.YEAR);
101101

102+
protected static final String UNKNOWN_DATE = "UNKNOWN";
103+
102104
static {
103105
try {
104106
// good patterns
@@ -310,6 +312,14 @@ protected void checkCopyright(File file) throws IOException {
310312
else if (lc == null)
311313
lc = lastChanged(file.getPath());
312314

315+
if (lc == UNKNOWN_DATE) {
316+
if (!c.sawUnknown)
317+
err("Some file(s) with unknown date (shallow clone?)");
318+
c.sawUnknown = true;
319+
if (c.verbose)
320+
System.out.println("Unknown date: " + file);
321+
return;
322+
}
313323
if (!lastYear.equals(lc)) {
314324
err(file + ": Copyright year is wrong; is " +
315325
lastYear + ", should be " + lc);
@@ -913,8 +923,12 @@ private static String lastChangedGit(String file) throws IOException {
913923
p.getInputStream()));
914924
String lcd = "";
915925
String line;
926+
boolean first = true;
916927
// date returned in the form 2006-09-04
917928
while ((line = r.readLine()) != null) {
929+
if (first && line.endsWith("(grafted)"))
930+
return UNKNOWN_DATE;
931+
first = false;
918932
if (line.startsWith("Date:")) {
919933
final String[] split = line.split(" ");
920934
lcd = split[split.length - 1];

src/main/java/org/glassfish/copyright/Copyright.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2010, 2019 Oracle and/or its affiliates. All rights reserved.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -96,6 +96,7 @@ public class Copyright {
9696
public int nNoYear;
9797
public int nDate;
9898
public int errors;
99+
public boolean sawUnknown;
99100

100101
public List<String> excludes = new ArrayList<String>();
101102

0 commit comments

Comments
 (0)