From patchwork Mon Aug 14 15:12:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 13353003 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0EB5BC04A94 for ; Mon, 14 Aug 2023 15:13:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232679AbjHNPMm (ORCPT ); Mon, 14 Aug 2023 11:12:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48380 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232749AbjHNPM1 (ORCPT ); Mon, 14 Aug 2023 11:12:27 -0400 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 936B51701 for ; Mon, 14 Aug 2023 08:12:21 -0700 (PDT) Received: by mail-wr1-x436.google.com with SMTP id ffacd0b85a97d-3196afc7d4bso1749525f8f.3 for ; Mon, 14 Aug 2023 08:12:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692025939; x=1692630739; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=W2FQoPMLFnkA9AHBm5fQVhne5jALeyP9JS8KJLLnMmk=; b=HM/V4/NvLVJTySjJW8m3lJy3aki2iZyS4JYsirjb1aEMIpz75IuWagwweRYGrYETMo hn9mxPsD8ByFV3qnjkAzegoThT1gyzNY1N0yVIezDAVEtjzu/j8Ws7px7JSAYD9FZZIL H4j67QA39CkpsPgSdtp1ab15skA//SlkdszFp/K/H6SRZpyShETpSFbcKwYFO+8Jf4zW 9Kx4m9mLAzAPe4I3X7GF2bG6J5W7BWYbG8tCb6YEwKJgJNqlkycVd4BZML0eBpxqvwOy yeu1W+ZAdcRhKsoQNq+3bhRXjAvganxNkC3vnTMSakOEz8u4n1zv+Eabj3KJPVLgW3Db ufLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692025939; x=1692630739; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=W2FQoPMLFnkA9AHBm5fQVhne5jALeyP9JS8KJLLnMmk=; b=h3HH2yVglUGJRhJhBqaP8i8w1LcXQi6OFmUw2ac78Iqt1OCYl6tXAEIG/1eUPzQz3O runjBrLTKI8rGngry4UmCqSKPU0hz3TUIrUD0MBT5PoP6EzV2lbS0Gm8CqEwR4RsfRJE cxI/3CzCIUoOK5uH22r5R+9d6Giwfxmy0BbGj02j+dUVjo4ueX0tU/0UdUJwJH3Nbxj3 8NXfvoSALWfl0BGWX+zjsosbaC+EmkYnYpx5d304Z5X7LjSfWQKqDhyPyURYsflKwmIc kFd8qHllw1gzC2R8BBzKnLLLEz8LToB1pGbMcJDjODd9ksNGswYQyZ/uyvbCaBti56dX ggJA== X-Gm-Message-State: AOJu0YzAixHH9jkRzwA2MtM+MCfh7zEuXP2jM+W99A6jpG0Xtez+hpTR 5LD7rCPB5gCnTkGOoIQhSL0SluIh2TA= X-Google-Smtp-Source: AGHT+IH+g9fQvMPSFTE4Q+Ni7jNL9JMvXWkfXNduBDXZkeu7I9dwkKk/t1ZMjaRCQ1XquyILmeHPEw== X-Received: by 2002:adf:f2d2:0:b0:319:63f3:c0cb with SMTP id d18-20020adff2d2000000b0031963f3c0cbmr6365981wrp.40.1692025939437; Mon, 14 Aug 2023 08:12:19 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id a4-20020a5d53c4000000b00319756d5b80sm4493866wrw.29.2023.08.14.08.12.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Aug 2023 08:12:19 -0700 (PDT) Message-ID: In-Reply-To: References: Date: Mon, 14 Aug 2023 15:12:15 +0000 Subject: [PATCH 1/3] scalar: add --[no-]src option Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: gitster@pobox.com, johannes.schindelin@gmx.de, Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee Some users have strong aversions to Scalar's opinion that the repository should be in a 'src' directory, even though it creates a clean slate for placing build outputs in adjacent directories. The --no-src option allows users to opt-out of the default behavior. While adding options, make sure the usage output by 'scalar clone -h' reports the same as the SYNOPSIS line in Documentation/scalar.txt. Signed-off-by: Derrick Stolee --- Documentation/scalar.txt | 8 +++++++- scalar.c | 11 +++++++++-- t/t9211-scalar-clone.sh | 8 ++++++++ 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/Documentation/scalar.txt b/Documentation/scalar.txt index f33436c7f65..cd65b3e230d 100644 --- a/Documentation/scalar.txt +++ b/Documentation/scalar.txt @@ -8,7 +8,8 @@ scalar - A tool for managing large Git repositories SYNOPSIS -------- [verse] -scalar clone [--single-branch] [--branch ] [--full-clone] [] +scalar clone [--single-branch] [--branch ] [--full-clone] + [--[no-]src] [] scalar list scalar register [] scalar unregister [] @@ -80,6 +81,11 @@ remote-tracking branch for the branch this option was used for the initial cloning. If the HEAD at the remote did not point at any branch when `--single-branch` clone was made, no remote-tracking branch is created. +--[no-]src:: + Specify if the repository should be created within a `src` directory + within ``. This is the default behavior, so use + `--no-src` to opt-out of the creation of the `src` directory. + --[no-]full-clone:: A sparse-checkout is initialized by default. This behavior can be turned off via `--full-clone`. diff --git a/scalar.c b/scalar.c index df7358f481c..938bb73f3ce 100644 --- a/scalar.c +++ b/scalar.c @@ -409,6 +409,7 @@ static int cmd_clone(int argc, const char **argv) { const char *branch = NULL; int full_clone = 0, single_branch = 0, show_progress = isatty(2); + int src = 1; struct option clone_options[] = { OPT_STRING('b', "branch", &branch, N_(""), N_("branch to checkout after clone")), @@ -417,10 +418,13 @@ static int cmd_clone(int argc, const char **argv) OPT_BOOL(0, "single-branch", &single_branch, N_("only download metadata for the branch that will " "be checked out")), + OPT_BOOL(0, "src", &src, + N_("create repository within 'src' directory")), OPT_END(), }; const char * const clone_usage[] = { - N_("scalar clone [] [--] []"), + N_("scalar clone [--single-branch] [--branch ] [--full-clone]\n" + "\t[--[no-]src] []"), NULL }; const char *url; @@ -456,7 +460,10 @@ static int cmd_clone(int argc, const char **argv) if (is_directory(enlistment)) die(_("directory '%s' exists already"), enlistment); - dir = xstrfmt("%s/src", enlistment); + if (src) + dir = xstrfmt("%s/src", enlistment); + else + dir = xstrdup(enlistment); strbuf_reset(&buf); if (branch) diff --git a/t/t9211-scalar-clone.sh b/t/t9211-scalar-clone.sh index 872ad1c9c2b..7ee73aba092 100755 --- a/t/t9211-scalar-clone.sh +++ b/t/t9211-scalar-clone.sh @@ -180,4 +180,12 @@ test_expect_success 'scalar clone warns when background maintenance fails' ' grep "could not turn on maintenance" err ' +test_expect_success '`scalar clone --no-src`' ' + scalar clone --src "file://$(pwd)/to-clone" with-src && + scalar clone --no-src "file://$(pwd)/to-clone" without-src && + + test_path_is_dir with-src/src && + test_path_is_missing without-src/src +' + test_done From patchwork Mon Aug 14 15:12:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 13353006 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 52D21C05052 for ; Mon, 14 Aug 2023 15:13:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232708AbjHNPMn (ORCPT ); Mon, 14 Aug 2023 11:12:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48402 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232762AbjHNPM2 (ORCPT ); Mon, 14 Aug 2023 11:12:28 -0400 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 408481705 for ; Mon, 14 Aug 2023 08:12:22 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id ffacd0b85a97d-3196fdb3238so1524392f8f.2 for ; Mon, 14 Aug 2023 08:12:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692025940; x=1692630740; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=acCVgj/MHDyqLLBjR9qI3rCSPLZ2cTxNAsxbj86HRlY=; b=FT0ZCi5+84fCXTCtYjpZb6BzC2gZ5b8hQYt/6E/AeqjNTjY1m03caqXB/WKZRp/yXZ ZHrgsj08+NjjJYAcD6Q0tgp0zoHMu4SC1tW0PHArOxCZFkwzTbL2TUPUtuQB4WoEyHzb rwmN8th3dUWTIJazdTlnanyIWsInqYN+sAXjU2G4KVa1svk5Y0pyqhanoKXuqdZkq+sQ tQDRwFiY2/ihu784GG1h7S1aLQ/TA6VPHkRR1zyEwdT4LIrzZXzGewqSNMeq49VC5jSp 7ompBWUCT7TcqlUY0hV4rjL1/hlEVAIpUhRyEVXB7LCCBKJxzokeFseatzurHtk5zowZ upvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692025940; x=1692630740; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=acCVgj/MHDyqLLBjR9qI3rCSPLZ2cTxNAsxbj86HRlY=; b=KXGPPZWL4oMQ5bSITkE1uUwLeGzyzLPqfnneXyyhA8P+z7d6YLtM6VPyPYCN+dE2Vc 1rOGpdc1ZqQZ2hIG4QlGBqwaUJraaUnM2JCUnQEILyzc7957QT3J01ayZYEoNMtZbGd/ osLhTweul37/fZIdt4qKLp3JFieym+fSympDjnNpz3nh2c/puEZWC+1e8ckZNP5ZoBpE pwVjhWGir6159cpNQ/MeHjhHwpo6we1OJv3akrJnyLAfoajIcmfOI+pn3HdRT3arZtzw 7PXlud0K362pdtzfz4xizhMjYWvaw3G9qTOhcdw1YxE4KBId4nIshiMfo3h7NIFggcUX T51w== X-Gm-Message-State: AOJu0YzIB45TPEqK3JEZ9eaTGl94v3LnQlT5XhB/T98082DAS+mZNTyK Lj6oxzUoS5P4ER23J2PS+Pu6476H/RU= X-Google-Smtp-Source: AGHT+IEp1xXfaI4E//1MRQH791TKtefTdpsMiQ0PGtMTegq+KiGYx/C7hTeFoSJvaEMeTWu85wHe5Q== X-Received: by 2002:adf:e607:0:b0:315:adf3:67db with SMTP id p7-20020adfe607000000b00315adf367dbmr7348371wrm.59.1692025940170; Mon, 14 Aug 2023 08:12:20 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id w2-20020a05600c014200b003fbc9b9699dsm14493058wmm.45.2023.08.14.08.12.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Aug 2023 08:12:19 -0700 (PDT) Message-ID: In-Reply-To: References: Date: Mon, 14 Aug 2023 15:12:16 +0000 Subject: [PATCH 2/3] setup: add discover_git_directory_reason() Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: gitster@pobox.com, johannes.schindelin@gmx.de, Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee There are many reasons why discovering a Git directory may fail. In particular, 8959555cee7 (setup_git_directory(): add an owner check for the top-level directory, 2022-03-02) added ownership checks as a security precaution. Callers attempting to set up a Git directory may want to inform the user about the reason for the failure. For that, expose the enum discovery_result from within setup.c and into cache.h where discover_git_directory() is defined. I initially wanted to change the return type of discover_git_directory() to be this enum, but several callers rely upon the "zero means success". The two problems with this are: 1. The zero value of the enum is actually GIT_DIR_NONE, so nonpositive results are errors. 2. There are multiple successful states, so some positive results are successful. Instead of updating all callers immediately, add a new method, discover_git_directory_reason(), and convert discover_git_directory() to be a thin shim on top of it. Because there are extra checks that discover_git_directory_reason() does after setup_git_directory_gently_1(), there are other modes that can be returned for failure states. Add these modes to the enum, but be sure to explicitly add them as BUG() states in the switch of setup_git_directory_gently(). Signed-off-by: Derrick Stolee --- setup.c | 32 +++++++++++--------------------- setup.h | 32 ++++++++++++++++++++++++++++++-- 2 files changed, 41 insertions(+), 23 deletions(-) diff --git a/setup.c b/setup.c index 18927a847b8..bbf8f684d93 100644 --- a/setup.c +++ b/setup.c @@ -1221,19 +1221,6 @@ static const char *allowed_bare_repo_to_string( return NULL; } -enum discovery_result { - GIT_DIR_NONE = 0, - GIT_DIR_EXPLICIT, - GIT_DIR_DISCOVERED, - GIT_DIR_BARE, - /* these are errors */ - GIT_DIR_HIT_CEILING = -1, - GIT_DIR_HIT_MOUNT_POINT = -2, - GIT_DIR_INVALID_GITFILE = -3, - GIT_DIR_INVALID_OWNERSHIP = -4, - GIT_DIR_DISALLOWED_BARE = -5, -}; - /* * We cannot decide in this function whether we are in the work tree or * not, since the config can only be read _after_ this function was called. @@ -1385,21 +1372,22 @@ static enum discovery_result setup_git_directory_gently_1(struct strbuf *dir, } } -int discover_git_directory(struct strbuf *commondir, - struct strbuf *gitdir) +enum discovery_result discover_git_directory_reason(struct strbuf *commondir, + struct strbuf *gitdir) { struct strbuf dir = STRBUF_INIT, err = STRBUF_INIT; size_t gitdir_offset = gitdir->len, cwd_len; size_t commondir_offset = commondir->len; struct repository_format candidate = REPOSITORY_FORMAT_INIT; + enum discovery_result result; if (strbuf_getcwd(&dir)) - return -1; + return GIT_DIR_CWD_FAILURE; cwd_len = dir.len; - if (setup_git_directory_gently_1(&dir, gitdir, NULL, 0) <= 0) { + if ((result = setup_git_directory_gently_1(&dir, gitdir, NULL, 0)) <= 0) { strbuf_release(&dir); - return -1; + return result; } /* @@ -1429,11 +1417,11 @@ int discover_git_directory(struct strbuf *commondir, strbuf_setlen(commondir, commondir_offset); strbuf_setlen(gitdir, gitdir_offset); clear_repository_format(&candidate); - return -1; + return GIT_DIR_INVALID_FORMAT; } clear_repository_format(&candidate); - return 0; + return result; } const char *setup_git_directory_gently(int *nongit_ok) @@ -1516,9 +1504,11 @@ const char *setup_git_directory_gently(int *nongit_ok) *nongit_ok = 1; break; case GIT_DIR_NONE: + case GIT_DIR_CWD_FAILURE: + case GIT_DIR_INVALID_FORMAT: /* * As a safeguard against setup_git_directory_gently_1 returning - * this value, fallthrough to BUG. Otherwise it is possible to + * these values, fallthrough to BUG. Otherwise it is possible to * set startup_info->have_repository to 1 when we did nothing to * find a repository. */ diff --git a/setup.h b/setup.h index 58fd2605dd2..b87d0d6fb2b 100644 --- a/setup.h +++ b/setup.h @@ -42,6 +42,30 @@ const char *resolve_gitdir_gently(const char *suspect, int *return_error_code); #define resolve_gitdir(path) resolve_gitdir_gently((path), NULL) void setup_work_tree(void); + +/* + * discover_git_directory_reason() is similar to discover_git_directory(), + * except it returns an enum value instead. It is important to note that + * a zero-valued return here is actually GIT_DIR_NONE, which is different + * from discover_git_directory. + */ +enum discovery_result { + GIT_DIR_NONE = 0, + GIT_DIR_EXPLICIT, + GIT_DIR_DISCOVERED, + GIT_DIR_BARE, + /* these are errors */ + GIT_DIR_HIT_CEILING = -1, + GIT_DIR_HIT_MOUNT_POINT = -2, + GIT_DIR_INVALID_GITFILE = -3, + GIT_DIR_INVALID_OWNERSHIP = -4, + GIT_DIR_DISALLOWED_BARE = -5, + GIT_DIR_INVALID_FORMAT = -6, + GIT_DIR_CWD_FAILURE = -7, +}; +enum discovery_result discover_git_directory_reason(struct strbuf *commondir, + struct strbuf *gitdir); + /* * Find the commondir and gitdir of the repository that contains the current * working directory, without changing the working directory or other global @@ -50,8 +74,12 @@ void setup_work_tree(void); * both have the same result appended to the buffer. The return value is * either 0 upon success and non-zero if no repository was found. */ -int discover_git_directory(struct strbuf *commondir, - struct strbuf *gitdir); +static inline int discover_git_directory(struct strbuf *commondir, + struct strbuf *gitdir) +{ + return discover_git_directory_reason(commondir, gitdir) <= 0; +} + const char *setup_git_directory_gently(int *); const char *setup_git_directory(void); char *prefix_path(const char *prefix, int len, const char *path); From patchwork Mon Aug 14 15:12:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 13353005 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 32196C04FE1 for ; Mon, 14 Aug 2023 15:13:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232719AbjHNPMo (ORCPT ); Mon, 14 Aug 2023 11:12:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48440 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232777AbjHNPM2 (ORCPT ); Mon, 14 Aug 2023 11:12:28 -0400 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 883D51708 for ; Mon, 14 Aug 2023 08:12:22 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id ffacd0b85a97d-317716a4622so3922925f8f.1 for ; Mon, 14 Aug 2023 08:12:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692025941; x=1692630741; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=51dI2tivwgeKa9JyBbrBM77QQNcKKmUn35cLx5RYQ38=; b=guyuck2Ow/lEJHrC3HxDW2z1psqm4lbFSrzq5xi7Ajo63hDUHh92uf4uz9ofr8UwS5 VkdS3/TgJDZZP3j72TwTwu6L+NIhZ9crXOqxrpGq1QWttV8wcoS9hLubZ1v/GyuMjGsG Za8G70JJUCb3BOIfzvIAIWZqrXpfQ7qZEwmZNZJJ4GXcSuaDly6D6BOuklfVfq1JEWNR oHuJvk6dTRpm0rcayQc0WdWDo+3WWn/6cUgUbU8ompj/zLiv+3mBqABa1HoIXwKtOO8O u0tNkrPSYHP1zdLN/SYY1Dk3C8Rjf2pY71qrNJo6JSb3+sWBSGsp/g8kLpDqrcwfv4IM PiRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692025941; x=1692630741; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=51dI2tivwgeKa9JyBbrBM77QQNcKKmUn35cLx5RYQ38=; b=fj2H2UsreTMgMRg5NaS8hIU3bk3/XXb/4YtFiqhLEsv9OcgffETBGXJ98uyKjRD+8Z rP+mvodH7thQ1spl75Q3PqwRjavQlPRk0MoOgBJQtKg+rR1NQDKvKqdla9WQQ00YdAv4 pIYH6z6BgXkqOEmwFkpAjIXwkoGHPdkUygOyjHrB4edwZpLZT+RaRHX0TBb5fdJ+Hzu+ xhhKW6RRQJCIPa0EbbqVQxSbFKP0dbyhk19RR5t3ASG0qiHCz7SjYerCJAeQ33NzwZHl LqG0HBZojRfkzHJuviqDmvqQUH7MK0+VmrC+idnueRtT7UMlJA326+FmwSBc+dPW0JSN V4Lg== X-Gm-Message-State: AOJu0YyXSTik1nSuBirX7+LAUKpnPThJK9f82fCbYLtA7bCClzwX//W1 4QYnaLDQUa+h+O14X6KyjBhBdfgKzHU= X-Google-Smtp-Source: AGHT+IGpjlW9QxsSRLYcybNCnR9lTDSjpzffMxgQyFsFKwB4TsCkzTyX7xasahG4H0HISa21sZkd4A== X-Received: by 2002:a5d:420e:0:b0:313:e48a:d173 with SMTP id n14-20020a5d420e000000b00313e48ad173mr7681031wrq.68.1692025940777; Mon, 14 Aug 2023 08:12:20 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id x13-20020a5d444d000000b00317f29ad113sm14611425wrr.32.2023.08.14.08.12.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Aug 2023 08:12:20 -0700 (PDT) Message-ID: <907410f76c4a5d7ef325545f52696a9a0c00b6b3.1692025937.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 14 Aug 2023 15:12:17 +0000 Subject: [PATCH 3/3] scalar reconfigure: help users remove buggy repos Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: gitster@pobox.com, johannes.schindelin@gmx.de, Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee When running 'scalar reconfigure -a', Scalar has warning messages about the repository missing (or not containing a .git directory). Failures can also happen while trying to modify the repository-local config for that repository. These warnings may seem confusing to users who don't understand what they mean or how to stop them. Add a warning that instructs the user how to remove the warning in future installations. Signed-off-by: Derrick Stolee --- scalar.c | 56 +++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 39 insertions(+), 17 deletions(-) diff --git a/scalar.c b/scalar.c index 938bb73f3ce..7d87d7ea724 100644 --- a/scalar.c +++ b/scalar.c @@ -664,6 +664,7 @@ static int cmd_reconfigure(int argc, const char **argv) git_config(get_scalar_repos, &scalar_repos); for (i = 0; i < scalar_repos.nr; i++) { + int failed = 0; const char *dir = scalar_repos.items[i].string; strbuf_reset(&commondir); @@ -674,30 +675,51 @@ static int cmd_reconfigure(int argc, const char **argv) if (errno != ENOENT) { warning_errno(_("could not switch to '%s'"), dir); - res = -1; - continue; + failed = -1; + goto loop_end; } strbuf_addstr(&buf, dir); if (remove_deleted_enlistment(&buf)) - res = error(_("could not remove stale " - "scalar.repo '%s'"), dir); + failed = error(_("could not remove stale " + "scalar.repo '%s'"), dir); else - warning(_("removing stale scalar.repo '%s'"), + warning(_("removed stale scalar.repo '%s'"), dir); strbuf_release(&buf); - } else if (discover_git_directory(&commondir, &gitdir) < 0) { - warning_errno(_("git repository gone in '%s'"), dir); - res = -1; - } else { - git_config_clear(); - - the_repository = &r; - r.commondir = commondir.buf; - r.gitdir = gitdir.buf; - - if (set_recommended_config(1) < 0) - res = -1; + goto loop_end; + } + + switch (discover_git_directory_reason(&commondir, &gitdir)) { + case GIT_DIR_INVALID_OWNERSHIP: + warning(_("repository at '%s' has different owner"), dir); + failed = -1; + goto loop_end; + + case GIT_DIR_DISCOVERED: + break; + + default: + warning(_("repository not found in '%s'"), dir); + failed = -1; + break; + } + + git_config_clear(); + + the_repository = &r; + r.commondir = commondir.buf; + r.gitdir = gitdir.buf; + + if (set_recommended_config(1) < 0) + failed = -1; + +loop_end: + if (failed) { + res = failed; + warning(_("to unregister this repository from Scalar, run\n" + "\tgit config --global --unset --fixed-value scalar.repo \"%s\""), + dir); } }