Skip to content

Commit 3a5169d

Browse files
committed
Use anyhow for error handling in example; prefer user-defined directory.
This way, we also show off certain safety precautions as `gitoxide` will refuse to initialize a repo in a non-empty directory.
1 parent e540a76 commit 3a5169d

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

git-repository/examples/init-non-bare-repo.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
// cargo run -p git-repository --example new
22

3+
use anyhow::Context;
34
use git_repository as git;
45

5-
fn main() -> Result<(), Box<dyn std::error::Error>> {
6-
let tmp = tempfile::TempDir::new()?;
7-
let work_dir = tmp.path().join("repo-non-bare");
6+
fn main() -> anyhow::Result<()> {
7+
let work_dir = std::env::args_os()
8+
.nth(1)
9+
.context("First argument needs to be the directory to initialize the repository in")?;
810
let repo = git::init(work_dir)?;
911

1012
println!(
@@ -27,7 +29,5 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
2729
git::commit::NO_PARENT_IDS,
2830
)?;
2931
println!("new commit id with empty tree: {:?}", id);
30-
31-
let _persisted = tmp.into_path();
3232
Ok(())
3333
}

0 commit comments

Comments
 (0)