1 use std::io::{Result, Error, ErrorKind};
2 use std::process::Command;
5 pub fn git_save_previous_branch(path: &Path) -> Result<String> {
6 let output = Command::new("git")
12 if !output.status.success() {
13 Err(Error::new(ErrorKind::Other, "Failed to get current branch"))
15 Ok(String::from_utf8(output.stdout).unwrap().trim().to_string())
19 pub fn git_checkout(path: &Path, branch: &str) -> Result<()> {
20 let output = Command::new("git")
25 if !output.status.success() {
26 Err(Error::new(ErrorKind::Other, format!("Failed to checkout {}", branch)))
32 pub fn git_fetch(path: &Path) -> Result<()> {
33 let output = Command::new("git")
37 if !output.status.success() {
38 return Err(Error::new(ErrorKind::Other, "Failed to fetch"));
43 pub fn git_check_for_conflicts(path: &Path) -> Result<bool> {
44 let merge_output = Command::new("git")
51 if !merge_output.status.success() {
52 return Err(Error::new(ErrorKind::Other, "Failed to merge"));
54 let conflicts_output = Command::new("git")
64 Ok(!conflicts_output.stdout.is_empty())
67 pub fn git_merge(path: &Path) -> Result<()> {
68 let output = Command::new("git")
73 if !output.status.success() {
74 Err(Error::new(ErrorKind::Other, "Failed to merge"))
80 pub fn git_push(path: &Path) -> Result<()> {
81 let output = Command::new("git")
87 if !output.status.success() {
88 Err(Error::new(ErrorKind::Other, "Failed to push to origin"))
94 pub fn get_commit(path: &Path, revision: &str) -> Result<String> {
95 let output = Command::new("git")
101 if !output.status.success() {
102 Err(Error::new(ErrorKind::Other, "Failed to get current commit"))
104 Ok(String::from_utf8(output.stdout).unwrap().trim().to_string())