Skip to content

Loading…

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

Closed
wants to merge 1 commit into from

4 participants

@rappazzo

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(GitSCM.java:1042)
00:02:56 at hudson.plugins.git.GitSCM$2.invoke(GitSCM.java:968)
00:02:56 at hudson.FilePath.act(FilePath.java:758)
00:02:56 at hudson.FilePath.act(FilePath.java:740)
00:02:56 at hudson.plugins.git.GitSCM.checkout(GitSCM.java:968)
00:02:56 at hudson.model.AbstractProject.checkout(AbstractProject.java:1193)
00:02:56 at hudson.model.AbstractBuild$AbstractRunner.checkout(AbstractBuild.java:555)
00:02:56 at hudson.model.AbstractBuild$AbstractRunner.run(AbstractBuild.java:443)
00:02:56 at hudson.model.Run.run(Run.java:1376)
00:02:56 at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:46)
00:02:56 at hudson.model.ResourceController.execute(ResourceController.java:88)
00:02:56 at hudson.model.Executor.run(Executor.java:175)

@rappazzo rappazzo closed this
@none-da

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: https://issues.jenkins-ci.org/browse/JENKINS-11535 and https://issues.jenkins-ci.org/browse/JENKINS-11547

@chandramuralis

Will this fix the issues : https://issues.jenkins-ci.org/browse/JENKINS-11535 and https://issues.jenkins-ci.org/browse/JENKINS-11547? these two were blocking issues for my project.

@rappazzo
@rappazzo
@ciaranj

@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!)

@rappazzo

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

@ciaranj

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/GitAPI.java
View
20 src/main/java/hudson/plugins/git/GitAPI.java
@@ -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.