Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/main/java/jenkins/plugins/git/GitSCMFileSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ static HeadNameResult calculate(@NonNull BranchSpec branchSpec,
}

String headName;
if (rev != null) {
if (rev != null && env != null) {
headName = env.expand(rev.getHead().getName());
} else {
if (branchSpecExpandedName.startsWith(prefix)) {
Expand Down
15 changes: 15 additions & 0 deletions src/test/java/jenkins/plugins/git/GitSCMFileSystemTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,21 @@ public void calculate_head_name_with_env() throws Exception {
assertEquals(Constants.R_HEADS, result6.prefix);
}

/* GitSCMFileSystem in git plugin 4.14.0 reported a null pointer
* exception when the rev was non-null and the env was null. */
@Issue("JENKINS-70158")
@Test
public void null_pointer_exception() throws Exception {
File gitDir = new File(".");
GitClient client = Git.with(TaskListener.NULL, new EnvVars()).in(gitDir).using("git").getClient();
ObjectId git260 = client.revParse(GIT_2_6_0_TAG);
AbstractGitSCMSource.SCMRevisionImpl rev260 =
new AbstractGitSCMSource.SCMRevisionImpl(new SCMHead("origin"), git260.getName());
GitSCMFileSystem.BuilderImpl.HeadNameResult result1 = GitSCMFileSystem.BuilderImpl.HeadNameResult.calculate(new BranchSpec("master-f"), rev260, null);
assertEquals("master-f", result1.headName);
assertEquals(Constants.R_HEADS, result1.prefix);
}

/** inline ${@link hudson.Functions#isWindows()} to prevent a transient remote classloader issue */
private boolean isWindows() {
return java.io.File.pathSeparatorChar==';';
Expand Down