Skip to content

Commit d06bd3a

Browse files
committed
feat(git): add Branch::rename method
Not used now, but might be used in the future to generate local-friendly branch names for the Github forge.
1 parent a881c0e commit d06bd3a

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

git-branchless-lib/src/git/reference.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,18 @@ impl<'repo> Branch<'repo> {
332332
}
333333
}
334334

335+
/// Rename the branch. The new name should not start with `refs/heads`.
336+
#[instrument]
337+
pub fn rename(&mut self, new_name: &str, force: bool) -> Result<()> {
338+
self.inner
339+
.rename(new_name, force)
340+
.map_err(|err| Error::RenameBranch {
341+
source: err,
342+
new_name: new_name.to_owned(),
343+
})?;
344+
Ok(())
345+
}
346+
335347
/// Delete the branch.
336348
#[instrument]
337349
pub fn delete(&mut self) -> Result<()> {

git-branchless-lib/src/git/repo.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,12 @@ pub enum Error {
167167
name: ReferenceName,
168168
},
169169

170+
#[error("could not rename branch to '{new_name}': {source}")]
171+
RenameBranch {
172+
source: git2::Error,
173+
new_name: String,
174+
},
175+
170176
#[error("could not delete branch: {0}")]
171177
DeleteBranch(#[source] git2::Error),
172178

0 commit comments

Comments
 (0)