Skip to content

Commit

Permalink
status: show untracked files
Browse files Browse the repository at this point in the history
  • Loading branch information
cstoitner committed Dec 25, 2024
1 parent 0bc388a commit 6c0c158
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 1 deletion.
4 changes: 3 additions & 1 deletion cli/src/commands/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use std::io;

use itertools::Itertools;
use jj_lib::copies::CopyRecords;
use jj_lib::repo::Repo;
Expand Down Expand Up @@ -47,7 +49,7 @@ pub(crate) fn cmd_status(
command: &CommandHelper,
args: &StatusArgs,
) -> Result<(), CommandError> {
let (workspace_command, _snapshot_stats) = command.workspace_helper_with_stats(ui)?;
let (workspace_command, snapshot_stats) = command.workspace_helper_with_stats(ui)?;
let repo = workspace_command.repo();
let maybe_wc_commit = workspace_command
.get_wc_commit_id()
Expand Down
1 change: 1 addition & 0 deletions cli/src/config/colors.toml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
"diff added" = { fg = "green" }
"diff token" = { underline = true }
"diff modified" = "cyan"
"diff untracked" = "magenta"
"diff renamed" = "cyan"
"diff copied" = "green"
"diff access-denied" = { bg = "red" }
Expand Down
66 changes: 66 additions & 0 deletions cli/tests/test_status_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,3 +368,69 @@ fn test_status_simplify_conflict_sides() {
Then run `jj squash` to move the resolution into the conflicted commit.
"###);
}

#[test]
fn test_status_untracked_files() {
let test_env = TestEnvironment::default();
test_env.add_config(r#"snapshot.auto-track = "none()""#);

test_env.jj_cmd_ok(test_env.env_root(), &["git", "init", "repo"]);
let repo_path = test_env.env_root().join("repo");

std::fs::write(repo_path.join("initially-untracked-file"), "...").unwrap();
std::fs::write(repo_path.join("always-untracked-file"), "...").unwrap();

let stdout = test_env.jj_cmd_success(&repo_path, &["status"]);
insta::assert_snapshot!(stdout, @r"
Untracked paths:
? always-untracked-file
? initially-untracked-file
Working copy : qpvuntsm 230dd059 (empty) (no description set)
Parent commit: zzzzzzzz 00000000 (empty) (no description set)
");

test_env.jj_cmd_success(&repo_path, &["file", "track", "initially-untracked-file"]);

let stdout = test_env.jj_cmd_success(&repo_path, &["status"]);
insta::assert_snapshot!(stdout, @r"
Working copy changes:
A initially-untracked-file
Untracked paths:
? always-untracked-file
Working copy : qpvuntsm 203bfea9 (no description set)
Parent commit: zzzzzzzz 00000000 (empty) (no description set)
");

test_env.jj_cmd_ok(&repo_path, &["new"]);

let stdout = test_env.jj_cmd_success(&repo_path, &["status"]);
insta::assert_snapshot!(stdout, @r"
Untracked paths:
? always-untracked-file
Working copy : mzvwutvl 69b48d55 (empty) (no description set)
Parent commit: qpvuntsm 203bfea9 (no description set)
");

test_env.jj_cmd_success(&repo_path, &["file", "untrack", "initially-untracked-file"]);
let stdout = test_env.jj_cmd_success(&repo_path, &["status"]);
insta::assert_snapshot!(stdout, @r"
Working copy changes:
D initially-untracked-file
Untracked paths:
? always-untracked-file
? initially-untracked-file
Working copy : mzvwutvl 16169825 (no description set)
Parent commit: qpvuntsm 203bfea9 (no description set)
");

test_env.jj_cmd_ok(&repo_path, &["new"]);

let stdout = test_env.jj_cmd_success(&repo_path, &["status"]);
insta::assert_snapshot!(stdout, @r"
Untracked paths:
? always-untracked-file
? initially-untracked-file
Working copy : yostqsxw 9b87b665 (empty) (no description set)
Parent commit: mzvwutvl 16169825 (no description set)
");
}

0 comments on commit 6c0c158

Please sign in to comment.