Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 21 additions & 12 deletions nbbuild/antsrc/org/netbeans/nbbuild/GitBranchHash.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,31 +79,40 @@ public void execute() throws BuildException {
if (headroot != null && Files.size(headroot) > 0l) {
List<String> lines = Files.readAllLines(headroot);
String line = lines.get(0);
String revLink = line.substring(line.indexOf(':')+1).trim();
branch = revLink.substring(revLink.lastIndexOf('/')+1).trim();
Path revPath = headroot.getParent().resolve(revLink);
if(Files.isRegularFile(revPath) && Files.size(revPath) > 0l) {
List<String> revlines = Files.readAllLines(revPath);
String revline = revlines.get(0);
if(revline.length()>=12){
hash = revline.trim();
if (!line.contains(":") && (line.length() == 40)) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this should be >= 40 and also trimmed? I have also no idea if >= 12 was just copying from HgID or necessary. 🤷

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not know that either. Just made some adjustments to work with a detached head.

//Detached HEAD
hash = line;
log("Detached HEAD please specify '" + branchProperty + "' externally.", Project.MSG_WARN);
} else {
String revLink = line.substring(line.indexOf(':')+1).trim();
branch = revLink.substring(revLink.lastIndexOf('/')+1).trim();
Path revPath = headroot.getParent().resolve(revLink);
if(Files.isRegularFile(revPath) && Files.size(revPath) > 0l) {
List<String> revlines = Files.readAllLines(revPath);
String revline = revlines.get(0);
if(revline.length()>=12){
hash = revline.trim();
} else {
log("no content in " + revPath, Project.MSG_WARN);
}
} else {
log("no content in " + revPath, Project.MSG_WARN);
log("unable to find revision info for " + revPath, Project.MSG_WARN);
}
} else {
log("unable to find revision info for " + revPath, Project.MSG_WARN);
}
} else {
log("No HEAD found starting from " + file, Project.MSG_WARN);
}
} catch(IOException ex) {
log("Could not read " + headroot + ": " + ex, Project.MSG_WARN);
}
if (!branch.isEmpty() && !hash.isEmpty()) {
if (!branch.isEmpty()) {
getProject().setNewProperty(branchProperty, branch);
}
if (!hash.isEmpty()) {
getProject().setNewProperty(hashProperty, hash);
}

}

}