Skip to content

Commit

Permalink
Merge pull request #44 from emanuelez/fixgitcredentials
Browse files Browse the repository at this point in the history
[JENKINS-21016] Check for exceptions thrown in finally while deleting gitcredentials
  • Loading branch information
ndeloof committed Dec 19, 2013
2 parents bf641ce + a1c8960 commit 016d43a
Showing 1 changed file with 12 additions and 25 deletions.
37 changes: 12 additions & 25 deletions src/main/java/org/jenkinsci/plugins/gitclient/CliGitAPIImpl.java
Expand Up @@ -5,22 +5,13 @@
import com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl;
import edu.umd.cs.findbugs.annotations.CheckForNull;
import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.EnvVars;
import hudson.FilePath;
import hudson.Functions;
import hudson.Launcher;
import hudson.*;
import hudson.Launcher.LocalLauncher;
import hudson.Util;
import hudson.model.TaskListener;
import hudson.plugins.git.Branch;
import hudson.plugins.git.GitException;
import hudson.plugins.git.IGitAPI;
import hudson.plugins.git.IndexEntry;
import hudson.plugins.git.Revision;
import hudson.plugins.git.*;
import hudson.remoting.Callable;
import hudson.slaves.SlaveComputer;
import hudson.util.ArgumentListBuilder;
import hudson.util.IOUtils;
import hudson.util.Secret;
import org.apache.commons.httpclient.Credentials;
import org.apache.commons.httpclient.HttpClient;
Expand All @@ -45,15 +36,7 @@
import java.net.URI;
import java.net.URISyntaxException;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -976,8 +959,8 @@ private String launchCommandWithCredentials(ArgumentListBuilder args, File workD
if (credentials != null) {
listener.getLogger().println("using .gitcredentials to set credentials");

String urlWithCrendentials = getGitCrendentialsURL(url, credentials);
store = createGitCrendetialsStore(urlWithCrendentials);
String urlWithCredentials = getGitCrendentialsURL(url, credentials);
store = createGitCredentialsStore(urlWithCredentials);
launchCommandIn(workDir, "config", "--local", "credential.helper", "store --store=\"" + store.getAbsolutePath() + "\"");
}
}
Expand All @@ -991,15 +974,19 @@ private String launchCommandWithCredentials(ArgumentListBuilder args, File workD
if (ssh != null) ssh.delete();
if (store != null) {
store.delete();
launchCommandIn(workDir, "config", "--local", "--remove-section", "credential.helper");
try {
launchCommandIn(workDir, "config", "--local", "--unset", "credential.helper");
} catch (GitException e) {
listener.getLogger().println("Could not remove the credential.helper section from the git configuration");
}
}
}
}

private File createGitCrendetialsStore(String urlWithCrendentials) throws IOException {
private File createGitCredentialsStore(String urlWithCredentials) throws IOException {
File store = File.createTempFile("git", ".credentials");
PrintWriter w = new PrintWriter(store);
w.println(urlWithCrendentials);
w.println(urlWithCredentials);
w.flush();
w.close();
return store;
Expand Down

0 comments on commit 016d43a

Please sign in to comment.