Skip to content

Commit b448557

Browse files
dschogitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent de1f68a commit b448557

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

contrib/scalar/scalar.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,11 @@ static void setup_enlistment_directory(int argc, const char **argv,
4343
usage_with_options(usagestr, options);
4444

4545
/* find the worktree, determine its corresponding root */
46-
if (argc == 1)
46+
if (argc == 1) {
4747
strbuf_add_absolute_path(&path, argv[0]);
48-
else if (strbuf_getcwd(&path) < 0)
48+
if (!is_directory(path.buf))
49+
die(_("'%s' does not exist"), path.buf);
50+
} else if (strbuf_getcwd(&path) < 0)
4951
die(_("need a working directory"));
5052

5153
strbuf_trim_trailing_dir_sep(&path);

contrib/scalar/t/t9099-scalar.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,9 @@ test_expect_success 'scalar supports -c/-C' '
9393
test true = "$(git -C sub config core.preloadIndex)"
9494
'
9595

96+
test_expect_success '`scalar [...] <dir>` errors out when dir is missing' '
97+
! scalar run config cloned 2>err &&
98+
grep "cloned. does not exist" err
99+
'
100+
96101
test_done

0 commit comments

Comments
 (0)