@@ -87,9 +87,7 @@ impl<'repo, 'index> StupidContext<'repo, 'index> {
87
87
88
88
fn git ( & self ) -> Command {
89
89
let mut command = Command :: new ( "git" ) ;
90
- self . git_dir . map ( |p| command. env ( "GIT_DIR" , p) ) ;
91
- self . work_dir . map ( |p| command. env ( "GIT_WORK_TREE" , p) ) ;
92
- self . index_path . map ( |p| command. env ( "GIT_INDEX_FILE" , p) ) ;
90
+ self . setup_git_env ( & mut command) ;
93
91
command
94
92
}
95
93
@@ -112,6 +110,14 @@ impl<'repo, 'index> StupidContext<'repo, 'index> {
112
110
Ok ( command)
113
111
}
114
112
113
+ fn setup_git_env ( & self , command : & mut Command ) {
114
+ self . git_dir . map ( |git_dir| command. env ( "GIT_DIR" , git_dir) ) ;
115
+ self . work_dir
116
+ . map ( |work_dir| command. env ( "GIT_WORK_TREE" , work_dir) ) ;
117
+ self . index_path
118
+ . map ( |index_path| command. env ( "GIT_INDEX_FILE" , index_path) ) ;
119
+ }
120
+
115
121
fn at_least_version ( & self , version : & StupidVersion ) -> Result < bool > {
116
122
let mut git_version = self . git_version . borrow_mut ( ) ;
117
123
if let Some ( git_version) = git_version. as_ref ( ) {
@@ -683,9 +689,7 @@ impl<'repo, 'index> StupidContext<'repo, 'index> {
683
689
SpecArg : AsRef < OsStr > ,
684
690
{
685
691
let mut command = Command :: new ( "gitk" ) ;
686
- self . git_dir . map ( |p| command. env ( "GIT_DIR" , p) ) ;
687
- self . work_dir . map ( |p| command. env ( "GIT_WORK_TREE" , p) ) ;
688
- self . index_path . map ( |p| command. env ( "GIT_INDEX_FILE" , p) ) ;
692
+ self . setup_git_env ( & mut command) ;
689
693
command. arg ( commit_id. to_string ( ) ) ;
690
694
if let Some ( pathspecs) = pathspecs {
691
695
command. arg ( "--" ) ;
@@ -1325,9 +1329,7 @@ impl<'repo, 'index> StupidContext<'repo, 'index> {
1325
1329
let mut args = user_cmd_str. split ( |c : char | c. is_ascii_whitespace ( ) ) ;
1326
1330
if let Some ( command_name) = args. next ( ) {
1327
1331
let mut command = Command :: new ( command_name) ;
1328
- self . git_dir . map ( |p| command. env ( "GIT_DIR" , p) ) ;
1329
- self . work_dir . map ( |p| command. env ( "GIT_WORK_TREE" , p) ) ;
1330
- self . index_path . map ( |p| command. env ( "GIT_INDEX_FILE" , p) ) ;
1332
+ self . setup_git_env ( & mut command) ;
1331
1333
let status = command
1332
1334
. args ( args)
1333
1335
. arg ( remote_name)
@@ -1357,9 +1359,7 @@ impl<'repo, 'index> StupidContext<'repo, 'index> {
1357
1359
let mut args = user_cmd_str. split ( |c : char | c. is_ascii_whitespace ( ) ) ;
1358
1360
if let Some ( command_name) = args. next ( ) {
1359
1361
let mut command = Command :: new ( command_name) ;
1360
- self . git_dir . map ( |p| command. env ( "GIT_DIR" , p) ) ;
1361
- self . work_dir . map ( |p| command. env ( "GIT_WORK_TREE" , p) ) ;
1362
- self . index_path . map ( |p| command. env ( "GIT_INDEX_FILE" , p) ) ;
1362
+ self . setup_git_env ( & mut command) ;
1363
1363
let status = command
1364
1364
. args ( args)
1365
1365
. arg ( remote_name)
@@ -1388,9 +1388,7 @@ impl<'repo, 'index> StupidContext<'repo, 'index> {
1388
1388
let mut args = user_cmd_str. split ( |c : char | c. is_ascii_whitespace ( ) ) ;
1389
1389
if let Some ( command_name) = args. next ( ) {
1390
1390
let mut command = Command :: new ( command_name) ;
1391
- self . git_dir . map ( |p| command. env ( "GIT_DIR" , p) ) ;
1392
- self . work_dir . map ( |p| command. env ( "GIT_WORK_TREE" , p) ) ;
1393
- self . index_path . map ( |p| command. env ( "GIT_INDEX_FILE" , p) ) ;
1391
+ self . setup_git_env ( & mut command) ;
1394
1392
let status = command
1395
1393
. args ( args)
1396
1394
. arg ( target. to_string ( ) )
0 commit comments