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 摘要。