我最近尝试了 JGit 的 S3 远程提供程序,它非常有用。
编辑:有关删除整个回购协议传输的声明,请参阅评论。然而,这并没有改变我在这里的主要问题。
所以现在我正在考虑有效地使用它,这让我想到了以下问题:
您是否使用 S3 上托管的 Git 存储库(不仅用于备份,还用于协作)?
是否可以对存储库进行加密?我知道 JGit 的默认 DES 加密,但我不想依赖古老的加密算法。
这种解决方案的优点和缺点是什么?
感谢您的意见!
我们有一个 gitolite 服务器,其中包含我们的客户定制应用程序。
每个应用程序都有一个子模块“存储库/核心”,它指的是我们的基础应用程序。
我们现在想要创建一个仪表板,显示所有客户的应用程序以及核心所在的版本。
gitolite 将所有内容存储在磁盘上的裸存储库中,仪表板应用程序可以直接访问存储库/或使用 ssh 密钥(如果更容易的话)。
我的问题是,如何从裸存储库中找出子模块所在的修订版以及谁提交了它?
即使不推荐,我也使用具体方法a:
git commit -m 'xxxx' file 1 file2
Run Code Online (Sandbox Code Playgroud)
索引和更改的两个文件都将成为提交的一部分。但不是例如 file3 和 file4 也被更改 - 但未在提交中命名。
问题:我如何使用 JGit 来做到这一点!甚至 Eclipse 也提供了这一点 - 但我没有找到任何使用 JGit (瓷器)来实现这一点的方法。
我可以通过 JGit 从 GitLab 克隆,但是当我去推送更改时,我收到一条not authorized错误消息。
三个更重要的细节:
我拥有该存储库,因此只读访问不存在问题。
该存储库是私有的,因此我知道 OAuth 2 令牌是有效的并且正在初始克隆中使用。
我只有用户名和 oauth2 令牌。我没有用户的密码、SSH 密钥或个人访问令牌。
这是我的克隆命令:
Git.cloneRepository()
.setURI(target)
.setDirectory(repoFolder)
.setCloneAllBranches(true)
.setCredentialsProvider(new UsernamePasswordCredentialsProvider("oauth2", token))
.call();
Run Code Online (Sandbox Code Playgroud)
这是我的推送命令:
PushCommand push = cloneSource.push();
push.setRemote(target);
push.setPushAll();
push.setCredentialsProvider(new UsernamePasswordCredentialsProvider("oauth2", token));
push.call();
Run Code Online (Sandbox Code Playgroud) 我一直在尝试使用JGIT和JIMFS使用类似的方法将一个小型 git 配置存储库克隆到内存中
FileSystem fs = Jimfs.newFileSystem(Configuration.unix());
Path gitPath = Files.createDirectories(fs.getPath("/git"));
Git.cloneRepository().setURI(...).setBranch(...).setDirectory(gitPath.toFile())
.setCredentialsProvider(...).call()
Run Code Online (Sandbox Code Playgroud)
但由于 JIMFS 使用路径Path API(因为它不使用默认的文件系统),而 JGIT 使用File API,因此 JIMFS 不实现 toFile() 调用:
@Override
public File toFile() {
// documented as unsupported for anything but the default file system
throw new UnsupportedOperationException();
}
Run Code Online (Sandbox Code Playgroud)
所以我得到的是这个UnsupportedOperationException。有没有一种简单的方法可以让这个(或类似的)设置工作而无需求助于磁盘上的临时目录?
我想读取某个分支中某个提交处的文件内容:我目前正在使用此代码来读取某个提交处的文件内容,忽略该分支。
public static String readContentOfFileAtCommit(String commitStr, String fileName)
throws IOException {
String content = null;
ObjectId lastCommitId = currentRepo.resolve(commitStr);
try (RevWalk revWalk = new RevWalk(currentRepo)) {
RevCommit commit = revWalk.parseCommit(lastCommitId);
RevTree tree = commit.getTree();
try (TreeWalk treeWalk = new TreeWalk(currentRepo)) {
treeWalk.addTree(tree);
treeWalk.setRecursive(true);
treeWalk.setFilter(PathFilter.create(fileName));
if (!treeWalk.next()) {
throw new IllegalStateException("Did not find expected file:" + fileName);
}
ObjectId objectId = treeWalk.getObjectId(0);
ObjectLoader loader = currentRepo.open(objectId);
content = new String(loader.getBytes());
}
revWalk.dispose();
}
return content;
}
Run Code Online (Sandbox Code Playgroud)
我的目标是在某个分支上完成的某个提交中获取文件的内容。
我正在使用 Java 并使用 jGit 创建一个应用程序。作为其中的一部分,我需要对用户进行身份验证。我想输出用户是否存在。目前我得到一个例外,如user is not authorized. 下面是我的代码。
import java.io.File;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider;
public class AuthenticateanUser {
public static void main(String[] args) throws Exception {
final String REMOTE_URL = "https://myRepo.git";
// prepare a new folder for the cloned repository
File localPath = File.createTempFile("TestGitRepository", "");
localPath.delete();
// then clone
try (Git result = Git.cloneRepository().setURI(REMOTE_URL)
.setCredentialsProvider(new UsernamePasswordCredentialsProvider("myId", "myPwd"))
.setDirectory(localPath).call()) {
System.out.println("Having repository: " + result.status());
}
}
}
Run Code Online (Sandbox Code Playgroud)
当我运行上面的代码时,如果我提供正确的凭据,我得到的输出为
Having repository:XXXXX
Run Code Online (Sandbox Code Playgroud)
如果我提供错误的凭据,我会收到错误消息
Exception in thread "main" org.eclipse.jgit.api.errors.TransportException: https://myRepo.git: …Run Code Online (Sandbox Code Playgroud) 我正在开发一个 Git 客户端,现在我正在尝试实现特定分支的签出。我有一个填充了分支名称的组合框,我想找出哪个分支是默认分支,以便在连接到有效的 Git 存储库时可以将其设置为组合框中的预选项目。
我列出了所有远程分支,如下所示,但我无法弄清楚哪个是默认分支。
Map<String, Ref> callAsMap = Git.lsRemoteRepository()
.setRemote("https://github.com/example")
.setCredentialsProvider(credentialsProvider)
.callAsMap();
Run Code Online (Sandbox Code Playgroud)
那么,有没有一种方法(标准或“hacky”)来检测哪个Ref对象代表默认分支?我怎样才能得到它的名字?
有没有办法用 JGit 设置提交时间?
翻了翻API,发现只能通过修改本地系统时间来完成。我想通过代码来实现它。并且可以在win系统上正常运行。
在我们开始之前:我是新手,所以我很抱歉
快速描述:
我有一个 Jira 插件,可以跟踪所选 git 提供程序中指定存储库的当前状态,例如 GitHub(跟踪提交、分支等)并将其显示在 JIRA 问题视图中
我需要检查我添加到插件的存储库是私有的还是公共的。如果是私人的,我需要请求其凭据。
有没有办法在 Java 中检查这种情况(例如通过 JGit)?
PS 我通过 HTTPS 链接将存储库添加到我的插件中