Skip to content

Add a log message to add_crate background job #2231

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Mar 1, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 23 additions & 14 deletions src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ impl Repository {
}
}

fn commit_and_push(&self, msg: &str, modified_file: &Path) -> Result<(), PerformError> {
fn perform_commit_and_push(&self, msg: &str, modified_file: &Path) -> Result<(), PerformError> {
// git add $file
let mut index = self.repository.index()?;
index.add_path(modified_file)?;
Expand Down Expand Up @@ -230,6 +230,17 @@ impl Repository {
ref_status
}

pub fn commit_and_push(&self, message: &str, modified_file: &Path) -> Result<(), PerformError> {
println!("Committing and pushing \"{}\"", message);

self.perform_commit_and_push(message, modified_file)
.map(|_| println!("Commit and push finished for \"{}\"", message))
.map_err(|err| {
eprintln!("Commit and push for \"{}\" errored: {}", message, err);
err
})
}

pub fn reset_head(&self) -> Result<(), PerformError> {
let mut origin = self.repository.find_remote("origin")?;
origin.fetch(
Expand Down Expand Up @@ -267,10 +278,9 @@ pub fn add_crate(env: &Environment, krate: Crate) -> Result<(), PerformError> {
serde_json::to_writer(&mut file, &krate)?;
file.write_all(b"\n")?;

repo.commit_and_push(
&format!("Updating crate `{}#{}`", krate.name, krate.vers),
&repo.relative_index_file(&krate.name),
)
let message: String = format!("Updating crate `{}#{}`", krate.name, krate.vers);

repo.commit_and_push(&message, &repo.relative_index_file(&krate.name))
}

/// Yanks or unyanks a crate version. This requires finding the index
Expand Down Expand Up @@ -320,15 +330,14 @@ pub fn yank(
let new = new?.join("\n") + "\n";
fs::write(&dst, new.as_bytes())?;

repo.commit_and_push(
&format!(
"{} crate `{}#{}`",
if yanked { "Yanking" } else { "Unyanking" },
krate,
version.num
),
&repo.relative_index_file(&krate),
)?;
let message: String = format!(
"{} crate `{}#{}`",
if yanked { "Yanking" } else { "Unyanking" },
krate,
version.num
);

repo.commit_and_push(&message, &repo.relative_index_file(&krate))?;

diesel::update(&version)
.set(versions::yanked.eq(yanked))
Expand Down