Repository.create(boolean bare) should provide a no-arg overload that uses isBare()
@hardikyadav12 已经在做这个了。
开始于 2026年9月16日。
评估
调研方向
从 org.eclipse.jgit.api.Repository (org.eclipse.jgit/src/org/eclipse/jgit/api/Repository.java) 中的 create(boolean bare) 方法及其调用者开始,包括 org.eclipse.jgit.test 下基于 FileRepositoryBuilder 的测试。添加委托给 create(isBare()) 的无参数重载,决定是否将 create(boolean) 标记为弃用,并运行仓库创建测试以及项目使用的任何 API/兼容性检查。完成意味着该重载存在、现有调用点仍能编译,且磁盘上的 bare/non-bare 状态与 isBare() 一致。
由索引模型根据 Issue 内容生成。
描述
Description
Repository.create(boolean bare) requires the caller to supply the bare flag
explicitly, even though the repository object already knows whether it is bare —
isBare() returns exactly that value, set by the builder via setBare() /
setWorkTree(…).
This creates a subtle footgun: a caller who builds a repository via
FileRepositoryBuilder and correctly sets .setBare() must still remember to pass
the same information again when calling create(), or the result is an inconsistency
between the on-disk layout and what the already-open Repository object reports.
// Consistent but redundant — caller must repeat what the builder already knows:
Repository repo = new FileRepositoryBuilder().setGitDir(dir).setBare().build();
repo.create(repo.isBare());
// If the caller forgets or passes the wrong value, the state is inconsistent:
repo.create(false); // creates a non-bare repo on disk, but repo.isBare() == true
Motivation
A no-arg Repository.create() overload that delegates to create(isBare()) would
remove the redundancy and eliminate the inconsistency risk. The existing
create(boolean bare) can stay for backward compatibility (might be marked deprecated), but the no-arg form
should become the canonical way to initialize a repository whose bare/non-bare nature
was already decided at build time.
Alternatives considered
Calling create(repository.isBare()) by hand — which is what callers currently must
do. This works, but requires knowing the idiom and is easy to get wrong (passing
true hardcoded is a common mistake for code that only tests with bare repositories).
Additional context
Encountered while implementing a utility that accepts a BaseRepositoryBuilder<?, R>
to let the caller control repository configuration. Before the fix, it called
repository.create(true) unconditionally, silently producing wrong behavior for
non-bare builds.
- 主要语言
- Java
- 星标
- 427
- 派生
- 116
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
eclipse-jgit/jgit 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 83/100
eclipse-jgit/jgit#329 ·
-
难度 2/5 1-3 小时 新手友好度 77/100
eclipse-jgit/jgit#327 ·
-
难度 2/5 1-3 小时 新手友好度 83/100
eclipse-jgit/jgit#293 · 2 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 72/100
eclipse-jgit/jgit#288 ·
-
难度 2/5 1-3 小时 新手友好度 72/100
eclipse-jgit/jgit#273 · 1 条评论 ·
查看 eclipse-jgit/jgit 的全部 Issue
相似的 Issue
-
? - Needs Triage bot_watch bug
难度 2/5 1-3 小时 新手友好度 78/100
NVIDIA/cudf-spark-jni#5594 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 92/100
-
难度 2/5 1-3 小时 新手友好度 75/100
维护者通常 1 天内回复
-
bug
难度 1/5 1 小时以内 新手友好度 88/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100
DataONEorg/dataone-indexer#390 ·