From: Junio C Hamano Date: Mon, 08 Jun 2020 22:02:11 GMT Subject: Re: [PATCH 7/8] worktree: generalize candidate worktree path validation Message-ID: In-Reply-To: <20200608062356.40264-8-sunshine@sunshineco.com> Eric Sunshine writes: > "git worktree add" checks that the specified path is a valid location > for a new worktree by ensuring that the path does not already exist and > is not already registered to another worktree (a path can be registered > but missing, for instance, if it resides on removable media). Since "git > worktree add" is not the only command which should perform such > validation ("git worktree move" ought to also), generalize the the > validation function for use by other callers, as well. Makes sense. > - validate_worktree_add(path, opts); > + worktrees = get_worktrees(0); > + check_candidate_path(path, opts->force, worktrees, "add"); > + free_worktrees(worktrees); > + worktrees = NULL; It is somewhat unsatisfying that the libified helper still signals its displeasure by dying, but a faithful conversion that can be cleaned up later (if we wanted to) like this step is easier to reason about.