@@ -5,7 +5,8 @@ pub mod juniper_hyper;
5
5
#[ macro_use]
6
6
extern crate lazy_static;
7
7
8
- use josh:: JoshError ;
8
+ use josh:: { josh_error, JoshError } ;
9
+ use std:: fs;
9
10
use std:: path:: PathBuf ;
10
11
11
12
#[ derive( PartialEq ) ]
@@ -429,13 +430,16 @@ pub fn push_head_url(
429
430
let shell = josh:: shell:: Shell {
430
431
cwd : repo. path ( ) . to_owned ( ) ,
431
432
} ;
433
+
432
434
let ( username, password) = auth. parse ( ) ?;
433
- let cmd = format ! (
434
- "git push {} {} '{}'" ,
435
- if force { "-f" } else { "" } ,
436
- & url,
437
- & spec
438
- ) ;
435
+
436
+ let mut cmd = vec ! [ "git" , "push" ] ;
437
+ if force {
438
+ cmd. push ( "--force" )
439
+ }
440
+ cmd. push ( & url) ;
441
+ cmd. push ( & spec) ;
442
+
439
443
let mut fakehead = repo. reference ( & rn, oid, true , "push_head_url" ) ?;
440
444
let ( stdout, stderr, status) = shell. command_env (
441
445
& cmd,
@@ -460,7 +464,8 @@ fn create_repo_base(path: &PathBuf) -> josh::JoshResult<josh::shell::Shell> {
460
464
git2:: Repository :: init_bare ( & path) ?;
461
465
462
466
let credential_helper =
463
- "'!f() { echo \" username=\" $GIT_USER\" \n password=\" $GIT_PASSWORD\" \" ; }; f'" ;
467
+ r#"!f() { echo username="${GIT_USER}"; echo password="${GIT_PASSWORD}"; }; f"# ;
468
+
464
469
let config_options = [
465
470
( "http.receivepack" , "true" ) ,
466
471
( "user.name" , "josh" ) ,
@@ -478,11 +483,29 @@ fn create_repo_base(path: &PathBuf) -> josh::JoshResult<josh::shell::Shell> {
478
483
} ;
479
484
480
485
config_options
481
- . map ( |( key, value) | shell. command ( format ! ( "git config {} {}" , key, value) . as_str ( ) ) ) ;
482
-
483
- shell. command ( "rm -Rf hooks" ) ;
484
- shell. command ( "rm -Rf *.lock" ) ;
485
- shell. command ( "rm -Rf packed-refs" ) ;
486
+ . iter ( )
487
+ . map (
488
+ |( key, value) | match shell. command ( & [ "git" , "config" , key, value] ) {
489
+ ( _, _, code) if code != 0 => Err ( josh_error ( "failed to set git config value" ) ) ,
490
+ _ => Ok ( ( ) ) ,
491
+ } ,
492
+ )
493
+ . collect :: < Result < Vec < _ > , _ > > ( ) ?;
494
+
495
+ [ path. join ( "hooks" ) , path. join ( "packed-refs" ) ]
496
+ . iter ( )
497
+ . filter ( |p| p. exists ( ) )
498
+ . map ( |p| fs:: remove_dir_all ( p) )
499
+ . collect :: < Result < Vec < _ > , _ > > ( ) ?;
500
+
501
+ // Delete all files ending with ".lock"
502
+ fs:: read_dir ( path) ?
503
+ . filter_map ( |entry| match entry {
504
+ Ok ( entry) if entry. path ( ) . ends_with ( ".lock" ) => Some ( path) ,
505
+ _ => None ,
506
+ } )
507
+ . map ( |file| fs:: remove_file ( file) )
508
+ . collect :: < Result < Vec < _ > , _ > > ( ) ?;
486
509
487
510
Ok ( shell)
488
511
}
@@ -495,7 +518,7 @@ pub fn create_repo(path: &std::path::Path) -> josh::JoshResult<()> {
495
518
let overlay_path = path. join ( "overlay" ) ;
496
519
tracing:: debug!( "init overlay repo: {:?}" , overlay_path) ;
497
520
let overlay_shell = create_repo_base ( & overlay_path) ?;
498
- overlay_shell. command ( "mkdir hooks" ) ;
521
+ overlay_shell. command ( & [ "mkdir" , " hooks"] ) ;
499
522
500
523
let josh_executable = std:: env:: current_exe ( ) . expect ( "can't find path to exe" ) ;
501
524
std:: os:: unix:: fs:: symlink (
@@ -525,13 +548,14 @@ pub fn get_head(
525
548
let shell = josh:: shell:: Shell {
526
549
cwd : path. to_owned ( ) ,
527
550
} ;
551
+
528
552
let ( username, password) = auth. parse ( ) ?;
529
553
530
- let cmd = format ! ( "git ls-remote --symref {} {} " , & url, "HEAD" ) ;
554
+ let cmd = & [ "git" , " ls-remote" , " --symref", & url, "HEAD" ] ;
531
555
tracing:: info!( "get_head {:?} {:?} {:?}" , cmd, path, "" ) ;
532
556
533
557
let ( stdout, _stderr, _) = shell. command_env (
534
- & cmd,
558
+ cmd,
535
559
& [ ] ,
536
560
& [ ( "GIT_PASSWORD" , & password) , ( "GIT_USER" , & username) ] ,
537
561
) ;
@@ -579,7 +603,7 @@ pub fn fetch_refs_from_url(
579
603
. iter ( )
580
604
. map ( |r| {
581
605
format ! (
582
- "' +{}:refs/josh/upstream/{}/{}' " ,
606
+ "+{}:refs/josh/upstream/{}/{}" ,
583
607
& r,
584
608
josh:: to_ns( upstream_repo) ,
585
609
& r
@@ -591,7 +615,12 @@ pub fn fetch_refs_from_url(
591
615
cwd : path. to_owned ( ) ,
592
616
} ;
593
617
594
- let cmd = format ! ( "git fetch --prune --no-tags {} {}" , & url, & specs. join( " " ) ) ;
618
+ let cmd = [ "git" , "fetch" , "--prune" , "--no-tags" , & url]
619
+ . map ( str:: to_owned)
620
+ . to_vec ( ) ;
621
+ let cmd = cmd. into_iter ( ) . chain ( specs. into_iter ( ) ) . collect :: < Vec < _ > > ( ) ;
622
+ let cmd = cmd. iter ( ) . map ( |s| s as & str ) . collect :: < Vec < & str > > ( ) ;
623
+
595
624
tracing:: info!( "fetch_refs_from_url {:?} {:?} {:?}" , cmd, path, "" ) ;
596
625
597
626
let ( username, password) = auth. parse ( ) . map_err ( FetchError :: from_josh_error) ?;
0 commit comments