@@ -10,6 +10,7 @@ mod command;
10
10
pub ( crate ) mod diff;
11
11
mod oid;
12
12
pub ( crate ) mod status;
13
+ mod tempindex;
13
14
mod version;
14
15
15
16
use std:: {
@@ -41,7 +42,7 @@ impl<'repo, 'index> Stupid<'repo, 'index> for gix::Repository {
41
42
StupidContext {
42
43
git_dir : Some ( self . git_dir ( ) ) ,
43
44
work_dir : self . work_dir ( ) ,
44
- index_path : None ,
45
+ index_filename : None ,
45
46
git_version : RefCell :: new ( None :: < StupidVersion > ) ,
46
47
}
47
48
}
@@ -52,7 +53,7 @@ impl<'repo, 'index> Stupid<'repo, 'index> for gix::Repository {
52
53
pub ( crate ) struct StupidContext < ' repo , ' index > {
53
54
git_dir : Option < & ' repo Path > ,
54
55
work_dir : Option < & ' repo Path > ,
55
- index_path : Option < & ' index Path > ,
56
+ index_filename : Option < & ' index Path > ,
56
57
git_version : RefCell < Option < StupidVersion > > ,
57
58
}
58
59
@@ -64,21 +65,14 @@ impl<'repo, 'index> StupidContext<'repo, 'index> {
64
65
where
65
66
F : FnOnce ( & StupidContext ) -> Result < T > ,
66
67
{
67
- let temp_index_root = if let Some ( git_dir) = self . git_dir {
68
- git_dir
69
- } else {
70
- self . index_path
71
- . expect ( "StupidContext has either a git_dir or an index_path" )
72
- . parent ( )
73
- . expect ( "git index path has parent" )
74
- } ;
75
- let index_tempfile = tempfile:: Builder :: new ( )
76
- . prefix ( "index-temp-stg" )
77
- . tempfile_in ( temp_index_root) ?;
68
+ let git_dir = self
69
+ . git_dir
70
+ . expect ( "git_dir required to use with_temp_index" ) ;
71
+ let temp_index = tempindex:: TempIndex :: new ( git_dir) ?;
78
72
let stupid_temp = StupidContext {
79
73
git_dir : self . git_dir ,
80
74
work_dir : self . work_dir ,
81
- index_path : Some ( index_tempfile . path ( ) ) ,
75
+ index_filename : Some ( temp_index . filename ( ) ) ,
82
76
git_version : RefCell :: new ( None ) ,
83
77
} ;
84
78
@@ -101,21 +95,28 @@ impl<'repo, 'index> StupidContext<'repo, 'index> {
101
95
let realpath =
102
96
|path| gix:: path:: realpath_opts ( path, cwd. as_path ( ) , gix:: path:: realpath:: MAX_SYMLINKS ) ;
103
97
if let Some ( git_dir) = self . git_dir {
104
- command. env ( "GIT_DIR" , realpath ( git_dir) ?) ;
98
+ let git_dir = realpath ( git_dir) ?;
99
+ if let Some ( index_filename) = self . index_filename {
100
+ command. env ( "GIT_INDEX_FILE" , git_dir. join ( index_filename) ) ;
101
+ }
102
+ command. env ( "GIT_DIR" , git_dir) ;
105
103
}
106
104
command. env ( "GIT_WORK_TREE" , "." ) ;
107
- if let Some ( index_path) = self . index_path {
108
- command. env ( "GIT_INDEX_FILE" , realpath ( index_path) ?) ;
109
- }
110
105
Ok ( command)
111
106
}
112
107
113
108
fn setup_git_env ( & self , command : & mut Command ) {
114
109
self . git_dir . map ( |git_dir| command. env ( "GIT_DIR" , git_dir) ) ;
115
110
self . work_dir
116
111
. 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) ) ;
112
+ self . index_filename . map ( |filename| {
113
+ command. env (
114
+ "GIT_INDEX_FILE" ,
115
+ self . git_dir
116
+ . expect ( "git_dir must be set when index_filename is used" )
117
+ . join ( filename) ,
118
+ )
119
+ } ) ;
119
120
}
120
121
121
122
fn at_least_version ( & self , version : & StupidVersion ) -> Result < bool > {
0 commit comments