Skip to content

Commit e566283

Browse files
committed
Auto merge of #2231 - rye:log-index-updates, r=jtgeibel
Add a log message to add_crate background job Per #2226; is this sufficient to resolve that issue? This PR simply adds a log message (`println!`) right before carrying out the final `commit_and_push` operation, which could otherwise fail silently if the Git host is experiencing an outage.
2 parents 3e80706 + c74d657 commit e566283

File tree

1 file changed

+23
-14
lines changed

1 file changed

+23
-14
lines changed

src/git.rs

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ impl Repository {
186186
}
187187
}
188188

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

233+
pub fn commit_and_push(&self, message: &str, modified_file: &Path) -> Result<(), PerformError> {
234+
println!("Committing and pushing \"{}\"", message);
235+
236+
self.perform_commit_and_push(message, modified_file)
237+
.map(|_| println!("Commit and push finished for \"{}\"", message))
238+
.map_err(|err| {
239+
eprintln!("Commit and push for \"{}\" errored: {}", message, err);
240+
err
241+
})
242+
}
243+
233244
pub fn reset_head(&self) -> Result<(), PerformError> {
234245
let mut origin = self.repository.find_remote("origin")?;
235246
origin.fetch(
@@ -267,10 +278,9 @@ pub fn add_crate(env: &Environment, krate: Crate) -> Result<(), PerformError> {
267278
serde_json::to_writer(&mut file, &krate)?;
268279
file.write_all(b"\n")?;
269280

270-
repo.commit_and_push(
271-
&format!("Updating crate `{}#{}`", krate.name, krate.vers),
272-
&repo.relative_index_file(&krate.name),
273-
)
281+
let message: String = format!("Updating crate `{}#{}`", krate.name, krate.vers);
282+
283+
repo.commit_and_push(&message, &repo.relative_index_file(&krate.name))
274284
}
275285

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

323-
repo.commit_and_push(
324-
&format!(
325-
"{} crate `{}#{}`",
326-
if yanked { "Yanking" } else { "Unyanking" },
327-
krate,
328-
version.num
329-
),
330-
&repo.relative_index_file(&krate),
331-
)?;
333+
let message: String = format!(
334+
"{} crate `{}#{}`",
335+
if yanked { "Yanking" } else { "Unyanking" },
336+
krate,
337+
version.num
338+
);
339+
340+
repo.commit_and_push(&message, &repo.relative_index_file(&krate))?;
332341

333342
diesel::update(&version)
334343
.set(versions::yanked.eq(yanked))

0 commit comments

Comments
 (0)