Skip to content


Changed firstLine() method in GitAPI to ignore a trailing empty line #41

wants to merge 1 commit into from

4 participants


Trying to fix a problem in my build server. I suspect that the GitAPI.firstLine() method was overly strict. Here is an example of the console output:

00:01:23 Checkout:development / c:\development - hudson.remoting.LocalChannel@1f6f81b
00:01:23 Workspace has a .git repository, but it appears to be corrupt.
00:01:23 Cloning the remote Git repository
00:01:23 Cloning repository origin
00:01:23 Error trying to determine the git version: Result has multiple lines
00:01:23 Assuming 1.6
00:02:56 ERROR: Error cloning remote repo 'origin' : Could not clone gitolite@code:central-code
00:02:56 ERROR: Cause: Error performing command: C:\Apps\Git\cmd\git.cmd clone -o origin gitolite@code:central-code c:\development
00:02:56 null
00:02:56 Trying next repository
00:02:56 ERROR: Could not clone repository
00:02:56 FATAL: Could not clone
00:02:56 hudson.plugins.git.GitException: Could not clone
00:02:56 at hudson.plugins.git.GitSCM$2.invoke(
00:02:56 at hudson.plugins.git.GitSCM$2.invoke(
00:02:56 at hudson.FilePath.act(
00:02:56 at hudson.FilePath.act(
00:02:56 at hudson.plugins.git.GitSCM.checkout(
00:02:56 at hudson.model.AbstractProject.checkout(
00:02:56 at hudson.model.AbstractBuild$AbstractRunner.checkout(
00:02:56 at hudson.model.AbstractBuild$
00:02:56 at
00:02:56 at
00:02:56 at hudson.model.ResourceController.execute(
00:02:56 at

@rappazzo rappazzo closed this

May I know why this pull-request was closed ? I see that its a fix related to corrupt repositories issue. I was wondering why it was closed. Here are the (blocker)issues which are still open: and


Will this fix the issues : and these two were blocking issues for my project.


@rappazzo Any chance of you re-opening it / re-submitting it ? I also need this patch it would seem (without it cherry-picked I suffer from 'continuous' build attempts, with it cherry-picked into a custom local plugin I don't!)


I am not sure I know how to re-open it. You could just recreate the same change and make a pull request.


Okey dokey, will do (I'll add in cover for the leaked file-handles issue too) :) .. I'll make a branch based on yours so you still get credit though !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Showing with 7 additions and 13 deletions.
  1. +7 −13 src/main/java/hudson/plugins/git/
20 src/main/java/hudson/plugins/git/
@@ -264,19 +264,13 @@ public void prune(RemoteConfig repository) throws GitException {
private String firstLine(String result) {
- BufferedReader reader = new BufferedReader(new StringReader(result));
- String line;
- try {
- line = reader.readLine();
- if (line == null)
- return null;
- if (reader.readLine() != null)
- throw new GitException("Result has multiple lines");
- } catch (IOException e) {
- throw new GitException("Error parsing result", e);
- }
- return line;
+ String[] lines = result.split("(\\r?\\n)+");
+ if (lines[0].trim().isEmpty()) {
+ return null;
+ } else if (lines.length > 1) {
+ throw new GitException("Result has multiple lines");
+ }
+ return lines[0];
public void changelog(String revFrom, String revTo, OutputStream outputStream) throws GitException {
Something went wrong with that request. Please try again.