Skip to content

Commit

Permalink
feat(git): add Branch::rename method
Browse files Browse the repository at this point in the history
Not used now, but might be used in the future to generate local-friendly branch names for the Github forge.
  • Loading branch information
arxanas committed Feb 11, 2024
1 parent 18a5d29 commit b3b204a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
12 changes: 12 additions & 0 deletions git-branchless-lib/src/git/reference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,18 @@ impl<'repo> Branch<'repo> {
}
}

/// Rename the branch. The new name should not start with `refs/heads`.
#[instrument]
pub fn rename(&mut self, new_name: &str, force: bool) -> Result<()> {
self.inner
.rename(new_name, force)
.map_err(|err| Error::RenameBranch {
source: err,
new_name: new_name.to_owned(),
})?;
Ok(())
}

/// Delete the branch.
#[instrument]
pub fn delete(&mut self) -> Result<()> {
Expand Down
6 changes: 6 additions & 0 deletions git-branchless-lib/src/git/repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,12 @@ pub enum Error {
name: ReferenceName,
},

#[error("could not rename branch to '{new_name}': {source}")]
RenameBranch {
source: git2::Error,
new_name: String,
},

#[error("could not delete branch: {0}")]
DeleteBranch(#[source] git2::Error),

Expand Down

0 comments on commit b3b204a

Please sign in to comment.