test-tool path-utils: support debugging "dubious ownership" issues

This adds a new sub-sub-command for `test-tool`, simply passing through the command-line arguments to the `is_path_owned_by_current_user()` function. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Mar 25, 2025 at 10:38 UTC 5bb88e89efc8b4babb2e2818063ebe88f482f82b
1 file changed +19
t/helper/test-path-utils.c
+19
@@ -504,6 +504,25 @@ int cmd__path_utils(int argc, const char **argv)
504 return !!res;
505 }
506
507 + if (argc > 1 && !strcmp(argv[1], "is_path_owned_by_current_user")) {
508 + int res = 0;
509 +
510 + for (int i = 2; i < argc; i++) {
511 + struct strbuf buf = STRBUF_INIT;
512 +
513 + if (is_path_owned_by_current_user(argv[i], &buf))
514 + printf("'%s' is owned by current SID\n", argv[i]);
515 + else {
516 + printf("'%s' is not owned by current SID: %s\n", argv[i], buf.buf);
517 + res = 1;
518 + }
519 +
520 + strbuf_release(&buf);
521 + }
522 +
523 + return res;
524 + }
525 +
526 fprintf(stderr, "%s: unknown function name: %s\n", argv[0],
527 argv[1] ? argv[1] : "(there was none)");
528 return 1;