Skip to content

Show relativePath in the result for better readability #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/fetch.rs
Original file line number Diff line number Diff line change
@@ -56,6 +56,7 @@ pub fn fetch(args: InputArgs, filter_list: Vec<Regex>) {
.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<Cred, GitError> {
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<String, GitError> {
10 changes: 9 additions & 1 deletion src/git.rs
Original file line number Diff line number Diff line change
@@ -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<String, Error>;
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) {
8 changes: 6 additions & 2 deletions src/status.rs
Original file line number Diff line number Diff line change
@@ -50,18 +50,22 @@ pub fn status(args: InputArgs, filter_list: Vec<Regex>) {
}
})
})
.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<String, GitError> {