JGit SubmoduleDeinitCommand can delete files from a dirty requested submodule

未關閉 適合新手
#293 2 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

評估

難度
2/5
預估耗時
1-3 小時
新手友好度
83/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
java
領域
api

研究方向

從 org.eclipse.jgit/src/org/eclipse/jgit/api/SubmoduleDeinitCommand.java 開始:checkDirty()(大約 L194-L210)開啟一個未過濾的 SubmoduleWalk.forIndex(repo),且只檢查第一個 index 條目,因此必須將其限制為透過 addPath() 給定的路徑。閱讀 call()(L92-L111)與 deinit()(L140-L152),以了解 DIRTY 狀態如何管控遞迴刪除。在 org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule 底下新增一個測試,包含兩個共用同一個 object ID 的 submodule 條目,其中只有被要求的路徑是 dirty;當它回傳 SubmoduleDeinitStatus.DIRTY、untracked 檔案仍然存在,且既有的 deinit 測試仍然通過時即算完成。

由索引模型根據 Issue 內容生成。

描述

Version

v7.8.0.202609011348-r-10-g87ec21000

Operating System

Linux/Unix

Bug description

SubmoduleDeinitCommand can deinitialize a dirty requested submodule without
force when another earlier submodule entry records the same object ID.

The command is expected to check the requested path and refuse to remove its
worktree when it contains local changes. In the reproducing repository,
submodules a and b both point to the same commit. a is clean and b
contains an untracked file. The call below requests only b and does not call
setForce(true):

new SubmoduleDeinitCommand(db).addPath("b").call();

call() initially walks the requested path, but checkDirty() then opens a
second SubmoduleWalk.forIndex(repo) without a path filter and examines only
the first index entry. Because a appears before b and has the same object
ID, the status of clean submodule a is used for the requested path b.
The command consequently proceeds to deinit("b"), which recursively deletes
the contents of b.

Relevant source at the tested revision:

Actual behavior

The requested dirty submodule is reported as successfully deinitialized, and
its untracked file is deleted even though force was not requested:

OBSERVED deinit requested=b status=SUCCESS dirty_file_exists=false

The control case, with only submodule b present, correctly detects the same
dirty file:

CONTROL deinit only=b status=DIRTY dirty_file_exists=true
Expected behavior

Because b contains local modifications and force was not requested, the
command should return SubmoduleDeinitStatus.DIRTY for b and leave all files
under b intact. This is also the behavior documented by setForce(false).

Relevant log output
OBSERVED deinit requested=b status=SUCCESS dirty_file_exists=false
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
BUILD SUCCESS

CONTROL deinit only=b status=DIRTY dirty_file_exists=true
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
BUILD SUCCESS
Other information

The standalone reproducer is included in the accompanying archive:

  • reproduce.sh copies reproduce_test.java into
    org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule, runs the two tests,
    records the environment and revision, and removes the temporary test source
    and generated test artifacts.
  • The test source is
    org.eclipse.jgit.submodule.SubmoduleDeinitReproductionTest.
  • Run it from the repository root with:
findings/submodules/jgit-deinit-unfiltered-dirty-check/reproduce.sh \
  findings/submodules/jgit-deinit-unfiltered-dirty-check/evidence/20260909

The effective Maven command uses -Pjavac -pl org.eclipse.jgit.test -am and
the following environment was used:

Git 2.39.5
Java openjdk version "17.0.20.1" 2026-08-18
Maven 3.8.7

The issue causes local data loss: uncommitted, untracked, generated, or other
files in the requested submodule can be removed by a non-forced deinit. The
demonstration requires two submodule entries with the same recorded object ID,
an initialized dirty target submodule, and an application or user invoking
deinit for that target. It does not demonstrate deletion outside the requested
submodule, code execution, privilege escalation, or a remote-only trigger.

The complete reproduction output is in
evidence/20260909/run.log. The implementation contract is documented by
setForce(),
which states that deinitialization should refuse local modifications unless
force is enabled.

Attachments

jgit-deinit-unfiltered-dirty-check.zip

主要語言
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 摘要。