diff options
author | edram <edram@qq.com> | 2021-10-22 14:54:03 +0800 |
---|---|---|
committer | edram <edram@qq.com> | 2021-10-22 14:54:03 +0800 |
commit | e8b6c55ab9a33b609672cd08cec6bad7c1312d0f (patch) | |
tree | cb1b11b1d614b8b7f2d7100e8316728c15141972 /src | |
parent | 4f701485740a487249491ae6f49a1ddeaae0f116 (diff) | |
download | gitblit-e8b6c55ab9a33b609672cd08cec6bad7c1312d0f.tar.gz gitblit-e8b6c55ab9a33b609672cd08cec6bad7c1312d0f.zip |
Fix mirrored http(s) with a username and password
This fixes #1059
Diffstat (limited to 'src')
-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;
|