1#[ allow( clippy::std_instead_of_alloc, clippy::std_instead_of_core ) ]
2mod private
3{
4
5 use crate::*;
6
7 use std::fmt;
8 use process_tools::process;
9 use error::
10 {
11 untyped::{ format_err, Context },
12 };
13
14 #[ derive( Debug, Default, Clone ) ]
15 pub struct ExtendedGitReport
17 {
18 pub add : Option< process::Report >,
20 pub commit : Option< process::Report >,
22 pub push : Option< process::Report >,
24 }
25
26 impl fmt::Display for ExtendedGitReport
27 {
28 fn fmt( &self, f : &mut fmt::Formatter< '_ > ) -> fmt::Result
29 {
30 let Self { add, commit, push } = &self;
31
32 if let Some( add ) = add { writeln!( f, "{add}" )? }
33 if let Some( commit ) = commit { writeln!( f, "{commit}" )? }
34 if let Some( push ) = push { writeln!( f, "{push}" )? }
35
36 std::fmt::Result::Ok( () )
37 }
38 }
39
40 #[ derive( Debug, Clone ) ]
44 pub struct GitOptions
45 {
46 pub git_root : AbsolutePath,
48 pub items : Vec< AbsolutePath >,
50 pub message : String,
52 pub dry : bool,
55 }
56
57 #[ allow( clippy::needless_pass_by_value ) ]
61 pub fn perform_git_commit( o : GitOptions ) -> error::untyped::Result< ExtendedGitReport >
62 {
64 use tool::git;
65 let mut report = ExtendedGitReport::default();
66 if o.items.is_empty() { return error::untyped::Result::Ok( report ); }
67 let items : error::untyped::Result< Vec< _ > > = o
68 .items
69 .iter()
70 .map
71 (
72 | item | item.as_ref().strip_prefix( o.git_root.as_ref() ).map( std::path::Path::to_string_lossy )
73 .with_context( || format!("git_root: {}, item: {}", o.git_root.as_ref().display(), item.as_ref().display() ) )
74 )
75 .collect();
76
77 let res = git::add( &o.git_root, &items?, o.dry ).map_err( | e | format_err!( "{report}\n{e}" ) )?;
78 report.add = Some( res );
79 let res = git::commit( &o.git_root, &o.message, o.dry ).map_err( | e | format_err!( "{report}\n{e}" ) )?;
80 report.commit = Some( res );
81
82 error::untyped::Result::Ok( report )
83 }
84}
85
86crate::mod_interface!
89{
90 own use ExtendedGitReport;
91 own use GitOptions;
92 own use perform_git_commit;
93}