Skip to content

Commit d35f770

Browse files
committed
UpstreamIndex: Extract create_empty_commit() method
1 parent e84bb55 commit d35f770

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

src/tests/git.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use anyhow::anyhow;
12
use git2::Repository;
23
use std::env;
34
use std::fs;
@@ -22,6 +23,23 @@ impl UpstreamIndex {
2223
pub fn url() -> Url {
2324
Url::from_file_path(&bare()).unwrap()
2425
}
26+
27+
pub fn create_empty_commit(&self) -> anyhow::Result<()> {
28+
let repo = &self.repository;
29+
30+
let head = repo.head()?;
31+
let target = head
32+
.target()
33+
.ok_or_else(|| anyhow!("Missing target for HEAD"))?;
34+
35+
let sig = repo.signature()?;
36+
let parent = repo.find_commit(target)?;
37+
let tree = repo.find_tree(parent.tree_id())?;
38+
39+
repo.commit(Some("HEAD"), &sig, &sig, "empty commit", &tree, &[&parent])?;
40+
41+
Ok(())
42+
}
2543
}
2644

2745
fn root() -> PathBuf {

src/tests/krate/publish.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -563,14 +563,7 @@ fn new_krate_git_upload_appends() {
563563
fn new_krate_git_upload_with_conflicts() {
564564
let (app, _, _, token) = TestApp::full().with_token();
565565

566-
let index = app.upstream_repository();
567-
let target = index.head().unwrap().target().unwrap();
568-
let sig = index.signature().unwrap();
569-
let parent = index.find_commit(target).unwrap();
570-
let tree = index.find_tree(parent.tree_id()).unwrap();
571-
index
572-
.commit(Some("HEAD"), &sig, &sig, "empty commit", &tree, &[&parent])
573-
.unwrap();
566+
app.upstream_index().create_empty_commit().unwrap();
574567

575568
let crate_to_publish = PublishBuilder::new("foo_conflicts");
576569
token.enqueue_publish(crate_to_publish).good();

0 commit comments

Comments
 (0)