22#include "refs.h"
33#include "strbuf.h"
44#include "worktree.h"
5+ #include "dir.h"
56
67void free_worktrees (struct worktree * * worktrees )
78{
@@ -94,6 +95,7 @@ static struct worktree *get_main_worktree(void)
9495 worktree -> is_bare = is_bare ;
9596 worktree -> head_ref = NULL ;
9697 worktree -> is_detached = is_detached ;
98+ worktree -> is_current = 0 ;
9799 add_head_info (& head_ref , worktree );
98100
99101done :
@@ -138,6 +140,7 @@ static struct worktree *get_linked_worktree(const char *id)
138140 worktree -> is_bare = 0 ;
139141 worktree -> head_ref = NULL ;
140142 worktree -> is_detached = is_detached ;
143+ worktree -> is_current = 0 ;
141144 add_head_info (& head_ref , worktree );
142145
143146done :
@@ -147,6 +150,25 @@ static struct worktree *get_linked_worktree(const char *id)
147150 return worktree ;
148151}
149152
153+ static void mark_current_worktree (struct worktree * * worktrees )
154+ {
155+ struct strbuf git_dir = STRBUF_INIT ;
156+ struct strbuf path = STRBUF_INIT ;
157+ int i ;
158+
159+ strbuf_addstr (& git_dir , absolute_path (get_git_dir ()));
160+ for (i = 0 ; worktrees [i ]; i ++ ) {
161+ struct worktree * wt = worktrees [i ];
162+ strbuf_addstr (& path , absolute_path (get_worktree_git_dir (wt )));
163+ wt -> is_current = !fspathcmp (git_dir .buf , path .buf );
164+ strbuf_reset (& path );
165+ if (wt -> is_current )
166+ break ;
167+ }
168+ strbuf_release (& git_dir );
169+ strbuf_release (& path );
170+ }
171+
150172struct worktree * * get_worktrees (void )
151173{
152174 struct worktree * * list = NULL ;
@@ -178,6 +200,8 @@ struct worktree **get_worktrees(void)
178200 }
179201 ALLOC_GROW (list , counter + 1 , alloc );
180202 list [counter ] = NULL ;
203+
204+ mark_current_worktree (list );
181205 return list ;
182206}
183207
0 commit comments