MCPcopy Create free account
hub / github.com/dashed/git-chain / backup

Method backup

src/git_chain/operations.rs:223–269  ·  view source on GitHub ↗
(&self, chain_name: &str)

Source from the content-addressed store, hash-verified

221 Ok(())
222 }
223 pub fn backup(&self, chain_name: &str) -> Result<(), Error> {
224 if Chain::chain_exists(self, chain_name)? {
225 let chain = Chain::get_chain(self, chain_name)?;
226
227 // ensure repository is in a clean state
228 match self.repo.state() {
229 RepositoryState::Clean => {
230 // go ahead to back up chain.
231 }
232 _ => {
233 eprintln!(
234 "🛑 Repository needs to be in a clean state before backing up chain: {}",
235 chain_name
236 );
237 process::exit(1);
238 }
239 }
240
241 if self.dirty_working_directory()? {
242 eprintln!(
243 "🛑 Unable to back up branches for the chain: {}",
244 chain.name.bold()
245 );
246 eprintln!("You have uncommitted changes in your working directory.");
247 eprintln!("Please commit or stash them.");
248 process::exit(1);
249 }
250
251 let orig_branch = self.get_current_branch_name()?;
252
253 chain.backup(self)?;
254
255 let current_branch = self.get_current_branch_name()?;
256
257 if current_branch != orig_branch {
258 println!("Switching back to branch: {}", orig_branch.bold());
259 self.checkout_branch(&orig_branch)?;
260 }
261
262 println!("🎉 Successfully backed up chain: {}", chain.name.bold());
263 } else {
264 eprintln!("Unable to back up chain.");
265 eprintln!("Chain does not exist: {}", chain_name);
266 process::exit(1);
267 }
268 Ok(())
269 }
270 pub fn push(&self, chain_name: &str, force_push: bool) -> Result<(), Error> {
271 if Chain::chain_exists(self, chain_name)? {
272 let chain = Chain::get_chain(self, chain_name)?;

Callers

nothing calls this directly

Calls 3

checkout_branchMethod · 0.80

Tested by

no test coverage detected