From 64f333e0abb5a51afc966a39967ec1c97248bd4e Mon Sep 17 00:00:00 2001 From: Dinesh Date: Tue, 21 Apr 2020 09:55:15 +0530 Subject: [PATCH] [Dinesh] Show relativePath in the result for better readability --- src/fetch.rs | 4 +++- src/git.rs | 10 +++++++++- src/status.rs | 8 ++++++-- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/fetch.rs b/src/fetch.rs index 27fa431..a0aaf15 100644 --- a/src/fetch.rs +++ b/src/fetch.rs @@ -56,6 +56,7 @@ pub fn fetch(args: InputArgs, filter_list: Vec) { .map(|dir| GitFetch { dir, remote: "origin".to_string(), + root: root.to_string(), }) .for_each(|clone| multi_bars.start_task(clone)); @@ -93,11 +94,12 @@ fn get_ssh_value(path: String) -> Result { pub struct GitFetch { dir: PathBuf, remote: String, + root: String } impl<'a> GitAction for GitFetch { fn get_name(&self) -> String { - format!("{} from {:?}", self.remote, self.dir) + format!("{} from {:?}", self.remote, Self::relative_path(&self.dir, &self.root)) } fn git_action(&mut self, prog: &ProgressReporter) -> Result { diff --git a/src/git.rs b/src/git.rs index 3c52eab..868d494 100644 --- a/src/git.rs +++ b/src/git.rs @@ -1,10 +1,18 @@ -use crate::progress::ProgressReporter; +use std::path::PathBuf; + use git2::Error; +use crate::progress::ProgressReporter; + pub trait GitAction { fn git_action(&mut self, prog: &ProgressReporter) -> Result; fn get_name(&self) -> String; + fn relative_path(dir: &PathBuf, root: &String) -> String { + let relative_path = dir.to_string_lossy().to_string().replace(root, ""); + format!(".{}", relative_path) + } + fn do_git_action(&mut self, prog: ProgressReporter) { prog.start(); match self.git_action(&prog) { diff --git a/src/status.rs b/src/status.rs index 2a9df9b..5bcb209 100644 --- a/src/status.rs +++ b/src/status.rs @@ -50,18 +50,22 @@ pub fn status(args: InputArgs, filter_list: Vec) { } }) }) - .map(|dir| GitStatus { dir }) + .map(|dir| GitStatus { + dir, + root: root.to_string() + }) .for_each(|status| multi_bars.start_task(status)); multi_bars.join().unwrap(); } pub struct GitStatus { dir: PathBuf, + root: String } impl<'a> GitAction for GitStatus { fn get_name(&self) -> String { - self.dir.to_string_lossy().to_string() + Self::relative_path(&self.dir, &self.root) } fn git_action(&mut self, _progress: &ProgressReporter) -> Result {