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

Đang mở Phù hợp với người mới
#297 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

@hardikyadav12 đang làm issue này rồi.

Từ ngày 16/9/2026.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
74/100
Loại issue
Tính năng
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
java
Lĩnh vực
api

Hướng nghiên cứu

Bắt đầu với phương thức create(boolean bare) trong org.eclipse.jgit.api.Repository (org.eclipse.jgit/src/org/eclipse/jgit/api/Repository.java) và các nơi gọi nó, bao gồm các test dựa trên FileRepositoryBuilder dưới org.eclipse.jgit.test. Thêm overload không đối số ủy quyền cho create(isBare()), quyết định xem create(boolean) có bị đánh dấu deprecated hay không, và chạy các test tạo repository cùng bất kỳ kiểm tra API/tương thích nào mà dự án sử dụng. Xong nghĩa là overload tồn tại, các vị trí gọi hiện tại vẫn biên dịch được, và trạng thái trên đĩa (bare/non-bare) khớp với isBare().

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
Java
Star
427
Fork
116
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của eclipse-jgit/jgit

Tất cả issue của eclipse-jgit/jgit

Issue tương tự

Thêm issue về Java

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.