]> git.ipfire.org Git - thirdparty/git.git/commitdiff
scalar: validate the optional enlistment argument
authorJohannes Schindelin <johannes.schindelin@gmx.de>
Sat, 28 May 2022 23:11:14 +0000 (16:11 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 31 May 2022 06:07:31 +0000 (23:07 -0700)
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>
contrib/scalar/scalar.c
contrib/scalar/t/t9099-scalar.sh

index 58ca0e56f14ab9059399203990648730a59a84a3..6d58c7a69805a2e1be7a3c4878fcf1095d987c45 100644 (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);
index 89781568f43abf301b6df3a932b064c44ecd3e80..bb42354a8ba45fc513a6b4a3253be9eaedd2ab22 100755 (executable)
@@ -93,4 +93,9 @@ test_expect_success 'scalar supports -c/-C' '
        test true = "$(git -C sub config core.preloadIndex)"
 '
 
+test_expect_success '`scalar [...] <dir>` errors out when dir is missing' '
+       ! scalar run config cloned 2>err &&
+       grep "cloned. does not exist" err
+'
+
 test_done