From 31b90af066926e4e5847aa2a71362a4a3e5f00f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hannes=20K=C3=B6rber?= Date: Tue, 4 Jan 2022 12:22:02 +0100 Subject: [PATCH] Properly report status on worktree repos --- src/repo.rs | 6 +----- src/table.rs | 31 +++++++++++++++++-------------- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/src/repo.rs b/src/repo.rs index 91a5b01..d277f1a 100644 --- a/src/repo.rs +++ b/src/repo.rs @@ -790,11 +790,7 @@ impl Repo { }; let changes = match is_worktree { - true => { - return Err(String::from( - "Cannot get changes as this is a bare worktree repository", - )) - } + true => None, false => { let statuses = self .0 diff --git a/src/table.rs b/src/table.rs index 6fa7ed2..3ea818d 100644 --- a/src/table.rs +++ b/src/table.rs @@ -30,21 +30,24 @@ fn add_repo_status( true => "\u{2714}", false => "", }, - &match repo_status.changes { - Some(changes) => { - let mut out = Vec::new(); - if changes.files_new > 0 { - out.push(format!("New: {}\n", changes.files_new)) + &match is_worktree { + true => String::from(""), + false => match repo_status.changes { + Some(changes) => { + let mut out = Vec::new(); + if changes.files_new > 0 { + out.push(format!("New: {}\n", changes.files_new)) + } + if changes.files_modified > 0 { + out.push(format!("Modified: {}\n", changes.files_modified)) + } + if changes.files_deleted > 0 { + out.push(format!("Deleted: {}\n", changes.files_deleted)) + } + out.into_iter().collect::().trim().to_string() } - if changes.files_modified > 0 { - out.push(format!("Modified: {}\n", changes.files_modified)) - } - if changes.files_deleted > 0 { - out.push(format!("Deleted: {}\n", changes.files_deleted)) - } - out.into_iter().collect::().trim().to_string() - } - None => String::from("\u{2714}"), + None => String::from("\u{2714}"), + }, }, repo_status .branches