affaan-m/ECC · warning

cannot reset hunks for untracked files

Error message

cannot reset hunks for untracked files

What it means

reset_hunk discards a hunk's changes by reverse-applying its patch, but untracked files have no diff hunks that git can reverse against an index — they are entirely new content. The library rejects the operation up front for any entry flagged untracked rather than letting git fail confusingly.

Solutions

  1. Check entry.untracked before offering/calling reset_hunk; discard untracked files by deleting them instead.
  2. Use file-level reset_path semantics appropriately, or remove the file from disk for full discard of untracked content.
  3. Filter untracked entries out of hunk-level action menus in the UI.

Example fix

// before
reset_hunk(&worktree, &entry, &hunk)?;

// after
if entry.untracked {
    std::fs::remove_file(worktree.path.join(&entry.path))?;
} else {
    reset_hunk(&worktree, &entry, &hunk)?;
}
Defensive patterns

Strategy: validation

Validate before calling

if entry.untracked {
    // discard untracked content by deleting instead
    std::fs::remove_file(worktree.path.join(&entry.path))?;
    return Ok(());
}

Type guard

fn is_hunk_resettable(entry: &GitStatusEntry) -> bool { !entry.untracked }

Try / catch

match reset_hunk(&worktree, &entry, &hunk) {
    Ok(()) => refresh_patch_view(),
    Err(e) if e.to_string().contains("untracked") => {
        std::fs::remove_file(worktree.path.join(&entry.path))?;
    }
    Err(e) => eprintln!("reset hunk failed: {e:#}"),
}

Prevention

When it happens

Trigger: Calling reset_hunk(worktree, entry, hunk) where entry.untracked == true, i.e. the file was created after HEAD and appears in the untracked section of the status/patch view.

Common situations: Showing 'discard hunk' actions for untracked files in a diff UI; hunk list built from untracked content but fed into the tracked-file reset path.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of affaan-m/ECC@8321021c54 (2026-09-16). Data as JSON: /api/errors/7357b323b26afff1. Report an issue: GitHub.

Appendix: source

Thrown at ecc2/src/worktree/mod.rs:432

pub fn unstage_hunk(worktree: &WorktreeInfo, hunk: &GitPatchHunk) -> Result<()> {
    if hunk.section != GitPatchSectionKind::Staged {
        anyhow::bail!("selected hunk is not staged");
    }
    git_apply_patch(
        &worktree.path,
        &["-R", "--cached"],
        &hunk.patch,
        "unstage selected hunk",
    )
}

pub fn reset_hunk(
    worktree: &WorktreeInfo,
    entry: &GitStatusEntry,
    hunk: &GitPatchHunk,
) -> Result<()> {
    if entry.untracked {
        anyhow::bail!("cannot reset hunks for untracked files");
    }

    match hunk.section {
        GitPatchSectionKind::Unstaged => {
            git_apply_patch(&worktree.path, &["-R"], &hunk.patch, "reset selected hunk")
        }
        GitPatchSectionKind::Staged => {
            if entry.unstaged {
                anyhow::bail!(
                    "cannot reset a staged hunk while the file also has unstaged changes; unstage it first"
                );
            }
            git_apply_patch(
                &worktree.path,
                &["-R", "--index"],
                &hunk.patch,
                "reset selected staged hunk",
            )

View on GitHub (pinned to 8321021c54)