Skip to content

Commit 82d635c

Browse files
committed
refactor(git): change PathBuf to &Path
1 parent 1c8284a commit 82d635c

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

src/core/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ pub fn print(program: ProgramInfo) {
126126
print!("\t\t\t\t{}", name);
127127

128128
if detail {
129-
let current_branch = git_current_branch(repository.to_path_buf());
129+
let current_branch = git_current_branch(repository);
130130
// TODO properly handle the perfect alignment of the tabs
131131
println!(" ({})", current_branch.yellow());
132132
} else {

src/core/git.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub fn get_repositories(path: &Path) -> Vec<PathBuf> {
2929
repositories
3030
}
3131

32-
pub fn git_current_branch(repository: PathBuf) -> String {
32+
pub fn git_current_branch(repository: &Path) -> String {
3333
let command_string = "git rev-parse --abbrev-ref HEAD";
3434
let (command, args) = build_command(command_string);
3535
let (error, output) = run_command(command, args, repository);
@@ -47,7 +47,7 @@ pub fn sync_repository_to_branch(repository: PathBuf, branch: &str) {
4747
println!("!> Syncing repository: [{}]", repo_name);
4848

4949
println!("\t!> Running git fetch");
50-
git_fetch(repository.to_path_buf());
50+
git_fetch(&repository);
5151

5252
let should_stash = git_has_changes(&repository);
5353

@@ -57,14 +57,14 @@ pub fn sync_repository_to_branch(repository: PathBuf, branch: &str) {
5757
}
5858

5959
println!("\t!> Running git checkout {}", &branch);
60-
let (err, _) = git_checkout(repository.to_path_buf(), branch.to_string());
60+
let (err, _) = git_checkout(&repository, branch.to_string());
6161

6262
if !err.is_empty() && err.contains("did not match any file(s) known to git") {
6363
println!("\t{}", "!!> Branch does not exist on this repository".red());
6464
}
6565

6666
println!("\t!> Running git pull");
67-
let (err, _) = git_pull(repository.to_path_buf());
67+
let (err, _) = git_pull(&repository);
6868

6969
if !err.is_empty() && err.contains("but no such ref was fetched") {
7070
println!(
@@ -90,7 +90,7 @@ fn build_command(command: &str) -> (String, Vec<&str>) {
9090
(command.to_string(), args.to_vec())
9191
}
9292

93-
fn run_command(command: String, args: Vec<&str>, cwd: PathBuf) -> (String, String) {
93+
fn run_command(command: String, args: Vec<&str>, cwd: &Path) -> (String, String) {
9494
let command = match Command::new(command).current_dir(cwd).args(args).output() {
9595
Err(err) => panic!("Error running command [{}]", err),
9696
Ok(cmd) => cmd,
@@ -104,18 +104,18 @@ fn run_command(command: String, args: Vec<&str>, cwd: PathBuf) -> (String, Strin
104104
(error, output)
105105
}
106106

107-
fn git_checkout(repository: PathBuf, branch: String) -> (String, String) {
107+
fn git_checkout(repository: &Path, branch: String) -> (String, String) {
108108
let command_string = format!("git checkout {}", branch);
109109
let (command, args) = build_command(&command_string);
110110
run_command(command, args, repository)
111111
}
112112

113-
fn git_pull(repository: PathBuf) -> (String, String) {
113+
fn git_pull(repository: &Path) -> (String, String) {
114114
let (command, args) = build_command("git pull");
115115
run_command(command, args, repository)
116116
}
117117

118-
fn git_fetch(repository: PathBuf) -> (String, String) {
118+
fn git_fetch(repository: &Path) -> (String, String) {
119119
let command_string = "git fetch";
120120
let (command, args) = build_command(command_string);
121121
run_command(command, args, repository)
@@ -124,13 +124,13 @@ fn git_fetch(repository: PathBuf) -> (String, String) {
124124
fn git_stash(repository: &Path) -> (String, String) {
125125
let command_string = "git stash save 'switcher:: changes'";
126126
let (command, args) = build_command(command_string);
127-
run_command(command, args, repository.to_path_buf())
127+
run_command(command, args, repository)
128128
}
129129

130130
fn git_has_changes(repository: &Path) -> bool {
131131
let command_string = "git status -s";
132132
let (command, args) = build_command(command_string);
133-
let (_, output) = run_command(command, args, repository.to_path_buf());
133+
let (_, output) = run_command(command, args, repository);
134134

135135
!output.is_empty()
136136
}

0 commit comments

Comments
 (0)