Skip to content
Permalink
Browse files
JENKINS-20991 - Sanitize rev-parse output with trimToNull()
  • Loading branch information
Evildethow authored and MarkEWaite committed Mar 6, 2016
1 parent 79b749a commit a9f57aa55e42f7af7ebced7bc73a336582bcdded
Showing with 7 additions and 7 deletions.
  1. +7 −7 src/main/java/org/jenkinsci/plugins/gitclient/CliGitAPIImpl.java
@@ -676,10 +676,10 @@ public ObjectId revParse(String revName) throws GitException, InterruptedExcepti

String arg = sanitize(revName + "^{commit}");
String result = launchCommand("rev-parse", arg);
String line = firstLine(result);
String line = StringUtils.trimToNull(result);
if (line == null)
throw new GitException("rev-parse no content returned for " + revName);
return ObjectId.fromString(line.trim());
return ObjectId.fromString(line);
}

/**
@@ -729,10 +729,10 @@ private String sanitize(String arg) {
*/
public ObjectId validateRevision(String revName) throws GitException, InterruptedException {
String result = launchCommand("rev-parse", "--verify", revName);
String line = firstLine(result);
String line = StringUtils.trimToNull(result);
if (line == null)
throw new GitException("null first line from rev-parse(" + revName +")");
return ObjectId.fromString(line.trim());
throw new GitException("null result from rev-parse(" + revName +")");
return ObjectId.fromString(line);
}

/** {@inheritDoc} */
@@ -1101,11 +1101,11 @@ public boolean isBareRepository(String GIT_DIR) throws GitException, Interrupted
String gitDir = "--git-dir=" + GIT_DIR;
ret = launchCommand(gitDir, "rev-parse", "--is-bare-repository");
}
String line = firstLine(ret);
String line = StringUtils.trimToNull(ret);
if (line == null)
throw new GitException("No output from bare repository check for " + GIT_DIR);

return !"false".equals(line.trim());
return !"false".equals(line);
}

public boolean isShallowRepository() {

0 comments on commit a9f57aa

Please sign in to comment.