|
|
@ -193,55 +193,40 @@ impl Vcs {
|
|
|
|
return Ok(());
|
|
|
|
return Ok(());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let current_profile = self.current_profile()?;
|
|
|
|
self.set_projects_using(profile_name, |project| {
|
|
|
|
|
|
|
|
project.switch_to_profile(profile_name)
|
|
|
|
for project in &mut self.projects {
|
|
|
|
})
|
|
|
|
let mut stashed_changes = false;
|
|
|
|
|
|
|
|
if let Some(current_profile_name) = ¤t_profile {
|
|
|
|
|
|
|
|
stashed_changes = project.repo.stash_changes(current_profile_name)?;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let ref_name = project.switch_to_profile(profile_name)?;
|
|
|
|
|
|
|
|
let unstashed_changes = project.repo.unstash_changes(profile_name)?;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
println!(
|
|
|
|
|
|
|
|
"{} set to {} {}{}",
|
|
|
|
|
|
|
|
project.name().bold().with(PROJECT_COLOR),
|
|
|
|
|
|
|
|
ref_name.with(REFS_COLOR),
|
|
|
|
|
|
|
|
if stashed_changes {
|
|
|
|
|
|
|
|
"«".cyan()
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
"".bold()
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
if unstashed_changes {
|
|
|
|
|
|
|
|
"»".dark_blue()
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
"".bold()
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
pub fn set_branch(&mut self, branch_name: &str) -> Result<(), Error> {
|
|
|
|
|
|
|
|
self.set_projects_using(branch_name, |project| project.repo.checkout(branch_name))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn set_branch(&mut self, branch_name: &str) -> Result<(), Error> {
|
|
|
|
fn set_projects_using<F>(&mut self, dest_name: &str, setter: F) -> Result<(), Error>
|
|
|
|
|
|
|
|
where
|
|
|
|
|
|
|
|
F: Fn(&mut Project) -> Result<String, Error>,
|
|
|
|
|
|
|
|
{
|
|
|
|
for project in &mut self.projects {
|
|
|
|
for project in &mut self.projects {
|
|
|
|
let current_ref = project.repo.current_ref()?;
|
|
|
|
let current_ref = project.repo.current_ref()?;
|
|
|
|
|
|
|
|
// stash changes before moving project off to a new ref
|
|
|
|
let stashed_changes = project.repo.stash_changes(¤t_ref)?;
|
|
|
|
let stashed_changes = project.repo.stash_changes(¤t_ref)?;
|
|
|
|
|
|
|
|
|
|
|
|
let new_ref = match project.repo.checkout(branch_name) {
|
|
|
|
// try to switch to new ref using provided setter
|
|
|
|
|
|
|
|
let new_ref = match setter(project) {
|
|
|
|
Ok(val) => val,
|
|
|
|
Ok(val) => val,
|
|
|
|
Err(err) => {
|
|
|
|
Err(err) => {
|
|
|
|
eprintln!(
|
|
|
|
eprintln!(
|
|
|
|
"{} unable to set {} ({})",
|
|
|
|
"{} unable to set {} ({})",
|
|
|
|
project.name().bold().with(PROJECT_COLOR),
|
|
|
|
project.name().bold().with(PROJECT_COLOR),
|
|
|
|
branch_name.with(REFS_COLOR),
|
|
|
|
dest_name.with(REFS_COLOR),
|
|
|
|
err.to_string().with(ERROR_COLOR),
|
|
|
|
err.to_string().with(ERROR_COLOR),
|
|
|
|
);
|
|
|
|
);
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
let unstashed_changes = project.repo.unstash_changes(branch_name)?;
|
|
|
|
|
|
|
|
|
|
|
|
// unstash changes if we had previously stashed any on this ref
|
|
|
|
|
|
|
|
let unstashed_changes = project.repo.unstash_changes(&new_ref)?;
|
|
|
|
|
|
|
|
|
|
|
|
println!(
|
|
|
|
println!(
|
|
|
|
"{} set to {} {}{}",
|
|
|
|
"{} set to {} {}{}",
|
|
|
@ -259,6 +244,7 @@ impl Vcs {
|
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|