Skip to content

Commit

Permalink
Merge pull request #467 from jglick/CredentialsMatchers.withId-NPE
Browse files Browse the repository at this point in the history
[JENKINS-40382] GitSCMFileSystem mistakes
  • Loading branch information
MarkEWaite committed Jan 14, 2017
2 parents fc384d9 + 70b40c3 commit f57167e
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/main/java/jenkins/plugins/git/GitSCMFileSystem.java
Expand Up @@ -236,6 +236,9 @@ public boolean supports(SCMSource source) {
@Override
public SCMFileSystem build(@NonNull Item owner, @NonNull SCM scm, @CheckForNull SCMRevision rev)
throws IOException, InterruptedException {
if (rev != null && !(rev instanceof AbstractGitSCMSource.SCMRevisionImpl)) {
return null;
}
TaskListener listener = new LogTaskListener(LOGGER, Level.FINE);
GitSCM gitSCM = (GitSCM) scm;
UserRemoteConfig config = gitSCM.getUserRemoteConfigs().get(0);
Expand All @@ -252,19 +255,22 @@ public SCMFileSystem build(@NonNull Item owner, @NonNull SCM scm, @CheckForNull
git.using(tool.getGitExe());
}
GitClient client = git.getClient();
client.addDefaultCredentials(CredentialsMatchers.firstOrNull(
CredentialsProvider.lookupCredentials(
String credentialsId = config.getCredentialsId();
if (credentialsId != null) {
client.addDefaultCredentials(CredentialsMatchers.firstOrNull(
CredentialsProvider.lookupCredentials(
StandardUsernameCredentials.class,
owner,
ACL.SYSTEM,
URIRequirementBuilder.fromUri(remote).build()
),
CredentialsMatchers.allOf(
CredentialsMatchers.withId(config.getCredentialsId()),
),
CredentialsMatchers.allOf(
CredentialsMatchers.withId(credentialsId),
GitClient.CREDENTIALS_MATCHER
)
)
)
);
);
}
if (!client.hasGitRepo()) {
listener.getLogger().println("Creating git repository in " + cacheDir);
client.init();
Expand Down Expand Up @@ -305,6 +311,9 @@ public SCMFileSystem build(@NonNull Item owner, @NonNull SCM scm, @CheckForNull
@Override
public SCMFileSystem build(@NonNull SCMSource source, @NonNull SCMHead head, @CheckForNull SCMRevision rev)
throws IOException, InterruptedException {
if (rev != null && !(rev instanceof AbstractGitSCMSource.SCMRevisionImpl)) {
return null;
}
TaskListener listener = new LogTaskListener(LOGGER, Level.INFO);
AbstractGitSCMSource gitSCMSource = (AbstractGitSCMSource) source;
String cacheEntry = gitSCMSource.getCacheEntry();
Expand Down

0 comments on commit f57167e

Please sign in to comment.