diff options
author | Eric Sunshine <sunshine@sunshineco.com> | 2020-02-24 04:08:48 -0500 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2020-02-24 13:05:07 -0800 |
commit | bb69b3b009c0093417942dba136b81fbf614c4ed (patch) | |
tree | 7ca5c5dd31f81939a0b4f3dea560ef9c3ad1983d /write-or-die.c | |
parent | worktree: add utility to find worktree by pathname (diff) | |
download | tgif-bb69b3b009c0093417942dba136b81fbf614c4ed.tar.xz |
worktree: don't allow "add" validation to be fooled by suffix matching
"git worktree add <path>" performs various checks before approving
<path> as a valid location for the new worktree. Aside from ensuring
that <path> does not already exist, one of the questions it asks is
whether <path> is already a registered worktree. To perform this check,
it queries find_worktree() and disallows the "add" operation if
find_worktree() finds a match for <path>. As a convenience, however,
find_worktree() casts an overly wide net to allow users to identify
worktrees by shorthand in order to keep typing to a minimum. For
instance, it performs suffix matching which, given subtrees "foo/bar"
and "foo/baz", can correctly select the latter when asked only for
"baz".
"add" validation knows the exact path it is interrogating, so this sort
of heuristic-based matching is, at best, questionable for this use-case
and, at worst, may may accidentally interpret <path> as matching an
existing worktree and incorrectly report it as already registered even
when it isn't. (In fact, validate_worktree_add() already contains a
special case to avoid accidentally matching against the main worktree,
precisely due to this problem.)
Avoid the problem of potential accidental matching against an existing
worktree by instead taking advantage of find_worktree_by_path() which
matches paths deterministically, without applying any sort of magic
shorthand matching performed by find_worktree().
Reported-by: Cameron Gunnin <cameron.gunnin@synopsys.com>
Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'write-or-die.c')
0 files changed, 0 insertions, 0 deletions