Skip to content
Open
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
81 changes: 48 additions & 33 deletions src/main/java/org/jenkinsci/plugins/gitclient/CliGitAPIImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,6 @@
EnvVars environment;
private Map<String, StandardCredentials> credentials = new HashMap<>();
private StandardCredentials defaultCredentials;
private StandardCredentials lfsCredentials;
private final String encoding;

/* If we fail some helper tool (e.g. SELinux chcon) do not make noise
Expand Down Expand Up @@ -680,10 +679,7 @@
}
}

StandardCredentials cred = credentials.get(url);
if (cred == null) {
cred = defaultCredentials;
}
StandardCredentials cred = getCredentials(url);
launchCommandWithCredentials(args, workspace, cred, url);
}

Expand Down Expand Up @@ -3177,23 +3173,49 @@
args.add("-f");
}
args.add(ref);
launchCommandIn(args, workspace, checkoutEnv, timeout);

StandardCredentials cred = null;
String checkoutUrl = null;
if (isAtLeastVersion(2, 27, 0, 0)) {

Check warning on line 3179 in src/main/java/org/jenkinsci/plugins/gitclient/CliGitAPIImpl.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 3179 is only partially covered, one branch is missing
String result = firstLine(launchCommand(
"config", "--get", "--default", "''", "remote.origin.partialclonefilter"));
if (result != null && !result.isBlank()) {

Check warning on line 3182 in src/main/java/org/jenkinsci/plugins/gitclient/CliGitAPIImpl.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 3182 is only partially covered, 2 branches are missing
checkoutUrl = launchCommand("config", "--get", "--default", "''", "remote.origin.url")
.trim(); // TODO: how to get the url correctly (and compatible with the

Check warning on line 3184 in src/main/java/org/jenkinsci/plugins/gitclient/CliGitAPIImpl.java

View check run for this annotation

ci.jenkins.io / Open Tasks Scanner

TODO

NORMAL: how to get the url correctly (and compatible with the
// unit tests)?
// checkoutUrl = getRemoteUrl("origin"); // fails with unit tests
if (checkoutUrl.isBlank()) {

Check warning on line 3187 in src/main/java/org/jenkinsci/plugins/gitclient/CliGitAPIImpl.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 3187 is only partially covered, one branch is missing
checkoutUrl = null;

Check warning on line 3188 in src/main/java/org/jenkinsci/plugins/gitclient/CliGitAPIImpl.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 3188 is not covered by tests
} else {
cred = getCredentials(checkoutUrl);
}
}
}

if (cred != null) {

Check warning on line 3195 in src/main/java/org/jenkinsci/plugins/gitclient/CliGitAPIImpl.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 3195 is only partially covered, one branch is missing
try {
// credentials are needed for instance for blobless clone and are simply not used in
// "standard" cases
launchCommandWithCredentials(args, workspace, cred, new URIish(checkoutUrl), timeout);
} catch (URISyntaxException e) {
throw new GitException("Invalid URL " + checkoutUrl, e);
}

Check warning on line 3202 in src/main/java/org/jenkinsci/plugins/gitclient/CliGitAPIImpl.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 3199-3202 are not covered by tests
} else {
launchCommandIn(args, workspace, checkoutEnv, timeout);
}

if (lfsRemote != null) {
final String url = getRemoteUrl(lfsRemote);
StandardCredentials cred = lfsCredentials;
if (cred == null) {
cred = credentials.get(url);
}
if (cred == null) {
cred = defaultCredentials;
StandardCredentials lfsCred = lfsCredentials;
if (lfsCred == null) {

Check warning on line 3210 in src/main/java/org/jenkinsci/plugins/gitclient/CliGitAPIImpl.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 3210 is only partially covered, one branch is missing
lfsCred = getCredentials(url);
}
ArgumentListBuilder lfsArgs = new ArgumentListBuilder();
lfsArgs.add("lfs");
lfsArgs.add("pull");
lfsArgs.add(lfsRemote);
try {
launchCommandWithCredentials(lfsArgs, workspace, cred, new URIish(url), timeout);
launchCommandWithCredentials(lfsArgs, workspace, lfsCred, new URIish(url), timeout);
} catch (URISyntaxException e) {
throw new GitException("Invalid URL " + url, e);
}
Expand Down Expand Up @@ -3740,10 +3762,7 @@
args.add("-h");
addCheckedRemoteUrl(args, url);

StandardCredentials cred = credentials.get(url);
if (cred == null) {
cred = defaultCredentials;
}
StandardCredentials cred = getCredentials(url);

String result = launchCommandWithCredentials(args, null, cred, url);

Expand All @@ -3768,10 +3787,7 @@
args.add("-h");
}

StandardCredentials cred = credentials.get(url);
if (cred == null) {
cred = defaultCredentials;
}
StandardCredentials cred = getCredentials(url);

addCheckedRemoteUrl(args, url);

Expand Down Expand Up @@ -3800,10 +3816,7 @@
args.add(pattern);
}

StandardCredentials cred = credentials.get(url);
if (cred == null) {
cred = defaultCredentials;
}
StandardCredentials cred = getCredentials(url);

String result = launchCommandWithCredentials(args, null, cred, url);

Expand Down Expand Up @@ -3843,10 +3856,7 @@
args.add(pattern);
}

StandardCredentials cred = credentials.get(url);
if (cred == null) {
cred = defaultCredentials;
}
StandardCredentials cred = getCredentials(url);

String result = launchCommandWithCredentials(args, null, cred, url);

Expand Down Expand Up @@ -3886,10 +3896,7 @@
ArgumentListBuilder args = new ArgumentListBuilder();
URIish uri = repository.getURIs().get(0);
String url = uri.toPrivateString();
StandardCredentials cred = credentials.get(url);
if (cred == null) {
cred = defaultCredentials;
}
StandardCredentials cred = getCredentials(url);

args.add("push");
addCheckedRemoteUrl(args, url);
Expand Down Expand Up @@ -3992,6 +3999,14 @@
return false;
}

private StandardCredentials getCredentials(String url) {
StandardCredentials cred = credentials.get(url);
if (cred == null) {

Check warning on line 4004 in src/main/java/org/jenkinsci/plugins/gitclient/CliGitAPIImpl.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 4004 is only partially covered, one branch is missing
cred = defaultCredentials;
}
return cred;
}

/** {@inheritDoc} */
@Override
public Set<GitObject> getTags() throws GitException, InterruptedException {
Expand Down
Loading