Skip to content

Commit 5b93ba9

Browse files
committed
refactor(git): move sync single repository logic to separate function
1 parent ec60a94 commit 5b93ba9

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

src/git.rs

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::fs;
2-
use std::path::PathBuf;
32
use std::path::Path;
3+
use std::path::PathBuf;
44
use std::process::Command;
55

66
pub fn get_repositories(path: &Path) -> Vec<PathBuf> {
@@ -40,24 +40,28 @@ pub fn git_current_branch(repository: PathBuf) -> String {
4040
output
4141
}
4242

43-
pub fn sync_repositories_to_branch(repositories: &[PathBuf], branch: &str) {
44-
for repository in repositories {
45-
let repo_name = repository.file_name().unwrap().to_str().unwrap();
43+
pub fn sync_repository_to_branch(repository: PathBuf, branch: &str) {
44+
let repo_name = repository.file_name().unwrap().to_str().unwrap();
4645

47-
println!("!> Syncing repository: [{}]", repo_name);
46+
println!("!> Syncing repository: [{}]", repo_name);
4847

49-
println!("\t!> Running git fetch");
50-
git_fetch(repository.to_path_buf());
48+
println!("\t!> Running git fetch");
49+
git_fetch(repository.to_path_buf());
5150

52-
println!("\t!> Running git stash");
53-
git_stash(repository.to_path_buf());
51+
println!("\t!> Running git stash");
52+
git_stash(repository.to_path_buf());
5453

55-
println!("\t!> Running git checkout {}", &branch);
56-
git_checkout(repository.to_path_buf(), branch.to_string());
54+
println!("\t!> Running git checkout {}", &branch);
55+
git_checkout(repository.to_path_buf(), branch.to_string());
5756

58-
println!("\t!> Running git pull");
59-
git_pull(repository.to_path_buf());
60-
println!("\n");
57+
println!("\t!> Running git pull");
58+
git_pull(repository.to_path_buf());
59+
println!("\n");
60+
}
61+
62+
pub fn sync_repositories_to_branch(repositories: &[PathBuf], branch: &str) {
63+
for repository in repositories {
64+
sync_repository_to_branch(repository.to_path_buf(), branch)
6165
}
6266
}
6367

0 commit comments

Comments
 (0)