File tree Expand file tree Collapse file tree 2 files changed +30
-2
lines changed Expand file tree Collapse file tree 2 files changed +30
-2
lines changed Original file line number Diff line number Diff line change @@ -2,12 +2,17 @@ use crate::{worktree, Worktree};
22
33/// Interact with individual worktrees and their information.
44impl crate :: Repository {
5- /// Return a list of all _linked_ worktrees sorted by private git dir path as a lightweight proxy.
5+ /// Return a list of all **linked** worktrees sorted by private git dir path as a lightweight proxy.
6+ ///
7+ /// This means the number is `0` even if there is the main worktree, as it is not counted as linked worktree.
8+ /// This also means it will be `1` if there is one linked worktree next to the main worktree.
9+ /// It's worth noting that a *bare* repository may have one or more linked worktrees, but has no *main* worktree,
10+ /// which is the reason why the *possibly* available main worktree isn't listed here.
611 ///
712 /// Note that these need additional processing to become usable, but provide a first glimpse a typical worktree information.
813 pub fn worktrees ( & self ) -> std:: io:: Result < Vec < worktree:: Proxy < ' _ > > > {
914 let mut res = Vec :: new ( ) ;
10- let iter = match std:: fs:: read_dir ( self . common_dir ( ) . join ( "worktrees" ) ) {
15+ let iter = match std:: fs:: read_dir ( dbg ! ( self . common_dir( ) ) . join ( "worktrees" ) ) {
1116 Ok ( iter) => iter,
1217 Err ( err) if err. kind ( ) == std:: io:: ErrorKind :: NotFound => return Ok ( res) ,
1318 Err ( err) => return Err ( err) ,
Original file line number Diff line number Diff line change @@ -358,6 +358,29 @@ mod open {
358358 wd. join( "this" ) . is_file( ) ,
359359 "The submodule itself has the file, so it should be in the worktree"
360360 ) ;
361+
362+ assert_eq ! ( sm_repo. worktrees( ) ?. len( ) , 1 , "only a single linked worktree" ) ;
363+ Ok ( ( ) )
364+ }
365+
366+ #[ test]
367+ fn list_submodule_worktrees ( ) -> crate :: Result {
368+ let sm_repo = named_subrepo_opts (
369+ "make_submodule_with_worktree.sh" ,
370+ "submodule-with-extra-worktree-host/m1" ,
371+ gix:: open:: Options :: isolated ( ) ,
372+ ) ?;
373+ let wd = sm_repo. work_dir ( ) . expect ( "workdir is present" ) ;
374+ assert ! (
375+ sm_repo. rev_parse_single( ":this" ) . is_ok( ) ,
376+ "the file is in the submodule"
377+ ) ;
378+ assert ! (
379+ wd. join( "this" ) . is_file( ) ,
380+ "The submodule itself has the file, so it should be in the worktree"
381+ ) ;
382+
383+ assert_eq ! ( sm_repo. worktrees( ) ?. len( ) , 1 , "only a single linked worktree" ) ;
361384 Ok ( ( ) )
362385 }
363386
You can’t perform that action at this time.
0 commit comments