Repository.create(boolean bare) should provide a no-arg overload that uses isBare()

未关闭 适合新手
#297 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

@hardikyadav12 已经在做这个了。

开始于 2026年9月16日。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
74/100
Issue 类型
功能
描述清晰度
描述清楚
活跃度
活跃
技术栈
java
领域
api

调研方向

从 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

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

eclipse-jgit/jgit 的其他 Issue

查看 eclipse-jgit/jgit 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。