File tree Expand file tree Collapse file tree 2 files changed +13
-0
lines changed Expand file tree Collapse file tree 2 files changed +13
-0
lines changed Original file line number Diff line number Diff line change @@ -55,6 +55,16 @@ impl crate::Repository {
55
55
} )
56
56
}
57
57
58
+ /// Return the shared worktree index if present, or return a new empty one which has an association to the place where the index would be.
59
+ pub fn index_or_empty ( & self ) -> Result < worktree:: Index , worktree:: open_index:: Error > {
60
+ Ok ( self . try_index ( ) ?. unwrap_or_else ( || {
61
+ worktree:: Index :: new ( gix_fs:: FileSnapshot :: new ( gix_index:: File :: from_state (
62
+ gix_index:: State :: new ( self . object_hash ( ) ) ,
63
+ self . index_path ( ) ,
64
+ ) ) )
65
+ } ) )
66
+ }
67
+
58
68
/// Return a shared worktree index which is updated automatically if the in-memory snapshot has become stale as the underlying file
59
69
/// on disk has changed, or `None` if no such file exists.
60
70
///
Original file line number Diff line number Diff line change @@ -111,6 +111,7 @@ mod with_core_worktree_config {
111
111
}
112
112
113
113
#[ test]
114
+ #[ cfg( feature = "index" ) ]
114
115
fn bare_relative ( ) -> crate :: Result {
115
116
let repo = repo ( "bare-relative-worktree" ) ;
116
117
@@ -123,6 +124,8 @@ mod with_core_worktree_config {
123
124
repo. work_dir( ) . is_none( ) ,
124
125
"we simply don't load core.worktree in bare repos either to match this behaviour"
125
126
) ;
127
+ assert ! ( repo. try_index( ) ?. is_none( ) ) ;
128
+ assert ! ( repo. index_or_empty( ) ?. entries( ) . is_empty( ) ) ;
126
129
Ok ( ( ) )
127
130
}
128
131
You can’t perform that action at this time.
0 commit comments