Skip to content

Add example showing retrieving of latest commit for a file#1243

Merged
weihanglo merged 1 commit into
rust-lang:mainfrom
DanielEScherzer:example-latest-commit
May 8, 2026
Merged

Add example showing retrieving of latest commit for a file#1243
weihanglo merged 1 commit into
rust-lang:mainfrom
DanielEScherzer:example-latest-commit

Conversation

@DanielEScherzer
Copy link
Copy Markdown
Contributor

Closes #588
Closes #943

@rustbot rustbot added the S-waiting-on-review Status: Waiting on review label May 7, 2026
@DanielEScherzer
Copy link
Copy Markdown
Contributor Author

Testing locally:

root@1976037f2eef:/rust/git2-rs# cargo run --example file-latest-commit -- --path examples/cat-file.rs
warning: libgit2-sys@0.18.3+1.9.2: failed to probe system libgit2:
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 1.30s
     Running `target/debug/examples/file-latest-commit --path examples/cat-file.rs`
Most recent commit modifying examples/cat-file.rs on default branch: a75e007a6eb1493e9ea487b12fe4ea7a7917ffc1

root@1976037f2eef:/rust/git2-rs# cargo run --example file-latest-commit -- --path examples/cat-file.rs --branch return-results
warning: libgit2-sys@0.18.3+1.9.2: failed to probe system libgit2:
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 1.37s
     Running `target/debug/examples/file-latest-commit --path examples/cat-file.rs --branch return-results`
Most recent commit modifying examples/cat-file.rs on branch return-results: d791501c0e5c21c56bf264414eef9b5f91699a62

For a75e007 and d791501

Copy link
Copy Markdown
Member

@weihanglo weihanglo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +63 to +66
println!(
"Error: no modifying commit found modifying {} {}",
args.path, branch_display
);
Copy link
Copy Markdown
Member

@weihanglo weihanglo May 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: eprintln! stderr for human. stdout for machine programmatic use case

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The overall main() uses println based on the other examples, and I figured I should be consistent with that

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I got that hence merged directly

@weihanglo weihanglo added this pull request to the merge queue May 8, 2026
Merged via the queue into rust-lang:main with commit 8aeb3ef May 8, 2026
7 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Waiting on review label May 8, 2026
@DanielEScherzer DanielEScherzer deleted the example-latest-commit branch May 8, 2026 01:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Is there a way of getting the latest commit for a file on a specific branch. Is there any way to get last commit of a certain file?

3 participants