2
2
#include "refs.h"
3
3
#include "strbuf.h"
4
4
#include "worktree.h"
5
+ #include "dir.h"
5
6
6
7
void free_worktrees (struct worktree * * worktrees )
7
8
{
@@ -94,6 +95,7 @@ static struct worktree *get_main_worktree(void)
94
95
worktree -> is_bare = is_bare ;
95
96
worktree -> head_ref = NULL ;
96
97
worktree -> is_detached = is_detached ;
98
+ worktree -> is_current = 0 ;
97
99
add_head_info (& head_ref , worktree );
98
100
99
101
done :
@@ -138,6 +140,7 @@ static struct worktree *get_linked_worktree(const char *id)
138
140
worktree -> is_bare = 0 ;
139
141
worktree -> head_ref = NULL ;
140
142
worktree -> is_detached = is_detached ;
143
+ worktree -> is_current = 0 ;
141
144
add_head_info (& head_ref , worktree );
142
145
143
146
done :
@@ -147,6 +150,25 @@ static struct worktree *get_linked_worktree(const char *id)
147
150
return worktree ;
148
151
}
149
152
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
+
150
172
struct worktree * * get_worktrees (void )
151
173
{
152
174
struct worktree * * list = NULL ;
@@ -178,6 +200,8 @@ struct worktree **get_worktrees(void)
178
200
}
179
201
ALLOC_GROW (list , counter + 1 , alloc );
180
202
list [counter ] = NULL ;
203
+
204
+ mark_current_worktree (list );
181
205
return list ;
182
206
}
183
207
0 commit comments