1010//! Run with: cargo run --example commit_workflows
1111
1212use rustic_git:: { Hash , Repository , Result } ;
13- use std:: fs;
14- use std:: path:: Path ;
13+ use std:: { env, fs} ;
1514
1615fn main ( ) -> Result < ( ) > {
1716 println ! ( "Rustic Git - Commit Workflows Example\n " ) ;
1817
19- let repo_path = "/tmp/ rustic_git_commit_example";
18+ let repo_path = env :: temp_dir ( ) . join ( " rustic_git_commit_example") ;
2019
2120 // Clean up any previous run
22- if Path :: new ( repo_path) . exists ( ) {
23- fs:: remove_dir_all ( repo_path) . expect ( "Failed to clean up previous example" ) ;
21+ if repo_path. exists ( ) {
22+ fs:: remove_dir_all ( & repo_path) . expect ( "Failed to clean up previous example" ) ;
2423 }
2524
2625 // Initialize repository
2726 println ! ( "Setting up repository for commit demonstrations..." ) ;
28- let repo = Repository :: init ( repo_path, false ) ?;
27+ let repo = Repository :: init ( & repo_path, false ) ?;
2928 println ! ( "Repository initialized\n " ) ;
3029
3130 println ! ( "=== Basic Commit Operations ===\n " ) ;
3231
3332 // Create initial files
3433 println ! ( "Creating initial project files..." ) ;
35- fs:: create_dir_all ( format ! ( "{}/ src", repo_path ) ) ?;
34+ fs:: create_dir_all ( repo_path . join ( " src") ) ?;
3635
3736 fs:: write (
38- format ! ( "{}/ README.md", repo_path ) ,
37+ repo_path . join ( " README.md") ,
3938 "# Commit Demo Project\n \n This project demonstrates commit workflows with rustic-git.\n " ,
4039 ) ?;
4140
4241 fs:: write (
43- format ! ( "{}/ src/main.rs", repo_path ) ,
42+ repo_path . join ( " src/main.rs") ,
4443 r#"fn main() {
4544 println!("Hello, Commit Demo!");
4645}
4746"# ,
4847 ) ?;
4948
5049 fs:: write (
51- format ! ( "{}/ Cargo.toml", repo_path ) ,
50+ repo_path . join ( " Cargo.toml") ,
5251 r#"[package]
5352name = "commit-demo"
5453version = "0.1.0"
@@ -109,10 +108,10 @@ edition = "2021"
109108
110109 // Create more files to commit with custom author
111110 println ! ( "Adding features for custom author commit..." ) ;
112- fs:: create_dir_all ( format ! ( "{}/ tests", repo_path ) ) ?;
111+ fs:: create_dir_all ( repo_path . join ( " tests") ) ?;
113112
114113 fs:: write (
115- format ! ( "{}/ src/lib.rs", repo_path ) ,
114+ repo_path . join ( " src/lib.rs") ,
116115 r#"//! Commit demo library
117116
118117pub fn greet(name: &str) -> String {
@@ -132,7 +131,7 @@ mod tests {
132131 ) ?;
133132
134133 fs:: write (
135- format ! ( "{}/ tests/integration_test.rs", repo_path ) ,
134+ repo_path . join ( " tests/integration_test.rs") ,
136135 r#"use commit_demo::greet;
137136
138137#[test]
@@ -166,7 +165,7 @@ fn test_integration() {
166165 // Commit 3: Update version
167166 println ! ( "Step 1: Update version information..." ) ;
168167 fs:: write (
169- format ! ( "{}/ Cargo.toml", repo_path ) ,
168+ repo_path . join ( " Cargo.toml") ,
170169 r#"[package]
171170name = "commit-demo"
172171version = "0.2.0"
@@ -182,7 +181,7 @@ description = "A demo project for commit workflows"
182181 // Commit 4: Add documentation
183182 println ! ( "Step 2: Add documentation..." ) ;
184183 fs:: write (
185- format ! ( "{}/ CHANGELOG.md", repo_path ) ,
184+ repo_path . join ( " CHANGELOG.md") ,
186185 r#"# Changelog
187186
188187## [0.2.0] - 2024-01-01
@@ -210,7 +209,7 @@ description = "A demo project for commit workflows"
210209 // Commit 5: Final polish
211210 println ! ( "Step 3: Final polish..." ) ;
212211 fs:: write (
213- format ! ( "{}/ README.md", repo_path ) ,
212+ repo_path . join ( " README.md") ,
214213 r#"# Commit Demo Project
215214
216215This project demonstrates commit workflows with rustic-git.
@@ -298,10 +297,7 @@ See CHANGELOG.md for version history.
298297 println ! ( "\n Testing commit with empty message:" ) ;
299298
300299 // Create a change to commit
301- fs:: write (
302- format ! ( "{}/temp_for_empty_message.txt" , repo_path) ,
303- "temp content" ,
304- ) ?;
300+ fs:: write ( repo_path. join ( "temp_for_empty_message.txt" ) , "temp content" ) ?;
305301 repo. add ( & [ "temp_for_empty_message.txt" ] ) ?;
306302
307303 match repo. commit ( "" ) {
@@ -336,7 +332,7 @@ See CHANGELOG.md for version history.
336332
337333 // Clean up
338334 println ! ( "\n Cleaning up example repository..." ) ;
339- fs:: remove_dir_all ( repo_path) ?;
335+ fs:: remove_dir_all ( & repo_path) ?;
340336 println ! ( "Commit workflows example completed!" ) ;
341337
342338 Ok ( ( ) )
0 commit comments