diff options
Diffstat (limited to 'server/common')
| -rw-r--r-- | server/common/src/git.rs | 13 | ||||
| -rw-r--r-- | server/common/src/tests.rs | 19 |
2 files changed, 31 insertions, 1 deletions
diff --git a/server/common/src/git.rs b/server/common/src/git.rs index 74c3247..ac0bdb3 100644 --- a/server/common/src/git.rs +++ b/server/common/src/git.rs @@ -326,6 +326,12 @@ impl RepoData { .await } + async fn delete_branch(&self, repo: &Repository, branch: &str) -> Result<(), Error> { + let mut cmd = self.git_cmd(repo); + cmd.arg("branch").arg("--delete").arg("--force").arg(branch); + self.run(&mut cmd).await + } + async fn get_log_format( &self, repo: &Repository, @@ -564,4 +570,11 @@ impl Repository { data.get_commiter(self, commit.as_str()).await } + + pub async fn delete_branch(&self, branch: impl Into<String>) -> Result<(), Error> { + let branch = branch.into(); + let data = self.lock.read().await; + + data.delete_branch(self, branch.as_str()).await + } } diff --git a/server/common/src/tests.rs b/server/common/src/tests.rs index f08ca44..41f44fe 100644 --- a/server/common/src/tests.rs +++ b/server/common/src/tests.rs @@ -202,7 +202,7 @@ async fn git_get_author_commiter(repo: &git::Repository) { assert!(repo.get_author("<invalid>").await.is_err()); } -async fn git_fetch(bare: bool) { +async fn git_fetch(bare: bool) -> git::Repository { let path = testdir!().join("repo"); let remote_path = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("src/testdata/bare"); let remote = remote_path.to_string_lossy().into_owned(); @@ -231,6 +231,7 @@ async fn git_fetch(bare: bool) { branch.unwrap(); other.unwrap(); } + repo } #[tokio::test] @@ -266,3 +267,19 @@ async fn test_git_fetch() { async fn test_git_bare_fetch() { git_fetch(true).await; } + +#[tokio::test] +async fn test_git_delete_branch() { + // Using git_fetch as we need a writeable git repo + let repo = git_fetch(false).await; + assert!(repo.delete_branch("other").await.is_ok()); + assert!(repo.delete_branch("does-not-exist").await.is_err()); +} + +#[tokio::test] +async fn test_git_bare_delete_branch() { + // Using git_fetch as we need a writeable git repo + let repo = git_fetch(true).await; + assert!(repo.delete_branch("other").await.is_ok()); + assert!(repo.delete_branch("does-not-exist").await.is_err()); +} |
