Skip to content

Commit

Permalink
Merge pull request #1381 from edram/master
Browse files Browse the repository at this point in the history
Fix mirrored http(s) with a username and password
  • Loading branch information
flaix authored Oct 22, 2021
2 parents 9d297ab + e8b6c55 commit 4f04ab8
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/main/java/com/gitblit/service/MirrorService.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,14 @@
import org.eclipse.jgit.lib.RefUpdate.Result;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.StoredConfig;
import org.eclipse.jgit.transport.CredentialsProvider;
import org.eclipse.jgit.transport.FetchResult;
import org.eclipse.jgit.transport.ReceiveCommand;
import org.eclipse.jgit.transport.ReceiveCommand.Type;
import org.eclipse.jgit.transport.RemoteConfig;
import org.eclipse.jgit.transport.TrackingRefUpdate;
import org.eclipse.jgit.transport.URIish;
import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -146,7 +149,12 @@ public void run() {
logger.debug("checking {} remote {} for ref updates", repositoryName, mirror.getName());
final boolean testing = false;
Git git = new Git(repository);
FetchResult result = git.fetch().setRemote(mirror.getName()).setDryRun(testing).call();
CredentialsProvider creds = null;
URIish fetchUri = mirror.getURIs().get(0);
if (fetchUri.getUser() != null && fetchUri.getPass() != null) {
creds = new UsernamePasswordCredentialsProvider(fetchUri.getUser(), fetchUri.getPass());
}
FetchResult result = git.fetch().setCredentialsProvider(creds).setRemote(mirror.getName()).setDryRun(testing).call();
Collection<TrackingRefUpdate> refUpdates = result.getTrackingRefUpdates();
if (refUpdates.size() > 0) {
ReceiveCommand ticketBranchCmd = null;
Expand Down

0 comments on commit 4f04ab8

Please sign in to comment.