@@ -29,7 +29,7 @@ pub fn get_repositories(path: &Path) -> Vec<PathBuf> {
29
29
repositories
30
30
}
31
31
32
- pub fn git_current_branch ( repository : PathBuf ) -> String {
32
+ pub fn git_current_branch ( repository : & Path ) -> String {
33
33
let command_string = "git rev-parse --abbrev-ref HEAD" ;
34
34
let ( command, args) = build_command ( command_string) ;
35
35
let ( error, output) = run_command ( command, args, repository) ;
@@ -47,7 +47,7 @@ pub fn sync_repository_to_branch(repository: PathBuf, branch: &str) {
47
47
println ! ( "!> Syncing repository: [{}]" , repo_name) ;
48
48
49
49
println ! ( "\t !> Running git fetch" ) ;
50
- git_fetch ( repository. to_path_buf ( ) ) ;
50
+ git_fetch ( & repository) ;
51
51
52
52
let should_stash = git_has_changes ( & repository) ;
53
53
@@ -57,14 +57,14 @@ pub fn sync_repository_to_branch(repository: PathBuf, branch: &str) {
57
57
}
58
58
59
59
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 ( ) ) ;
61
61
62
62
if !err. is_empty ( ) && err. contains ( "did not match any file(s) known to git" ) {
63
63
println ! ( "\t {}" , "!!> Branch does not exist on this repository" . red( ) ) ;
64
64
}
65
65
66
66
println ! ( "\t !> Running git pull" ) ;
67
- let ( err, _) = git_pull ( repository. to_path_buf ( ) ) ;
67
+ let ( err, _) = git_pull ( & repository) ;
68
68
69
69
if !err. is_empty ( ) && err. contains ( "but no such ref was fetched" ) {
70
70
println ! (
@@ -90,7 +90,7 @@ fn build_command(command: &str) -> (String, Vec<&str>) {
90
90
( command. to_string ( ) , args. to_vec ( ) )
91
91
}
92
92
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 ) {
94
94
let command = match Command :: new ( command) . current_dir ( cwd) . args ( args) . output ( ) {
95
95
Err ( err) => panic ! ( "Error running command [{}]" , err) ,
96
96
Ok ( cmd) => cmd,
@@ -104,18 +104,18 @@ fn run_command(command: String, args: Vec<&str>, cwd: PathBuf) -> (String, Strin
104
104
( error, output)
105
105
}
106
106
107
- fn git_checkout ( repository : PathBuf , branch : String ) -> ( String , String ) {
107
+ fn git_checkout ( repository : & Path , branch : String ) -> ( String , String ) {
108
108
let command_string = format ! ( "git checkout {}" , branch) ;
109
109
let ( command, args) = build_command ( & command_string) ;
110
110
run_command ( command, args, repository)
111
111
}
112
112
113
- fn git_pull ( repository : PathBuf ) -> ( String , String ) {
113
+ fn git_pull ( repository : & Path ) -> ( String , String ) {
114
114
let ( command, args) = build_command ( "git pull" ) ;
115
115
run_command ( command, args, repository)
116
116
}
117
117
118
- fn git_fetch ( repository : PathBuf ) -> ( String , String ) {
118
+ fn git_fetch ( repository : & Path ) -> ( String , String ) {
119
119
let command_string = "git fetch" ;
120
120
let ( command, args) = build_command ( command_string) ;
121
121
run_command ( command, args, repository)
@@ -124,13 +124,13 @@ fn git_fetch(repository: PathBuf) -> (String, String) {
124
124
fn git_stash ( repository : & Path ) -> ( String , String ) {
125
125
let command_string = "git stash save 'switcher:: changes'" ;
126
126
let ( command, args) = build_command ( command_string) ;
127
- run_command ( command, args, repository. to_path_buf ( ) )
127
+ run_command ( command, args, repository)
128
128
}
129
129
130
130
fn git_has_changes ( repository : & Path ) -> bool {
131
131
let command_string = "git status -s" ;
132
132
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) ;
134
134
135
135
!output. is_empty ( )
136
136
}
0 commit comments