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

Method checkout_branch

src/git_chain/core.rs:120–136  ·  view source on GitHub ↗
(&self, branch_name: &str)

Source from the content-addressed store, hash-verified

118 }
119
120 pub fn checkout_branch(&self, branch_name: &str) -> Result<(), Error> {
121 let (object, reference) = self.repo.revparse_ext(branch_name)?;
122
123 // set working directory
124 self.repo.checkout_tree(&object, None)?;
125
126 // set HEAD to branch_name
127 match reference {
128 // ref_name is an actual reference like branches or tags
129 Some(ref_name) => self.repo.set_head(ref_name.name().unwrap()),
130 // this is a commit, not a reference
131 None => self.repo.set_head_detached(object.id()),
132 }
133 .unwrap_or_else(|_| panic!("Failed to set HEAD to branch {}", branch_name));
134
135 Ok(())
136 }
137
138 pub fn git_branch_exists(&self, branch_name: &str) -> Result<bool, Error> {
139 Ok(self.git_local_branch_exists(branch_name)?

Callers 4

runFunction · 0.80
rebaseMethod · 0.80
backupMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected