git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 2/2] setup: make bareRepository=explicit work in GIT_DIR of a secondary worktree

From
Kyle Lippincott <spectral@google.com>
Date
Mar 9, 2024, 00:12 UTC
Message-ID
<CAO_smVjD8DFcvveAg2iiWGhtNJGCT1ieAUzJbX3TNNJjm-5rMw@mail.gmail.com>
In-Reply-To
<xmqqy1ase1vo.fsf@gitster.g>
On Fri, Mar 8, 2024 at 3:32 PM Junio C Hamano <gitster@pobox.com> wrote:
Show 35 quoted lines
>
> Kyle Lippincott <spectral@google.com> writes:
>
> >>     $ cat ../seconary/.git
> >
> > Nit: typo, should be `secondary` (missing the `d`)
>
> Good eyes.  Thanks.
>
> >> +       /*
> >> +        * We should be a subdirectory of /.git/worktrees inside
> >> +        * the $GIT_DIR of the primary worktree.
> >> +        *
> >> +        * NEEDSWORK: some folks create secondary worktrees out of a
> >> +        * bare repository; they don't count ;-), at least not yet.
> >> +        */
> >> +       if (!strstr(path, "/.git/worktrees/"))
> >
> > Do we need to be concerned about path separators being different on
> > Windows? Or have they already been normalized here?
>
> I am not certain offhand, but if they need to tolerate different
> separators, they can send in patches.
>
> >> +               goto out;
> >> +
> >> +       /*
> >> +        * Does gitdir that points at the ".git" file at the root of
> >> +        * the secondary worktree roundtrip here?
> >> +        */
> >
> > What loss of security do we have if we don't have as stringent of a
> > check? i.e. if we just did `return !!strstr(path, "/.git/worktrees/)`?
>
> No loss of security.
Then should we just do that?
+ /* Assumption: `path` points to the root of a $GIT_DIR. */
 static int is_repo_with_working_tree(const char *path)
 {
-       return ends_with_path_components(path, ".git");
+       /* $GIT_DIR immediately below the primary working tree */
+       if (ends_with_path_components(path, ".git"))
+               return 1;
+
+       /*
+        * Also allow $GIT_DIRs in secondary worktrees.
+        * These do not end in .git, but are still considered safe because
+        * of the .git component in the path.
+        */
+       if (strstr(path, "/.git/worktrees/"))
+               return 1;
+
+       return 0;
 }
Show 17 quoted lines
>
> These "keep result the status we want to return if we want to return
> immediately here, and always jump to the out label instead of
> returning" patterns is mere a disciplined way to make it easier to
> write code that does not leak.  The very first one may not have to
> do the "goto out" and instead immediately return, but by writing
> this way, I do not need to be always looking out to shoot down
> patches that adds new check and/or allocations before this
> condition and early "out".
>
> > Or maybe we even combine the existing ends_with(.git) check with this
>
> At the mechanical level, perhaps, but I'd want logically separate
> things treated as distinct cases.  One is about being inside
> $GIT_DIR of the primary worktrees (where more than majority of users
> will encounter) and the new one is about being inside $GIT_DIR of
> secondaries.
Previous: Junio C HamanoNext: Junio C Hamano
Message 10 of 17 in “setup: allow cwd=.git w/ bareRepository=explicit”
  1. setup: allow cwd=.git w/ bareRepository=explicitKyle Lippincott via GitGitGadget, Jan 20, 2024
  2. Junio C HamanoJan 20, 2024
  3. Kyle LippincottJan 22, 2024
  4. Junio C HamanoMar 6, 2024
  5. 0/2 Loosening safe.bareRepository=explicit even furtherJunio C Hamano, Mar 8, 2024
  6. 2/2 setup: make bareRepository=explicit work in GIT_DIR of a secondary worktreeJunio C Hamano, Mar 8, 2024
  7. Junio C HamanoMar 8, 2024
  8. Kyle LippincottMar 8, 2024
  9. Junio C HamanoMar 8, 2024
  10. Kyle LippincottMar 9, 2024
  11. Junio C HamanoMar 9, 2024
  12. Kyle MeyerMar 9, 2024
  13. Junio C HamanoMar 9, 2024
  14. 1/2 setup: detect to be in $GIT_DIR with a new helperJunio C Hamano, Mar 8, 2024
  15. setup: notice more types of implicit bare repositoriesJunio C Hamano, Mar 9, 2024
  16. Kyle LippincottMar 11, 2024
  17. Junio C HamanoMar 11, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.