Skip to content

Commit 581b4c5

Browse files
committed
status: show untracked files
1 parent b696d98 commit 581b4c5

File tree

3 files changed

+78
-1
lines changed

3 files changed

+78
-1
lines changed

cli/src/commands/status.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
use std::io;
16+
1517
use itertools::Itertools;
1618
use jj_lib::copies::CopyRecords;
1719
use jj_lib::repo::Repo;
@@ -47,7 +49,7 @@ pub(crate) fn cmd_status(
4749
command: &CommandHelper,
4850
args: &StatusArgs,
4951
) -> Result<(), CommandError> {
50-
let (workspace_command, _snapshot_stats) = command.workspace_helper_with_stats(ui)?;
52+
let (workspace_command, snapshot_stats) = command.workspace_helper_with_stats(ui)?;
5153
let repo = workspace_command.repo();
5254
let maybe_wc_commit = workspace_command
5355
.get_wc_commit_id()
@@ -85,6 +87,16 @@ pub(crate) fn cmd_status(
8587
)?;
8688
}
8789

90+
// TODO: make sure this always display all untracked non-ignored files, even
91+
// when using watchman. See https://github.com/jj-vcs/jj/commit/168c7979feab40d58f49fe19683975697a7bc089 for details.
92+
formatter.with_label("diff", |formatter| {
93+
for path in snapshot_stats.untracked_paths.keys() {
94+
let ui_path = workspace_command.path_converter().format_file_path(path);
95+
writeln!(formatter.labeled("untracked"), "? {ui_path}")?;
96+
}
97+
io::Result::Ok(())
98+
})?;
99+
88100
// TODO: Conflicts should also be filtered by the `matcher`. See the related
89101
// TODO on `MergedTree::conflicts()`.
90102
let conflicts = wc_commit.tree()?.conflicts().collect_vec();

cli/src/config/colors.toml

+1
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
"diff added" = { fg = "green" }
9494
"diff token" = { underline = true }
9595
"diff modified" = "cyan"
96+
"diff untracked" = "magenta"
9697
"diff renamed" = "cyan"
9798
"diff copied" = "green"
9899
"diff access-denied" = { bg = "red" }

cli/tests/test_status_command.rs

+64
Original file line numberDiff line numberDiff line change
@@ -368,3 +368,67 @@ fn test_status_simplify_conflict_sides() {
368368
Then run `jj squash` to move the resolution into the conflicted commit.
369369
"###);
370370
}
371+
372+
#[test]
373+
fn test_status_untracked_files() {
374+
let test_env = TestEnvironment::default();
375+
test_env.add_config(r#"snapshot.auto-track = "none()""#);
376+
377+
test_env.jj_cmd_ok(test_env.env_root(), &["git", "init", "repo"]);
378+
let repo_path = test_env.env_root().join("repo");
379+
380+
std::fs::write(repo_path.join("initially-untracked-file"), "...").unwrap();
381+
std::fs::write(repo_path.join("always-untracked-file"), "...").unwrap();
382+
383+
let stdout = test_env.jj_cmd_success(&repo_path, &["status"]);
384+
insta::assert_snapshot!(stdout, @r"
385+
The working copy is clean
386+
? always-untracked-file
387+
? initially-untracked-file
388+
Working copy : qpvuntsm 230dd059 (empty) (no description set)
389+
Parent commit: zzzzzzzz 00000000 (empty) (no description set)
390+
");
391+
392+
test_env.jj_cmd_success(&repo_path, &["file", "track", "initially-untracked-file"]);
393+
394+
let stdout = test_env.jj_cmd_success(&repo_path, &["status"]);
395+
insta::assert_snapshot!(stdout, @r"
396+
Working copy changes:
397+
A initially-untracked-file
398+
? always-untracked-file
399+
Working copy : qpvuntsm 203bfea9 (no description set)
400+
Parent commit: zzzzzzzz 00000000 (empty) (no description set)
401+
");
402+
403+
test_env.jj_cmd_ok(&repo_path, &["new"]);
404+
405+
let stdout = test_env.jj_cmd_success(&repo_path, &["status"]);
406+
insta::assert_snapshot!(stdout, @r"
407+
The working copy is clean
408+
? always-untracked-file
409+
Working copy : mzvwutvl 69b48d55 (empty) (no description set)
410+
Parent commit: qpvuntsm 203bfea9 (no description set)
411+
");
412+
413+
test_env.jj_cmd_success(&repo_path, &["file", "untrack", "initially-untracked-file"]);
414+
let stdout = test_env.jj_cmd_success(&repo_path, &["status"]);
415+
insta::assert_snapshot!(stdout, @r"
416+
Working copy changes:
417+
D initially-untracked-file
418+
? always-untracked-file
419+
? initially-untracked-file
420+
Working copy : mzvwutvl 16169825 (no description set)
421+
Parent commit: qpvuntsm 203bfea9 (no description set)
422+
");
423+
424+
test_env.jj_cmd_ok(&repo_path, &["new"]);
425+
426+
let stdout = test_env.jj_cmd_success(&repo_path, &["status"]);
427+
insta::assert_snapshot!(stdout, @r"
428+
The working copy is clean
429+
? always-untracked-file
430+
? initially-untracked-file
431+
Working copy : yostqsxw 9b87b665 (empty) (no description set)
432+
Parent commit: mzvwutvl 16169825 (no description set)
433+
");
434+
}

0 commit comments

Comments
 (0)