Skip to content

Commit 71f1ffb

Browse files
committed
Add a wrapper for commit/push logic
Now, the wrapper prints the message before the commit and push begins, and proceeds to either print a success message or eprint the error before yielding it back. Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
1 parent 244ac85 commit 71f1ffb

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/git.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,7 @@ impl Repository {
186186
}
187187
}
188188

189-
fn commit_and_push(&self, msg: &str, modified_file: &Path) -> Result<(), PerformError> {
190-
println!("commit_and_push: Preparing \"{}\"", msg);
191-
189+
fn perform_commit_and_push(&self, msg: &str, modified_file: &Path) -> Result<(), PerformError> {
192190
// git add $file
193191
let mut index = self.repository.index()?;
194192
index.add_path(modified_file)?;
@@ -229,11 +227,20 @@ impl Repository {
229227
ref_status = Err("update_reference callback was not called".into());
230228
}
231229

232-
println!("commit_and_push: Finished with \"{}\"", msg);
233-
234230
ref_status
235231
}
236232

233+
pub fn commit_and_push(&self, message: &str, modified_file: &Path) -> Result<(), PerformError> {
234+
println!("Committing and pushing \"{}\"", message);
235+
236+
self.perform_commit_and_push(message, modified_file)
237+
.map(|_| println!("Commit and push finished for \"{}\"", message))
238+
.map_err(|err| {
239+
eprintln!("Commit and push errored: {}", err);
240+
err
241+
})
242+
}
243+
237244
pub fn reset_head(&self) -> Result<(), PerformError> {
238245
let mut origin = self.repository.find_remote("origin")?;
239246
origin.fetch(

0 commit comments

Comments
 (0)