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 {
5555 } )
5656 }
5757
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+
5868 /// Return a shared worktree index which is updated automatically if the in-memory snapshot has become stale as the underlying file
5969 /// on disk has changed, or `None` if no such file exists.
6070 ///
Original file line number Diff line number Diff line change @@ -111,6 +111,7 @@ mod with_core_worktree_config {
111111 }
112112
113113 #[ test]
114+ #[ cfg( feature = "index" ) ]
114115 fn bare_relative ( ) -> crate :: Result {
115116 let repo = repo ( "bare-relative-worktree" ) ;
116117
@@ -123,6 +124,8 @@ mod with_core_worktree_config {
123124 repo. work_dir( ) . is_none( ) ,
124125 "we simply don't load core.worktree in bare repos either to match this behaviour"
125126 ) ;
127+ assert ! ( repo. try_index( ) ?. is_none( ) ) ;
128+ assert ! ( repo. index_or_empty( ) ?. entries( ) . is_empty( ) ) ;
126129 Ok ( ( ) )
127130 }
128131
You can’t perform that action at this time.
0 commit comments