@@ -21,9 +21,115 @@ This edition covers what happened during the months of January and February 2025
2121### General
2222-->
2323
24- <!-- -
2524### Reviews
26- -->
25+
26+ + [[ PATCH] worktree: detect from secondary worktree if main worktree is bare] ( https://lore.kernel.org/git/pull.1829.git.1731653548549.gitgitgadget@gmail.com/ )
27+
28+ Last November, Olga Pilipenco sent a patch to the mailing list
29+ addressing an issue she encountered while working with multiple
30+ [ worktrees] ( https://git-scm.com/docs/git-worktree ) .
31+
32+ Git worktrees allow developers to check out multiple branches from
33+ the same repository simultaneously, each in its own working
34+ directory. Unlike creating separate clones, worktrees share the same
35+ object database and references, saving disk space and avoiding the
36+ need to push and fetch between copies of the repository. They can be
37+ very useful when working on multiple features in parallel or when
38+ needing to make a quick fix while in the middle of other development
39+ work.
40+
41+ The issue happened when a repository had a main worktree that was
42+ bare with ` core.bare = true ` in ` config.worktree ` . If a new
43+ secondary worktree was created, then from that secondary worktree
44+ the main worktree appeared as non-bare. This prevented users from
45+ checking out or working with the default branch of the main worktree
46+ (typically "main" or "master") in the secondary worktree.
47+
48+ When ` extensions.worktreeConfig ` is enabled, each worktree has its
49+ own configuration settings in a ` config.worktree ` file that can
50+ override repository-wide settings in the common ` config ` file. This
51+ allows different worktrees to have different configurations, but it
52+ also means that settings from one worktree aren't automatically
53+ visible to commands running in another worktree.
54+
55+ Olga found that when inside the secondary worktree, the main
56+ worktree's configuration wasn't initialized, and her patch fixed
57+ that by loading the main worktree's ` config.worktree ` file only when
58+ required.
59+
60+ Unfortunately Olga's email fell through the cracks, receiving no
61+ response. But last January she sent a
62+ [ version 2] ( https://lore.kernel.org/git/pull.1829.v2.git.1737063335673.gitgitgadget@gmail.com/ )
63+ of her patch. There was no code change compared to the first
64+ version, but she added people in "Cc:", and she had rebased the
65+ patch on top of the "maint" branch.
66+
67+ This time Eric Sunshine replied. He acknowledged that this was a
68+ real problem and noted that it had been documented in a "NEEDSWORK"
69+ comment added in 2019 into the code that mentioned it. He then
70+ attempted to rewrite the commit message of the patch in a way that
71+ was "more idiomatic" to the project and that added more details to
72+ help understand the problem.
73+
74+ The suggested commit message especially mentioned that when
75+ ` extensions.worktreeConfig ` is true, commands run in a secondary
76+ worktree only consulted ` $commondir/config ` and
77+ ` $commondir/worktrees/<id>/config.worktree ` . Thus they never saw
78+ that the main worktree's ` core.bare ` setting was true in
79+ ` $commondir/config.worktree ` .
80+
81+ Eric also suggested removing some parts of Olga's commit message
82+ that talked about other solutions she had considered, or that
83+ repeated in which circumstances the problem appeared. Then there
84+ were a number of small comments on the code part of the patch.
85+
86+ Olga replied to Eric saying that the commit message he proposed was
87+ "so much better" than the original one. She agreed with most of
88+ Eric's suggestions and answered the few questions he asked.
89+
90+ Eric replied explaining some technical details and making a few more
91+ suggestions.
92+
93+ Junio Hamano, the Git maintainer then replied to Eric thanking him
94+ "for an easy-to-read review" and thanking Olga for working on this
95+ issue.
96+
97+ Eric and Olga further discussed technical improvements to the
98+ patch. In the course of that discussion, Eric explained the
99+ historical context related to using the "bare main worktree"
100+ expression:
101+
102+ > It's a historic "accident" that when worktree support was designed,
103+ > the idea of linking worktrees to a bare repository was not considered.
104+ > Support for using worktrees with a bare repository was added later.
105+ > However, by that time, the term "main worktree" was already well
106+ > established, with the very unfortunate result that even when there is
107+ > no actual "main worktree" but only a bare repository with "linked
108+ > worktrees" hanging off it, the repository itself is usually referred
109+ > to as the "bare main worktree", which is an obvious misnomer; the
110+ > repository is just a repository (i.e. the object database and other
111+ > meta-information) and there is no actual main worktree.
112+
113+ Olga then sent a
114+ [ version 3] ( https://lore.kernel.org/git/pull.1829.v3.git.1738346881907.gitgitgadget@gmail.com/ )
115+ of her patch. It used the commit message suggested by Eric, and
116+ implemented his suggestions.
117+
118+ Junio reviewed this new version of the patch and had a single
119+ question about the code that decided when it was necessary to read
120+ the main worktree's ` config.worktree ` file. Olga and Junio further
121+ discussed how to make it clearer what that code was doing, and
122+ eventually agreed on adding a four line long comment on top of it.
123+
124+ Olga then sent a
125+ [ version 4] ( https://lore.kernel.org/git/pull.1829.v4.git.1738737014194.gitgitgadget@gmail.com/ )
126+ of her patch which only added that four line long comment.
127+
128+ The patch was later merged into the 'master' branch, so the next
129+ 2.49 version of Git that should be released in a few weeks will
130+ finally resolve a long-standing issue and significantly enhance the
131+ usability of Git worktrees for developers working with bare
132+ repositories.
27133
28134<!-- -
29135### Support
0 commit comments