diff options
author | Florian Zschocke <2362065+flaix@users.noreply.github.com> | 2021-10-22 20:05:15 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-22 20:05:15 +0200 |
commit | 4f04ab8ec402dd51bbdb7121d89da2d9a385f1a8 (patch) | |
tree | db9c8226c8802aefdc24ec7e9e25b9046975de14 /src/main | |
parent | 9d297ab016f200df28a08354ec2c1533e07c5ca0 (diff) | |
parent | e8b6c55ab9a33b609672cd08cec6bad7c1312d0f (diff) | |
download | gitblit-4f04ab8ec402dd51bbdb7121d89da2d9a385f1a8.tar.gz gitblit-4f04ab8ec402dd51bbdb7121d89da2d9a385f1a8.zip |
Merge pull request #1381 from edram/master
Fix mirrored http(s) with a username and password
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/com/gitblit/service/MirrorService.java | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/main/java/com/gitblit/service/MirrorService.java b/src/main/java/com/gitblit/service/MirrorService.java index cf9ccb55..eb247fc0 100644 --- a/src/main/java/com/gitblit/service/MirrorService.java +++ b/src/main/java/com/gitblit/service/MirrorService.java @@ -27,11 +27,14 @@ import org.eclipse.jgit.api.Git; 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;
@@ -146,7 +149,12 @@ public class MirrorService implements Runnable { 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;
|