A3: add untracked files to .gitignore from the Changes context menu

git.ignore appends one anchored, escaped literal pattern per path to the
work tree root's .gitignore, skipping patterns already there. The Changes
window gets a row context menu (right click, Shift+F10, context-menu key)
with Open and Add to .gitignore.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
danny 2026-10-31 14:33:42 +01:00
parent ce681871ad
commit 68599fa2ac
14 changed files with 633 additions and 5 deletions

View file

@ -1,7 +1,7 @@
//! The merge commands through the engine with pending outcomes:
//! `git.merge` up to date, with conflicts and refused; `git.conflictVersions`;
//! `git.markResolved` and `git.mergeAbort`, each followed by `gitChanged`;
//! bad params. Skips with a message when git is not installed.
//! `git.mergeMessage`; `git.ignore` (C7 A3); bad params. Skips with a message when git is not installed.
#![allow(
clippy::unwrap_used,
@ -198,6 +198,8 @@ fn bad_params_and_no_project() {
("git.merge", json!({"branch": "-x"})),
("git.markResolved", json!({"paths": []})),
("git.conflictVersions", json!({"path": 3})),
("git.ignore", json!({"paths": []})),
("git.ignore", json!({"paths": ["../x"]})),
] {
assert!(
matches!(
@ -216,3 +218,32 @@ fn bad_params_and_no_project() {
Err(EngineError::Disabled(_))
));
}
#[test]
fn ignore_appends_a_literal_pattern_and_refreshes() {
if !have_git() {
return;
}
let dir = tempfile::tempdir().unwrap();
let root = dir.path();
conflicting(root);
std::fs::write(root.join("debug[1].log"), "x").unwrap();
std::fs::write(root.join("debug1.log"), "x").unwrap();
let host = Host::open(root);
host.git_changes();
let out = host
.run("git.ignore", json!({"paths": ["debug[1].log"]}))
.unwrap();
assert_eq!(out["patterns"].as_array().unwrap().len(), 1);
assert_eq!(host.git_changes(), 1);
let status = host.run("git.status", Value::Null).unwrap();
let paths: Vec<&str> = status["files"]
.as_array()
.unwrap()
.iter()
.map(|f| f["path"].as_str().unwrap())
.collect();
assert!(paths.contains(&"debug1.log"), "{paths:?}");
assert!(paths.contains(&".gitignore"), "{paths:?}");
assert!(!paths.contains(&"debug[1].log"), "{paths:?}");
}