scalar: validate the optional enlistment argument

The `scalar` command needs a Scalar enlistment for many subcommands, and
looks in the current directory for such an enlistment (traversing the
parent directories until it finds one).

These is subcommands can also be called with an optional argument
specifying the enlistment. Here, too, we traverse parent directories as
needed, until we find an enlistment.

However, if the specified directory does not even exist, or is not a
directory, we should stop right there, with an error message.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Johannes Schindelin
2022-05-28 16:11:14 -07:00
committed by Junio C Hamano
parent de1f68a968
commit b44855743b
2 changed files with 9 additions and 2 deletions

View File

@ -43,9 +43,11 @@ static void setup_enlistment_directory(int argc, const char **argv,
usage_with_options(usagestr, options);
/* find the worktree, determine its corresponding root */
if (argc == 1)
if (argc == 1) {
strbuf_add_absolute_path(&path, argv[0]);
else if (strbuf_getcwd(&path) < 0)
if (!is_directory(path.buf))
die(_("'%s' does not exist"), path.buf);
} else if (strbuf_getcwd(&path) < 0)
die(_("need a working directory"));
strbuf_trim_trailing_dir_sep(&path);