File tree Expand file tree Collapse file tree 2 files changed +35
-1
lines changed
Expand file tree Collapse file tree 2 files changed +35
-1
lines changed Original file line number Diff line number Diff line change @@ -60,6 +60,13 @@ enum Command {
6060 ///
6161 /// This renames `.git` to `.yolk_git` to ensure that git interaction happens through the yolk CLI
6262 Safeguard ,
63+
64+ /// Run a given shell command within a canonical context. I.e.: `yolk exec-canonical gitui`.
65+ #[ clap( name = "exec-canonical" ) ]
66+ ExecCanonical {
67+ #[ clap( allow_hyphen_values = true ) ]
68+ command : Vec < String > ,
69+ } ,
6370 /// Make sure you don't accidentally commit your local egg states
6471 ///
6572 /// Evaluate a rhai expression.
@@ -271,6 +278,17 @@ fn run_command(args: Args) -> Result<()> {
271278 . map_err ( |e| e. into_report ( "<inline>" , expr) ) ?;
272279 println ! ( "{result}" ) ;
273280 }
281+ Command :: ExecCanonical { command } => {
282+ yolk. with_canonical_state ( || {
283+ let mut command = command. iter ( ) ;
284+ let binary = command. next ( ) . context ( "No command to run given" ) ?;
285+ yolk. paths ( )
286+ . start_command ( binary) ?
287+ . args ( command)
288+ . status ( )
289+ . into_diagnostic ( )
290+ } ) ?;
291+ }
274292 Command :: Git {
275293 command,
276294 force_canonical,
Original file line number Diff line number Diff line change 1- use std:: path:: { Path , PathBuf } ;
1+ use std:: {
2+ path:: { Path , PathBuf } ,
3+ process:: Command ,
4+ } ;
25
36use fs_err:: PathExt ;
47use miette:: { Context as _, IntoDiagnostic , Result } ;
@@ -140,6 +143,19 @@ impl YolkPaths {
140143 Ok ( ( ) )
141144 }
142145
146+ /// Start a [`std::process::Command`] with the `GIT_DIR` variable set to the git directory.
147+ pub fn start_command ( & self , binary : & str ) -> Result < Command > {
148+ let mut cmd = Command :: new ( binary) ;
149+ cmd. env (
150+ "GIT_DIR" ,
151+ self . active_yolk_git_dir ( ) ?
152+ . canonical ( ) ?
153+ . to_string_lossy ( )
154+ . to_string ( ) ,
155+ ) ;
156+ Ok ( cmd)
157+ }
158+
143159 /// Start a [Git] command helper with the paths correctly set for this yolk repository
144160 pub fn start_git ( & self ) -> Result < Git > {
145161 Ok ( Git :: new ( self . root_path ( ) , self . active_yolk_git_dir ( ) ?) )
You can’t perform that action at this time.
0 commit comments