Tôi có đoạn code sau đây (xem các ý kiến về những gì đang xảy ra):JGit đặt git: URI thay vì https: cho từ xa trên circleCI
// Clone repository from GitHub into a local directory.
Git git = Git.cloneRepository()
.setBranch("gh-pages")
.setURI("https://github.com/RAnders00/KayonDoc.git")
.setDirectory(new File("/home/ubuntu/KayonDoc"))
.call();
// Print out remotes in config from JGit
Config config = git.getRepository().getConfig();
config.getSubsections("remote").forEach(it -> {
System.out.println(config.getString("remote", it, "url"));
});
// Prints https://github.com/RAnders00/KayonDoc.git
// Everything seems OK
// You could perform some changes to the repository here...
// Push changes to origin
git.push()
.setCredentialsManager(new UsernamePasswordCredentialsProvider("RAnders00", "hunter2"))
.call();
// Throws exception (look below)
Caught: org.eclipse.jgit.api.errors.TransportException: [email protected]:RAnders00/KayonDoc.git: push not permitted
org.eclipse.jgit.api.errors.TransportException: [email protected]:RAnders00/KayonDoc.git: push not permitted
at org.eclipse.jgit.api.PushCommand.call(PushCommand.java:164)
at org.eclipse.jgit.api.PushCommand.call(PushCommand.java:80)
at <your class> (YourClass.java:?)
Caused by: org.eclipse.jgit.errors.TransportException: [email protected]:RAnders00/KayonDoc.git: push not permitted
at org.eclipse.jgit.transport.BasePackPushConnection.noRepository(BasePackPushConnection.java:176)
at org.eclipse.jgit.transport.BasePackConnection.readAdvertisedRefsImpl(BasePackConnection.java:200)
at org.eclipse.jgit.transport.BasePackConnection.readAdvertisedRefs(BasePackConnection.java:178)
at org.eclipse.jgit.transport.TransportGitSsh$SshPushConnection.<init>(TransportGitSsh.java:341)
at org.eclipse.jgit.transport.TransportGitSsh.openPush(TransportGitSsh.java:166)
at org.eclipse.jgit.transport.PushProcess.execute(PushProcess.java:154)
at org.eclipse.jgit.transport.Transport.push(Transport.java:1200)
at org.eclipse.jgit.api.PushCommand.call(PushCommand.java:157)
... 3 more
JGit được lưu url git:
vào .git/FETCH_HEAD
tệp, sau đó được sử dụng để đẩy. Vì giao thức git:
không hỗ trợ xác thực, tôi không thể đẩy đến điều khiển từ xa và quá trình không thành công.
Tệp .git/config
chứa đúng https:
URI cho điều khiển từ xa (đó là lý do mã được in https:
URI).
Câu hỏi của tôi là:
Những gì tôi có thể làm để làm cho JGit thiết lập https:
URI đúng
(mà sau đó sẽ cho phép tôi để đẩy một lần nữa)?
Vấn đề này chỉ xuất hiện trong một môi trường rất đặc biệt (trên circleCI, một hộp ảo Ubuntu 12.04.2 LTS) - nó không reproducable trên 15.10, 14.04 LTS và 12.04.2 LTS phân phối ubuntu tươi và không reproducable trên Các cửa sổ.
Cách dễ nhất để tái tạo sự cố là create kho lưu trữ GitHub giả, sau đó start building dự án giả của bạn trên CircleCI, sau đó chạy lại bản dựng đầu tiên của bạn bằng SSH. Sau đó bạn có 30 phút thời gian SSH để tải lên bất kỳ tệp groovy/java nào vào hộp. Sau 30 phút, hộp sẽ bị đóng chặt.
Nếu tôi sử dụng git remote -v
trong thư mục này đã được nhân bản thành, tôi nhận được: (mà chỉ tôi đến một thực tế là git:
URI được thực sự sử dụng)
origin [email protected]:RAnders00/KayonDoc.git (fetch)
origin [email protected]:RAnders00/KayonDoc.git (push)
Tôi có thể xác nhận rằng trên Windows URL https vẫn còn nguyên vẹn. Nếu đây không phải là trường hợp với Linux nó có vẻ như một lỗi và tôi sẽ [nộp một bugzilla] (https://eclipse.org/jgit/support/). –
Có, tuy nhiên, xem nhanh mã không hiển thị lý do rõ ràng cho điều này, cấu hình được tạo từ URL mà bạn đặt mà không cần bất kỳ điều chỉnh nào của lược đồ.Có lẽ bạn có thể thực hiện gỡ lỗi nhanh chóng vào JGit trên máy của mình để loại trừ một số cách sử dụng API không chính xác trong mã của bạn ... – centic
nếu tôi là bạn, tôi chỉ sử dụng giao thức git với các khóa ssh – AdamSkywalker