From patchwork Thu Nov 19 15:52:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 11918029 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5AD02C63697 for ; Thu, 19 Nov 2020 15:52:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D70C7246DE for ; Thu, 19 Nov 2020 15:52:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="TwN51CiD" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728790AbgKSPw1 (ORCPT ); Thu, 19 Nov 2020 10:52:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727937AbgKSPw0 (ORCPT ); Thu, 19 Nov 2020 10:52:26 -0500 Received: from mail-wr1-x444.google.com (mail-wr1-x444.google.com [IPv6:2a00:1450:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7A737C0613CF for ; Thu, 19 Nov 2020 07:52:26 -0800 (PST) Received: by mail-wr1-x444.google.com with SMTP id p1so6893721wrf.12 for ; Thu, 19 Nov 2020 07:52:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=1GgAmuFPRJYZ+FUW0eyYH5o0bmzoEDvVV5Hz6ckF9j8=; b=TwN51CiDsLbRdGqFdoBT0mraWO0deR6IaVnVN/E1ddybXIN3Nycu0DnVZkz8FVuRCk jwEURCwkQKpDart3ukUs+VTX7sA+iWk0nqBmkMo742/KjRct8YK+bAUiC2XUTnUTM+jJ LoPHpOHNOnFMlDU4h3E9WCA+mpFPJQiiDQMUhhXHsZEOWh4raIpTZYSLRyBChXi13NkF q/okd+E9YRVaFYC8s7uykss8tcLakN72BrTUS67FHENGxQcUebVzBfzpa2ypplHtLW0c FTtiGj2Ezx2kYEtDG6tFaMFDMuwjMIF/ZMY9ROlW0Urf9T7st1laWPC5cvdZLeTGFXkR PzWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=1GgAmuFPRJYZ+FUW0eyYH5o0bmzoEDvVV5Hz6ckF9j8=; b=g2jsVlzPVHp6OU4R7Mn2cS9vbSOax603Mt1PeKIZqg7kHyqLyXdANMMOJ8LMlbjH3d 88RBWFodcPtGvyI9J3fsUdPCRxC6YkFyfN8g7EWG8ckrsj6/Cud1JEiKm1cYPLUDcWvL k3KQ0puxYcWVPAxGJmURfUbN/P76HNGNI7N/hb/i8oPErsgjqlPDYlv65dZhntg1tC4j ZjoXwZLv5GJunoJESii1AOHG4r78q/7Tu5cPlWjb/cDruVdiLRMkkBE2Rdt+fAiIi5vd NAxvcaLjNHt8sMlaTb3co6mQs10oEUdBDcbKBCTJFQpUrvhSC6CyiQryS74dsb47rMDQ Telw== X-Gm-Message-State: AOAM530PIQVw49cXfOSaUJTRFQ/XPPLbitE9z+HISMXJOXyhLjQ3M7FM YZ9aoAu27emnEGOs3ePcjmtFjRvbNMo= X-Google-Smtp-Source: ABdhPJwkmW1ggq2CYymRbr9oqEt+YClaurrgE8vWa/vUfe0Mvslr+Nj56WIaDeUjLwE4bebNyT4/+w== X-Received: by 2002:a05:6000:1292:: with SMTP id f18mr10865761wrx.196.1605801145120; Thu, 19 Nov 2020 07:52:25 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id q7sm148492wrg.95.2020.11.19.07.52.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Nov 2020 07:52:24 -0800 (PST) Message-Id: <2da2131114eb47e70ccaf8fb9c51bf7fb5b173b0.1605801143.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Thu, 19 Nov 2020 15:52:17 +0000 Subject: [PATCH 1/7] t1300: test "set all" mode with value_regex Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Jonathan Nieder , Emily Shaffer , Johannes Schindelin , Jeff King , Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee Without additional modifiers, 'git config' attempts to set a single value in the .git/config file. When the value_regex parameter is supplied, this command behaves in a non-trivial manner. Consider 'git config key value value_regex'. The expected behavior is as follows: 1. If there are multiple existing values that match 'value_regex', then the command fails. Users should use --replace-all instead. 2. If there is one existing value that matches 'value_regex', then the new config has one entry where 'key=value'. 3. If there is no existing values match 'value_regex', then the 'key=value' pair is appended, making this 'key' a multi-valued config setting. Add a test that demonstrates these options. Signed-off-by: Derrick Stolee --- t/t1300-config.sh | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/t/t1300-config.sh b/t/t1300-config.sh index 97ebfe1f9d..ef56b08070 100755 --- a/t/t1300-config.sh +++ b/t/t1300-config.sh @@ -1914,4 +1914,39 @@ test_expect_success '--replace-all does not invent newlines' ' test_cmp expect .git/config ' +test_expect_success 'set all config with value_regex' ' + q_to_tab >initial <<-\EOF && + [abc] + Qkey = one + EOF + + cp initial .git/config && + git config abc.key two a+ && + q_to_tab >expect <<-\EOF && + [abc] + Qkey = one + Qkey = two + EOF + test_cmp expect .git/config && + + test_must_fail git config abc.key three o+ 2>err && + test_i18ngrep "has multiple values" err && + git config abc.key three a+ && + q_to_tab >expect <<-\EOF && + [abc] + Qkey = one + Qkey = two + Qkey = three + EOF + test_cmp expect .git/config && + + cp initial .git/config && + git config abc.key three o+ && + q_to_tab >expect <<-\EOF && + [abc] + Qkey = three + EOF + test_cmp expect .git/config +' + test_done From patchwork Thu Nov 19 15:52:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 11918031 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 89CCEC6369E for ; Thu, 19 Nov 2020 15:52:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2384322256 for ; Thu, 19 Nov 2020 15:52:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="qQYOy1Wj" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728817AbgKSPw3 (ORCPT ); Thu, 19 Nov 2020 10:52:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48520 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728798AbgKSPw2 (ORCPT ); Thu, 19 Nov 2020 10:52:28 -0500 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 39E59C0613CF for ; Thu, 19 Nov 2020 07:52:27 -0800 (PST) Received: by mail-wr1-x42d.google.com with SMTP id r17so7006026wrw.1 for ; Thu, 19 Nov 2020 07:52:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=qMTWhMN+LLjYiLcXeHd4DHknZxr/m76sFg4Y83A66QQ=; b=qQYOy1WjcCeLxJ04TrsvpBAJGB1CfSqgf/x7bWCtTZTrQpPezGbp2U2Vtem1Q/7q7w osEkQRSwGpBlVwgBikNuaFCATqmeAFUsDKQhFn0HLz00GW6oOBd3rrcHocanCtAjGJ2G H+EcYmzNmvKXOsgHY18rQr+73isYrJKhAu3ACHg5gNBYRQIzB0Lc886bCwAl0CI6ezrG isnBYNGFyZsiha400SfNKRmT+XGJnIruPPlTcrVkFyp2BRqfGhK0d3d3hsEGlHKPVa8c qK2u9/VFXPcFiCpFAxrpsVPu05748nhezGnz//dmAsDUZW1ovPbuzQqJmK+v1SiQ55TC ffWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=qMTWhMN+LLjYiLcXeHd4DHknZxr/m76sFg4Y83A66QQ=; b=uOnHfitz9UwgroyUpMCgc93SElpM2kIUWu0qScWqHsCdWMk0jU+Yxvu98vYBoLNfDl R9K8B5rHli7MYlxqWGxX4d6vEXfooEapP2j2MBkfCrY8iPF9Uosmrr6gbN4z/pZH16iz KPVFVcnxfTcIObDTgzEiUdD4k7m1YYt7VzxLYmCZ7qLvPdWtGLjQv5jBD2wdlr5IVpML FWCWQ7XXlYEfx+8PjJ2Wx15YRFbyLjKsiu4xRArwuO3CchSxVtnyJ+Tjplts2yzr+ZMY MYHaYXZ25VZdApNbx8sbphUpKEQlnyT7CKCpik4sGky1HZd+6LTeDzyq4co6uQ2MxsDL ozsA== X-Gm-Message-State: AOAM530TT71btj4uZA+XAgoJotyYcsSPjVfgcjr0EgnUByubMk0KfEgO yvA2rXiuAD2djxeSVJGMKUC29o/3TdY= X-Google-Smtp-Source: ABdhPJwWVr2iggx4F++45IOwJhCUHU9ZrgOV9B7A1LriIUWuVo76QNRv/qHmzGMkI/yiNvdLw0dMOA== X-Received: by 2002:adf:a40c:: with SMTP id d12mr11101361wra.154.1605801145840; Thu, 19 Nov 2020 07:52:25 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id u81sm464661wmb.27.2020.11.19.07.52.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Nov 2020 07:52:25 -0800 (PST) Message-Id: <1237289706d3786b332c8f5930402088a6382258.1605801143.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Thu, 19 Nov 2020 15:52:18 +0000 Subject: [PATCH 2/7] t1300: add test for --replace-all with value_regex Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Jonathan Nieder , Emily Shaffer , Johannes Schindelin , Jeff King , Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee The --replace-all option was added in 4ddba79d (git-config-set: add more options) but was not tested along with the 'value_regex' parameter. Since we will be updating this option to optionally treat 'value_regex' as a fixed string, let's add a test here that documents the current behavior. Signed-off-by: Derrick Stolee --- t/t1300-config.sh | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/t/t1300-config.sh b/t/t1300-config.sh index ef56b08070..74e0f84c0a 100755 --- a/t/t1300-config.sh +++ b/t/t1300-config.sh @@ -1949,4 +1949,20 @@ test_expect_success 'set all config with value_regex' ' test_cmp expect .git/config ' +test_expect_success '--replace-all and value_regex' ' + q_to_tab >.git/config <<-\EOF && + [abc] + Qkey = one + Qkey = two + Qkey = three + EOF + q_to_tab >expect <<-\EOF && + [abc] + Qkey = four + Qkey = three + EOF + git config --replace-all abc.key four "o+" && + test_cmp expect .git/config +' + test_done From patchwork Thu Nov 19 15:52:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 11918037 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0A5A5C64E69 for ; Thu, 19 Nov 2020 15:52:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9C68A22256 for ; Thu, 19 Nov 2020 15:52:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="SqOtTzke" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728805AbgKSPw3 (ORCPT ); Thu, 19 Nov 2020 10:52:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48526 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728753AbgKSPw2 (ORCPT ); Thu, 19 Nov 2020 10:52:28 -0500 Received: from mail-wr1-x441.google.com (mail-wr1-x441.google.com [IPv6:2a00:1450:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F363BC0613D4 for ; Thu, 19 Nov 2020 07:52:27 -0800 (PST) Received: by mail-wr1-x441.google.com with SMTP id p1so6893812wrf.12 for ; Thu, 19 Nov 2020 07:52:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=j0EWcNhXtYXBhpcUDgl/YsH4xrUwg2LxDGZ4CpK31tI=; b=SqOtTzkee1oHtd3f/KbkC86tPM3MofLp9HzJ9wlDcXa0sPau6uPZt03OlfLx3PNORX KjmjUXYVX6oz2PsUUn7fVQIsYyNoCbg4iqbnOJJOg3qcrWzCmwX/e8Xe/JX5eCdAq2Qz c01WWqjBXJXaB3+l6CniAa2cZCQWt/vdUCfJCQCQaHlFCVTKZXDioxDlDgY28dGDeC0S hrt9VC++ubPuh29Bc76aT2reEDqAhoBgyxp6YGyaRtuzACnbPakpISPuiGfIwv8Ejioc 1n4JPqgcpTE4RCGRt+ESgMXxzberPy82O657lqxcs0q5EPF6zblJfyJtC3fAhZ+9wLn3 2rlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=j0EWcNhXtYXBhpcUDgl/YsH4xrUwg2LxDGZ4CpK31tI=; b=Mh5hFk6d70FWUcVWWkZbgnjWNdY118wHKXzRQjR2tjPunzzTcmFQPzjYcjletx4RAB 3vxl2rgsQDGkd31u/arHqWjS36ydCUBbhglVNa6WzlMyPE7BZrkDq31vyzkq95fdd4t8 +5MvEL+Q5cdU0h3Vh2s+8RRoq5KUh3P6I9JGUGYF/qMOB8WMWUYwAJ6MjtKhlFnRWdK+ yAYgZH3Vq0NRNd3LyOCjnL8N0XJtRFmjgBAdi2GYY3p+v5Pl4Y1RiT9I2LloVL2py3JR m7WOPi7Yf/vdXvi7MPU22TIbsV7+96g1sdS8aDFgw8M6pnA5Nh3XhcR0mbBDIIIHRKgm UAsw== X-Gm-Message-State: AOAM530rF4mJtQUJVUzw/iVnDqKDqSssAMBSb6sMB69jrbIrruoiNg56 NunYQft5Tk3F8mNXW/KFLn8tY5O4pg8= X-Google-Smtp-Source: ABdhPJybwD/D/Pt3DIj2vHP/mzNf9fjRP23keAv4HM4Is6lBY9a8JIQuB2yf35+qtW3dsbptVV83xQ== X-Received: by 2002:adf:f90f:: with SMTP id b15mr11105121wrr.343.1605801146517; Thu, 19 Nov 2020 07:52:26 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id a9sm229129wrp.21.2020.11.19.07.52.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Nov 2020 07:52:26 -0800 (PST) Message-Id: In-Reply-To: References: Date: Thu, 19 Nov 2020 15:52:19 +0000 Subject: [PATCH 3/7] config: convert multi_replace to flags Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Jonathan Nieder , Emily Shaffer , Johannes Schindelin , Jeff King , Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee We will extend the flexibility of the config API. Before doing so, let's take an existing 'int multi_replace' parameter and replace it with a new 'int flags' parameter that can take multiple options as a bit field. Update all callers that specified multi_replace to now specify the CONFIG_FLAGS_MULTI_REPLACE flag. To add more clarity, extend the documentation of git_config_set_multivar_in_file() including a clear labeling of its arguments. Other config API methods in config.h do not require a change to their prototypes, but they have an equivalent update to their implementations. Signed-off-by: Derrick Stolee --- builtin/branch.c | 4 ++-- builtin/config.c | 6 ++++-- builtin/remote.c | 8 +++++--- config.c | 24 ++++++++++++------------ config.h | 17 +++++++++++++---- 5 files changed, 36 insertions(+), 23 deletions(-) diff --git a/builtin/branch.c b/builtin/branch.c index e82301fb1b..5ce3844d22 100644 --- a/builtin/branch.c +++ b/builtin/branch.c @@ -829,10 +829,10 @@ int cmd_branch(int argc, const char **argv, const char *prefix) die(_("Branch '%s' has no upstream information"), branch->name); strbuf_addf(&buf, "branch.%s.remote", branch->name); - git_config_set_multivar(buf.buf, NULL, NULL, 1); + git_config_set_multivar(buf.buf, NULL, NULL, CONFIG_FLAGS_MULTI_REPLACE); strbuf_reset(&buf); strbuf_addf(&buf, "branch.%s.merge", branch->name); - git_config_set_multivar(buf.buf, NULL, NULL, 1); + git_config_set_multivar(buf.buf, NULL, NULL, CONFIG_FLAGS_MULTI_REPLACE); strbuf_release(&buf); } else if (argc > 0 && argc <= 2) { if (filter.kind != FILTER_REFS_BRANCHES) diff --git a/builtin/config.c b/builtin/config.c index 5e39f61885..e7c7f3d455 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -823,7 +823,8 @@ int cmd_config(int argc, const char **argv, const char *prefix) value = normalize_value(argv[0], argv[1]); UNLEAK(value); return git_config_set_multivar_in_file_gently(given_config_source.file, - argv[0], value, argv[2], 1); + argv[0], value, argv[2], + CONFIG_FLAGS_MULTI_REPLACE); } else if (actions == ACTION_GET) { check_argc(argc, 1, 2); @@ -859,7 +860,8 @@ int cmd_config(int argc, const char **argv, const char *prefix) check_write(); check_argc(argc, 1, 2); return git_config_set_multivar_in_file_gently(given_config_source.file, - argv[0], NULL, argv[1], 1); + argv[0], NULL, argv[1], + CONFIG_FLAGS_MULTI_REPLACE); } else if (actions == ACTION_RENAME_SECTION) { int ret; diff --git a/builtin/remote.c b/builtin/remote.c index c8240e9fcd..29b1652975 100644 --- a/builtin/remote.c +++ b/builtin/remote.c @@ -708,7 +708,7 @@ static int mv(int argc, const char **argv) strbuf_reset(&buf); strbuf_addf(&buf, "remote.%s.fetch", rename.new_name); - git_config_set_multivar(buf.buf, NULL, NULL, 1); + git_config_set_multivar(buf.buf, NULL, NULL, CONFIG_FLAGS_MULTI_REPLACE); strbuf_addf(&old_remote_context, ":refs/remotes/%s/", rename.old_name); for (i = 0; i < oldremote->fetch.raw_nr; i++) { char *ptr; @@ -1485,7 +1485,8 @@ static int update(int argc, const char **argv) static int remove_all_fetch_refspecs(const char *key) { - return git_config_set_multivar_gently(key, NULL, NULL, 1); + return git_config_set_multivar_gently(key, NULL, NULL, + CONFIG_FLAGS_MULTI_REPLACE); } static void add_branches(struct remote *remote, const char **branches, @@ -1674,7 +1675,8 @@ static int set_url(int argc, const char **argv) if (!delete_mode) git_config_set_multivar(name_buf.buf, newurl, oldurl, 0); else - git_config_set_multivar(name_buf.buf, NULL, oldurl, 1); + git_config_set_multivar(name_buf.buf, NULL, oldurl, + CONFIG_FLAGS_MULTI_REPLACE); out: strbuf_release(&name_buf); return 0; diff --git a/config.c b/config.c index 2b79fe76ad..4841c68a91 100644 --- a/config.c +++ b/config.c @@ -2716,9 +2716,9 @@ void git_config_set(const char *key, const char *value) * if value_regex!=NULL, disregard key/value pairs where value does not match. * if value_regex==CONFIG_REGEX_NONE, do not match any existing values * (only add a new one) - * if multi_replace==0, nothing, or only one matching key/value is replaced, - * else all matching key/values (regardless how many) are removed, - * before the new pair is written. + * if (flags & CONFIG_FLAGS_MULTI_REPLACE) == 0, at most one matching + * key/value is replaced, else all matching key/values (regardless + * how many) are removed, before the new pair is written. * * Returns 0 on success. * @@ -2739,7 +2739,7 @@ void git_config_set(const char *key, const char *value) int git_config_set_multivar_in_file_gently(const char *config_filename, const char *key, const char *value, const char *value_regex, - int multi_replace) + int flags) { int fd = -1, in_fd = -1; int ret; @@ -2756,7 +2756,7 @@ int git_config_set_multivar_in_file_gently(const char *config_filename, if (ret) goto out_free; - store.multi_replace = multi_replace; + store.multi_replace = (flags & CONFIG_FLAGS_MULTI_REPLACE) != 0; if (!config_filename) config_filename = filename_buf = git_pathdup("config"); @@ -2845,7 +2845,7 @@ int git_config_set_multivar_in_file_gently(const char *config_filename, /* if nothing to unset, or too many matches, error out */ if ((store.seen_nr == 0 && value == NULL) || - (store.seen_nr > 1 && multi_replace == 0)) { + (store.seen_nr > 1 && !store.multi_replace)) { ret = CONFIG_NOTHING_SET; goto out_free; } @@ -2984,10 +2984,10 @@ int git_config_set_multivar_in_file_gently(const char *config_filename, void git_config_set_multivar_in_file(const char *config_filename, const char *key, const char *value, - const char *value_regex, int multi_replace) + const char *value_regex, int flags) { if (!git_config_set_multivar_in_file_gently(config_filename, key, value, - value_regex, multi_replace)) + value_regex, flags)) return; if (value) die(_("could not set '%s' to '%s'"), key, value); @@ -2996,17 +2996,17 @@ void git_config_set_multivar_in_file(const char *config_filename, } int git_config_set_multivar_gently(const char *key, const char *value, - const char *value_regex, int multi_replace) + const char *value_regex, int flags) { return git_config_set_multivar_in_file_gently(NULL, key, value, value_regex, - multi_replace); + flags); } void git_config_set_multivar(const char *key, const char *value, - const char *value_regex, int multi_replace) + const char *value_regex, int flags) { git_config_set_multivar_in_file(NULL, key, value, value_regex, - multi_replace); + flags); } static int section_name_match (const char *buf, const char *name) diff --git a/config.h b/config.h index 060874488f..266eb22e46 100644 --- a/config.h +++ b/config.h @@ -70,6 +70,13 @@ enum config_event_t { CONFIG_EVENT_ERROR }; +/* + * When CONFIG_FLAGS_MULTI_REPLACE is specified, all matching key/values + * are removed before a new pair is written. If the flag is not present, + * then set operations replace only the first match. + */ +#define CONFIG_FLAGS_MULTI_REPLACE (1 << 0) + /* * The parser event function (if not NULL) is called with the event type and * the begin/end offsets of the parsed elements. @@ -276,13 +283,15 @@ int git_config_set_multivar_in_file_gently(const char *, const char *, const cha * - the value regex, as a string. It will disregard key/value pairs where value * does not match. * - * - a multi_replace value, as an int. If value is equal to zero, nothing or only - * one matching key/value is replaced, else all matching key/values (regardless - * how many) are removed, before the new pair is written. + * - a flags value with bits corresponding to the CONFIG_FLAG_* macros. * * It returns 0 on success. */ -void git_config_set_multivar_in_file(const char *, const char *, const char *, const char *, int); +void git_config_set_multivar_in_file(const char *config_filename, + const char *key, + const char *value, + const char *value_regex, + int flags); /** * rename or remove sections in the config file From patchwork Thu Nov 19 15:52:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 11918035 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 78C27C64E75 for ; Thu, 19 Nov 2020 15:52:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2C95422256 for ; Thu, 19 Nov 2020 15:52:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="jLD5mGxT" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728840AbgKSPwf (ORCPT ); Thu, 19 Nov 2020 10:52:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48554 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727937AbgKSPwd (ORCPT ); Thu, 19 Nov 2020 10:52:33 -0500 Received: from mail-wm1-x344.google.com (mail-wm1-x344.google.com [IPv6:2a00:1450:4864:20::344]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A3DA3C0617A7 for ; Thu, 19 Nov 2020 07:52:31 -0800 (PST) Received: by mail-wm1-x344.google.com with SMTP id 1so7191823wme.3 for ; Thu, 19 Nov 2020 07:52:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=C7gc6ZVBdCx8pSOzVMf40W3Pjx8pVRZ16wuxsmUbKts=; b=jLD5mGxTcDBedMXf4hKCcHd7/A1HKIj6I2hJODeALA+EXH/Fbt6yD65J3iPSmItKkk HoetqtWJqSj7sFPWCwN21QafMSHDXCq40w9Z7Jj+HdWxmGiDi3MJzGIUmRzOqVe6kemK FBovNgyQAVX4KyzDtGHXJYtygfnfztw57cv07aOwo5AMEm0ekZkuMxlYbkQ/CiSMOF/l J3mZDwtlYy5Q8KFNmqn4xAvSiDF4xW21J1fPGsO+Y1tnTCCyKr8KyfEK4B3Z977SOQxq SlcXlp7l+rZZKNl6DwYwCRSUOKkqm+hWz0fbzbineAwdgUKNg+PGjidWBWV3EKdI7B1n OX/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=C7gc6ZVBdCx8pSOzVMf40W3Pjx8pVRZ16wuxsmUbKts=; b=PQ/HAx25QZEpSXlav1HXncx0IEombqkN5cg8Zeov+huLrCPHYfc4p372synk12dSmZ JvObJjUJw+wpXl7WLAn2qyQC8e7odsqgkwYpOX/rVZnXzRDCr2ju/HqhYFjZnWTdfWj0 EMM7OhlfpVJ3NdygHEo6+wZImQwxtGUBddtXe5Iawbg3c9MQ26UyZcMKV7p8rPCUqSfk glnvLbRU2YafFg1oeuhbZZGPtMjdcsTIeK6+cMzlZe9f0H498I9bBbUZssbpn1YoMyfz OlYfhUp2QcQLoinPJGouzTsOcSDQOTFlJmGzkGX2Y9DxEICNZ16o7hcylrJkV45AfDgx YVCQ== X-Gm-Message-State: AOAM530C88z4z2N3F5V1pASlkPSf8w5wUKQJ5XIRseDY0kRDVnqEbJAY LXfmcjHnNkZ872P+3wWZxAdGrvuMXlI= X-Google-Smtp-Source: ABdhPJzTrqERvTy5BXG1fttbkqlzanxl9ykC96gvAjplC+/79xekiHXfXDt7IcbeOAOMxbmSKXkfSQ== X-Received: by 2002:a1c:6306:: with SMTP id x6mr4600631wmb.154.1605801147249; Thu, 19 Nov 2020 07:52:27 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id t13sm188726wru.67.2020.11.19.07.52.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Nov 2020 07:52:26 -0800 (PST) Message-Id: <28493184b60d3fa46cde346eaae6128bce87c114.1605801143.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Thu, 19 Nov 2020 15:52:20 +0000 Subject: [PATCH 4/7] config: add --literal-value option, un-implemented Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Jonathan Nieder , Emily Shaffer , Johannes Schindelin , Jeff King , Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee The 'git config' builtin takes a 'value_regex' parameter for several actions. This can cause confusion when expecting exact value matches instead of regex matches, especially when the input string contains glob characters. While callers can escape the patterns themselves, it would be more friendly to allow an argument to disable the pattern matching in favor of an exact string match. Add a new '--literal-value' option that does not currently change the behavior. The implementation will follow for each appropriate action. For now, check and test that --literal-value will abort the command when included with an incompatible action. The name '--literal-value' was chosen over something simpler like '--literal' because some commands allow regular expressions on the key in addition to the value. Signed-off-by: Derrick Stolee --- Documentation/git-config.txt | 20 +++++++++++++------- builtin/config.c | 17 +++++++++++++++++ t/t1300-config.sh | 13 +++++++++++++ 3 files changed, 43 insertions(+), 7 deletions(-) diff --git a/Documentation/git-config.txt b/Documentation/git-config.txt index 7573160f21..e244dd73f0 100644 --- a/Documentation/git-config.txt +++ b/Documentation/git-config.txt @@ -9,15 +9,15 @@ git-config - Get and set repository or global options SYNOPSIS -------- [verse] -'git config' [] [--type=] [--show-origin] [--show-scope] [-z|--null] name [value [value_regex]] +'git config' [] [--type=] [--literal-value] [--show-origin] [--show-scope] [-z|--null] name [value [value_regex]] 'git config' [] [--type=] --add name value -'git config' [] [--type=] --replace-all name value [value_regex] -'git config' [] [--type=] [--show-origin] [--show-scope] [-z|--null] --get name [value_regex] -'git config' [] [--type=] [--show-origin] [--show-scope] [-z|--null] --get-all name [value_regex] -'git config' [] [--type=] [--show-origin] [--show-scope] [-z|--null] [--name-only] --get-regexp name_regex [value_regex] +'git config' [] [--type=] [--literal-value] --replace-all name value [value_regex] +'git config' [] [--type=] [--show-origin] [--show-scope] [-z|--null] [--literal-value] --get name [value_regex] +'git config' [] [--type=] [--show-origin] [--show-scope] [-z|--null] [--literal-value] --get-all name [value_regex] +'git config' [] [--type=] [--show-origin] [--show-scope] [-z|--null] [--literal-value] [--name-only] --get-regexp name_regex [value_regex] 'git config' [] [--type=] [-z|--null] --get-urlmatch name URL -'git config' [] --unset name [value_regex] -'git config' [] --unset-all name [value_regex] +'git config' [] [--literal-value] --unset name [value_regex] +'git config' [] [--literal-value] --unset-all name [value_regex] 'git config' [] --rename-section old_name new_name 'git config' [] --remove-section name 'git config' [] [--show-origin] [--show-scope] [-z|--null] [--name-only] -l | --list @@ -165,6 +165,12 @@ See also <>. --list:: List all variables set in config file, along with their values. +--literal-value:: + When used with the `value_regex` argument, treat `value_regex` as + an exact string instead of a regular expression. This will restrict + the name/value pairs that are matched to only those where the value + is exactly equal to the `value_regex`. + --type :: 'git config' will ensure that any input or output is valid under the given type constraint(s), and will canonicalize outgoing values in ``'s diff --git a/builtin/config.c b/builtin/config.c index e7c7f3d455..ad6c695737 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -34,6 +34,7 @@ static int respect_includes_opt = -1; static struct config_options config_options; static int show_origin; static int show_scope; +static int literal; #define ACTION_GET (1<<0) #define ACTION_GET_ALL (1<<1) @@ -52,6 +53,16 @@ static int show_scope; #define ACTION_GET_COLORBOOL (1<<14) #define ACTION_GET_URLMATCH (1<<15) +#define ACTION_LITERAL_ALLOWED (\ + ACTION_GET |\ + ACTION_GET_ALL |\ + ACTION_GET_REGEXP |\ + ACTION_REPLACE_ALL |\ + ACTION_UNSET |\ + ACTION_UNSET_ALL |\ + ACTION_SET_ALL\ +) + /* * The actions "ACTION_LIST | ACTION_GET_*" which may produce more than * one line of output and which should therefore be paged. @@ -141,6 +152,7 @@ static struct option builtin_config_options[] = { OPT_BIT(0, "rename-section", &actions, N_("rename section: old-name new-name"), ACTION_RENAME_SECTION), OPT_BIT(0, "remove-section", &actions, N_("remove a section: name"), ACTION_REMOVE_SECTION), OPT_BIT('l', "list", &actions, N_("list all"), ACTION_LIST), + OPT_BOOL(0, "literal-value", &literal, N_("use literal equality when matching values")), OPT_BIT('e', "edit", &actions, N_("open an editor"), ACTION_EDIT), OPT_BIT(0, "get-color", &actions, N_("find the color configured: slot [default]"), ACTION_GET_COLOR), OPT_BIT(0, "get-colorbool", &actions, N_("find the color setting: slot [stdout-is-tty]"), ACTION_GET_COLORBOOL), @@ -745,6 +757,11 @@ int cmd_config(int argc, const char **argv, const char *prefix) usage_builtin_config(); } + if (literal && !(actions & ACTION_LITERAL_ALLOWED)) { + error(_("--literal only applies with 'value_regex'")); + usage_builtin_config(); + } + if (actions & PAGING_ACTIONS) setup_auto_pager("config", 1); diff --git a/t/t1300-config.sh b/t/t1300-config.sh index 74e0f84c0a..73f5ca4361 100755 --- a/t/t1300-config.sh +++ b/t/t1300-config.sh @@ -1965,4 +1965,17 @@ test_expect_success '--replace-all and value_regex' ' test_cmp expect .git/config ' +test_expect_success 'refuse --literal-value for incompatible actions' ' + git config dev.null bogus && + test_must_fail git config --literal-value --add dev.null bogus && + test_must_fail git config --literal-value --get-urlmatch dev.null bogus && + test_must_fail git config --literal-value --get-urlmatch dev.null bogus && + test_must_fail git config --literal-value --rename-section dev null && + test_must_fail git config --literal-value --remove-section dev && + test_must_fail git config --literal-value --list && + test_must_fail git config --literal-value --get-color dev.null && + test_must_fail git config --literal-value --get-colorbool dev.null && + test_must_fail git config --literal-value --edit +' + test_done From patchwork Thu Nov 19 15:52:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 11918033 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 486F3C6379F for ; Thu, 19 Nov 2020 15:52:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DEE59246E4 for ; Thu, 19 Nov 2020 15:52:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ZTdm17/Q" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728825AbgKSPwa (ORCPT ); Thu, 19 Nov 2020 10:52:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48544 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727937AbgKSPwa (ORCPT ); Thu, 19 Nov 2020 10:52:30 -0500 Received: from mail-wm1-x344.google.com (mail-wm1-x344.google.com [IPv6:2a00:1450:4864:20::344]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9BF3CC0613CF for ; Thu, 19 Nov 2020 07:52:29 -0800 (PST) Received: by mail-wm1-x344.google.com with SMTP id h21so7189035wmb.2 for ; Thu, 19 Nov 2020 07:52:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=OWQ3v9UyitTFDicPlXh4ba1drpNyBkVGV5aCa53kYGI=; b=ZTdm17/QvEk5Bw21aK0rngQzUquddxt2Yrdd5gzwWSfnRbfDcTomNOj+PdrP2X5toA K5qu6TEb5k53nf9+Oa1UuWfkin6LJQ4vi9zJN1bKnttpDPv4HIhOjWM+xBGmkK+sjbZ6 BMi8pqtz308x62T0BB9QqXhOQBUsnmhKJtjEYv9rxYDHyvQWOkdDmR+BaSmJSpqSMvsm qIFAEVsUWzzG3Xr/Py318bq5vmtPOV4rschulPvZVypvtpwOt8BXDBoKcqplYHKRBBNP 3vok+r0HTp1bNEgPWoDHsZ0wRqAitFvC53eGWVtDBtQ0Mp0iE0B+2b3IAs7h3Lz7/Tu+ yxEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=OWQ3v9UyitTFDicPlXh4ba1drpNyBkVGV5aCa53kYGI=; b=Ttk1MyknUOh8P1cxgBfDDmSa15OdGD7BShQ9cAmuWOCOyOAH4cZofXMp3i/+M5y68U nTBfShW2bPgGy8u/GjZkFu7WMM1MrAi18A1Wr5NBXUiGw5C9vCog/BLcxrWPI3ed5ogw +JHGGSaJJVvjqirF7MHtJWcTvA/j03DGO+QSlpT4MYOaNmUqdm8ZcI5MG5aW0EEufvtQ mprR+oJpEKsEfkiBRTpooUlDeCWZ7NXFFyyWccp2Yh1M2rLNlCoggBqqPNgz6P2Yz7ZN ubri7cjp6hcoFgRBOdGfiBAIRLvqZZiEAzUSI6Lp+3yNu8HPH02rwVJhNrOBmjKf/Jwj O9OQ== X-Gm-Message-State: AOAM532ra8TPXqD21xy7iCVpFD+fXmCQVg2/UhKkMQdK83MTnuJggqGR 18IGhlUEz79SXRgU3veOHYWYoyQtAYs= X-Google-Smtp-Source: ABdhPJyvJ9REJCsmD2jOerhV0GoS3Jg6D/HX9uyE5DyRqssMUiAud0luIpAvX2bJyeiaGVbhVAJqYQ== X-Received: by 2002:a1c:44f:: with SMTP id 76mr5375874wme.181.1605801148178; Thu, 19 Nov 2020 07:52:28 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id z6sm489047wmi.1.2020.11.19.07.52.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Nov 2020 07:52:27 -0800 (PST) Message-Id: <5881b2d987e3e8575d054a64fe21fbe7e7967aba.1605801143.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Thu, 19 Nov 2020 15:52:21 +0000 Subject: [PATCH 5/7] config: plumb --literal-value into config API Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Jonathan Nieder , Emily Shaffer , Johannes Schindelin , Jeff King , Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee The git_config_set_multivar_in_file_gently() and related methods now take a 'flags' bitfield, so add a new bit representing the --literal-value option from 'git config'. This alters the purpose of the value_regex parameter to be an exact string match. This requires some initialization changes in git_config_set_multivar_in_file_gently() and a new strcmp() call in the matches() method. The new CONFIG_FLAGS_LITERAL_VALUE flag is initialized in builtin/config.c based on the --literal-value option, and that needs to be updated in several callers. This patch only affects some of the modes of 'git config', and the rest will be completed in the next change. Signed-off-by: Derrick Stolee --- builtin/config.c | 16 +++++++++++----- config.c | 5 +++++ config.h | 7 +++++++ t/t1300-config.sh | 48 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 71 insertions(+), 5 deletions(-) diff --git a/builtin/config.c b/builtin/config.c index ad6c695737..6ab5a0d68f 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -626,6 +626,7 @@ int cmd_config(int argc, const char **argv, const char *prefix) { int nongit = !startup_info->have_repository; char *value; + int flags = 0; given_config_source.file = xstrdup_or_null(getenv(CONFIG_ENVIRONMENT)); @@ -761,6 +762,8 @@ int cmd_config(int argc, const char **argv, const char *prefix) error(_("--literal only applies with 'value_regex'")); usage_builtin_config(); } + if (literal) + flags = CONFIG_FLAGS_LITERAL_VALUE; if (actions & PAGING_ACTIONS) setup_auto_pager("config", 1); @@ -823,7 +826,8 @@ int cmd_config(int argc, const char **argv, const char *prefix) value = normalize_value(argv[0], argv[1]); UNLEAK(value); return git_config_set_multivar_in_file_gently(given_config_source.file, - argv[0], value, argv[2], 0); + argv[0], value, argv[2], + flags); } else if (actions == ACTION_ADD) { check_write(); @@ -832,7 +836,8 @@ int cmd_config(int argc, const char **argv, const char *prefix) UNLEAK(value); return git_config_set_multivar_in_file_gently(given_config_source.file, argv[0], value, - CONFIG_REGEX_NONE, 0); + CONFIG_REGEX_NONE, + flags); } else if (actions == ACTION_REPLACE_ALL) { check_write(); @@ -841,7 +846,7 @@ int cmd_config(int argc, const char **argv, const char *prefix) UNLEAK(value); return git_config_set_multivar_in_file_gently(given_config_source.file, argv[0], value, argv[2], - CONFIG_FLAGS_MULTI_REPLACE); + flags | CONFIG_FLAGS_MULTI_REPLACE); } else if (actions == ACTION_GET) { check_argc(argc, 1, 2); @@ -868,7 +873,8 @@ int cmd_config(int argc, const char **argv, const char *prefix) check_argc(argc, 1, 2); if (argc == 2) return git_config_set_multivar_in_file_gently(given_config_source.file, - argv[0], NULL, argv[1], 0); + argv[0], NULL, argv[1], + flags); else return git_config_set_in_file_gently(given_config_source.file, argv[0], NULL); @@ -878,7 +884,7 @@ int cmd_config(int argc, const char **argv, const char *prefix) check_argc(argc, 1, 2); return git_config_set_multivar_in_file_gently(given_config_source.file, argv[0], NULL, argv[1], - CONFIG_FLAGS_MULTI_REPLACE); + flags | CONFIG_FLAGS_MULTI_REPLACE); } else if (actions == ACTION_RENAME_SECTION) { int ret; diff --git a/config.c b/config.c index 4841c68a91..5028c1e736 100644 --- a/config.c +++ b/config.c @@ -2402,6 +2402,7 @@ struct config_store_data { size_t baselen; char *key; int do_not_match; + const char *literal_value; regex_t *value_regex; int multi_replace; struct { @@ -2431,6 +2432,8 @@ static int matches(const char *key, const char *value, { if (strcmp(key, store->key)) return 0; /* not ours */ + if (store->literal_value) + return !strcmp(store->literal_value, value); if (!store->value_regex) return 1; /* always matches */ if (store->value_regex == CONFIG_REGEX_NONE) @@ -2803,6 +2806,8 @@ int git_config_set_multivar_in_file_gently(const char *config_filename, store.value_regex = NULL; else if (value_regex == CONFIG_REGEX_NONE) store.value_regex = CONFIG_REGEX_NONE; + else if (flags & CONFIG_FLAGS_LITERAL_VALUE) + store.literal_value = value_regex; else { if (value_regex[0] == '!') { store.do_not_match = 1; diff --git a/config.h b/config.h index 266eb22e46..ddb81e1e32 100644 --- a/config.h +++ b/config.h @@ -77,6 +77,13 @@ enum config_event_t { */ #define CONFIG_FLAGS_MULTI_REPLACE (1 << 0) +/* + * When CONFIG_FLAGS_LITERAL_VALUE is specified, match key/value pairs + * by string comparison (not regex match) to the provided value_regex + * parameter. + */ +#define CONFIG_FLAGS_LITERAL_VALUE (1 << 1) + /* * The parser event function (if not NULL) is called with the event type and * the begin/end offsets of the parsed elements. diff --git a/t/t1300-config.sh b/t/t1300-config.sh index 73f5ca4361..ed12b4f7a0 100755 --- a/t/t1300-config.sh +++ b/t/t1300-config.sh @@ -1978,4 +1978,52 @@ test_expect_success 'refuse --literal-value for incompatible actions' ' test_must_fail git config --literal-value --edit ' +test_expect_success '--literal-value uses exact string matching' ' + GLOB="a+b*c?d[e]f.g" && + q_to_tab >initial <<-EOF && + [literal] + Qtest = $GLOB + EOF + + cp initial .git/config && + git config literal.test bogus "$GLOB" && + q_to_tab >expect <<-EOF && + [literal] + Qtest = $GLOB + Qtest = bogus + EOF + test_cmp expect .git/config && + cp initial .git/config && + git config --literal-value literal.test bogus "$GLOB" && + q_to_tab >expect <<-EOF && + [literal] + Qtest = bogus + EOF + test_cmp expect .git/config && + + cp initial .git/config && + test_must_fail git config --unset literal.test "$GLOB" && + git config --literal-value --unset literal.test "$GLOB" && + test_must_fail git config literal.test && + + cp initial .git/config && + test_must_fail git config --unset-all literal.test "$GLOB" && + git config --literal-value --unset-all literal.test "$GLOB" && + test_must_fail git config literal.test && + + cp initial .git/config && + git config --replace-all literal.test bogus "$GLOB" && + q_to_tab >expect <<-EOF && + [literal] + Qtest = $GLOB + Qtest = bogus + EOF + test_cmp expect .git/config && + + cp initial .git/config && + git config --replace-all literal.test bogus "$GLOB" && + git config --literal-value --replace-all literal.test bogus "$GLOB" && + test_cmp_config bogus literal.test +' + test_done From patchwork Thu Nov 19 15:52:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 11918039 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2325EC64E7B for ; Thu, 19 Nov 2020 15:52:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B085D22256 for ; Thu, 19 Nov 2020 15:52:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="KS4Qxh/p" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728832AbgKSPwe (ORCPT ); Thu, 19 Nov 2020 10:52:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48546 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728821AbgKSPwa (ORCPT ); Thu, 19 Nov 2020 10:52:30 -0500 Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4F0DCC0613CF for ; Thu, 19 Nov 2020 07:52:30 -0800 (PST) Received: by mail-wr1-x443.google.com with SMTP id u12so7002995wrt.0 for ; Thu, 19 Nov 2020 07:52:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=wnPa/yXaCbLPuMwyJevPtUDswrTQEOLursxTVQ0r5yU=; b=KS4Qxh/pCQxnGC43EYhwVdY6KbYF2Vs7Gmw1/194tD/Jbzai6ohE+PNVonkLFdgvY5 WA2cjByIfnohcUozcXB9mHU9DBkbVH6WpLVISkf3WyzAtYNVqPOheAWiDgHWYOwXzyuw x3/cu0H1Tkgyo+eP1MKTIBSh/tCG5MiiFnmWJPV9cKaPVywT1bypVWCEV2obrPMA7JA+ TcokfrfdVFxpGn7ueZ/MI/glpBtkqgKmLx37rMCVzsIybDzXNrVEVjhDTyoH7Kmem8fI jJdT0akShbDJ9JjxVMUC0SMRo+jS5W2yuaWIbDuo+nln7Rre+LM/2K8tja+4aD8YVmoJ pYeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=wnPa/yXaCbLPuMwyJevPtUDswrTQEOLursxTVQ0r5yU=; b=BBLUyBt8R5s+rYTZNlu6K6G03qo+DOZa/dj2iKPV87NeXPVDulct+AXdrl8I8WU+d7 dOsxEZkL76oy70xjqe1GRlN1bgt6IujOEWLf8iZB80izv3uBvuBjOVwYJYSVS2fAM2LS rSSZIm6OlRwpu8DU9rtqjLyR3XWv4Zvo+zOPcOkK2KdR4TKk119O72VzJA540Ix6amSL v0yET8F1dkc+50HSAgUq6yqen2ZUs4qRjuCMqOU1ACX551ZL9zgdcMKHnkFkjUDiEFG+ BNxs37yzxTLA14NKapLUUmrugKtlmh/6YWTyRBWX7Gty3IS20DoLCpoaWsFkUG54djep 1byw== X-Gm-Message-State: AOAM530zbuGF/4XM+k5ecN5EZnyuljF9f8hmhsytEuCSvCXJJPurRfxU BXXwX71KIuC4t/xHilRF6DC//5QYUag= X-Google-Smtp-Source: ABdhPJxIpNKSlQnbNFM9VY2j/4ctsarGcSHt4mS2FgBlzL+TP2fURWGo8g8nmmbIl/oor43dEEaAzQ== X-Received: by 2002:a5d:614e:: with SMTP id y14mr11718738wrt.25.1605801148974; Thu, 19 Nov 2020 07:52:28 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id l3sm499781wmf.0.2020.11.19.07.52.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Nov 2020 07:52:28 -0800 (PST) Message-Id: <7c8e3769c723405a421de3b44b4c90ce48b26e4d.1605801143.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Thu, 19 Nov 2020 15:52:22 +0000 Subject: [PATCH 6/7] config: implement --literal-value with --get* Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Jonathan Nieder , Emily Shaffer , Johannes Schindelin , Jeff King , Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee The config builtin does its own regex matching of values for the --get, --get-all, and --get-regexp modes. Plumb the existing 'flags' parameter to the get_value() method so we can initialize the value_regex argument as a fixed string instead of a regex pattern. Signed-off-by: Derrick Stolee --- builtin/config.c | 15 ++++++++++----- t/t1300-config.sh | 24 ++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/builtin/config.c b/builtin/config.c index 6ab5a0d68f..1d5cfab8f1 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -14,6 +14,7 @@ static const char *const builtin_config_usage[] = { static char *key; static regex_t *key_regexp; +static const char *value_regex; static regex_t *regexp; static int show_keys; static int omit_values; @@ -298,6 +299,8 @@ static int collect_config(const char *key_, const char *value_, void *cb) return 0; if (use_key_regexp && regexec(key_regexp, key_, 0, NULL, 0)) return 0; + if (literal && strcmp(value_regex, (value_?value_:""))) + return 0; if (regexp != NULL && (do_not_match ^ !!regexec(regexp, (value_?value_:""), 0, NULL, 0))) return 0; @@ -308,7 +311,7 @@ static int collect_config(const char *key_, const char *value_, void *cb) return format_config(&values->items[values->nr++], key_, value_); } -static int get_value(const char *key_, const char *regex_) +static int get_value(const char *key_, const char *regex_, int flags) { int ret = CONFIG_GENERIC_ERROR; struct strbuf_list values = {NULL}; @@ -345,7 +348,9 @@ static int get_value(const char *key_, const char *regex_) } } - if (regex_) { + if (regex_ && (flags & CONFIG_FLAGS_LITERAL_VALUE)) + value_regex = regex_; + else if (regex_) { if (regex_[0] == '!') { do_not_match = 1; regex_++; @@ -850,19 +855,19 @@ int cmd_config(int argc, const char **argv, const char *prefix) } else if (actions == ACTION_GET) { check_argc(argc, 1, 2); - return get_value(argv[0], argv[1]); + return get_value(argv[0], argv[1], flags); } else if (actions == ACTION_GET_ALL) { do_all = 1; check_argc(argc, 1, 2); - return get_value(argv[0], argv[1]); + return get_value(argv[0], argv[1], flags); } else if (actions == ACTION_GET_REGEXP) { show_keys = 1; use_key_regexp = 1; do_all = 1; check_argc(argc, 1, 2); - return get_value(argv[0], argv[1]); + return get_value(argv[0], argv[1], flags); } else if (actions == ACTION_GET_URLMATCH) { check_argc(argc, 2, 2); diff --git a/t/t1300-config.sh b/t/t1300-config.sh index ed12b4f7a0..8531d01c7c 100755 --- a/t/t1300-config.sh +++ b/t/t1300-config.sh @@ -2026,4 +2026,28 @@ test_expect_success '--literal-value uses exact string matching' ' test_cmp_config bogus literal.test ' +test_expect_success '--get and --get-all with --literal-value' ' + GLOB="a+b*c?d[e]f.g" && + q_to_tab >.git/config <<-EOF && + [literal] + Qtest = bogus + Qtest = $GLOB + EOF + + git config --get literal.test bogus && + test_must_fail git config --get literal.test "$GLOB" && + git config --get --literal-value literal.test "$GLOB" && + test_must_fail git config --get --literal-value literal.test non-existent && + + git config --get-all literal.test bogus && + test_must_fail git config --get-all literal.test "$GLOB" && + git config --get-all --literal-value literal.test "$GLOB" && + test_must_fail git config --get-all --literal-value literal.test non-existent && + + git config --get-regexp literal+ bogus && + test_must_fail git config --get-regexp literal+ "$GLOB" && + git config --get-regexp --literal-value literal+ "$GLOB" && + test_must_fail git config --get-regexp --literal-value literal+ non-existent +' + test_done From patchwork Thu Nov 19 15:52:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 11918041 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DA8C0C64E7A for ; Thu, 19 Nov 2020 15:52:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6B44C246E0 for ; Thu, 19 Nov 2020 15:52:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="gKORP7zI" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728843AbgKSPwf (ORCPT ); Thu, 19 Nov 2020 10:52:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48552 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728826AbgKSPwb (ORCPT ); Thu, 19 Nov 2020 10:52:31 -0500 Received: from mail-wm1-x343.google.com (mail-wm1-x343.google.com [IPv6:2a00:1450:4864:20::343]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1EFC3C0613D4 for ; Thu, 19 Nov 2020 07:52:31 -0800 (PST) Received: by mail-wm1-x343.google.com with SMTP id a186so4858978wme.1 for ; Thu, 19 Nov 2020 07:52:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=nO4OnZKfAXqr/SR7EZdgw2SGUFb0d15DKP99WiXhYtE=; b=gKORP7zID494E46kvHvQMSqVFcVMALdScuNp0C24IeuqqdPLN8oW7qZyhtmZ18tFwj +JkzvmnijSVTYAaDkSOqfvHnYYkxrFvFtWa57uBDoYKb4yIbKWRYaxmXBNiSddFoIW+r D2vBfyJIEXdgEKiFqVmqBczT9zlGIAMZ7raUkBLUH9FzG6RpEAwpxhX8Wok4dxddoPbW Upgw1/svF3OYo+f3uAu6SkDunfr9Qw98cwqwCH6gCTiatiRkqBTPBIRqwlOdf/E6hLvD 1MdrG9kLaMQW75vjmJXH/VVcBX/i2eO5+78vbQ1kx2mieLJnMcBC36NCKD8N7U7hxbo3 gjIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=nO4OnZKfAXqr/SR7EZdgw2SGUFb0d15DKP99WiXhYtE=; b=PLdnNi+8MH8zmNRmFz6qeXMlCVSow0QERB/QIjlzNEy/9TROCMyFvo0okpatCs9XuS Cc3Zmsy8wpRBzyYYFdJ0L17ZqcVy+OHFe5QWDMO1UsACKNdLQIEbS2brUniQ09k5Wfvp rho1ceIQJCy8R/BXlgMr37bOCRdiw5TiAXTMvDK7GjASC1vxfdsVigrMYyqUuqlTZ01s 65X8esAnr0CHE5DBjs+rzFFYmmM5QGcN22kiQ7/9KJ2ecoAUSXlKrps6QvUeQ+akRrfh B3tAGjiHJmDmSbajcoKvxAFXpmC90fqIMlJCOtBAA/bmbq8H2unMmNgGOPonDuAYoU7W mDxQ== X-Gm-Message-State: AOAM5324/l7lSctWnAaUUVrJ8wlIKpenPFXiHc3bbGfwhaCieKA3Wooc 7YByyDUk1GPwQEv7LSYoHtiwun1S5Ws= X-Google-Smtp-Source: ABdhPJwRJAfTlXpxpUFcJ7xrkyueqSJKzPKbikHqBfru/hjGLQMKwK9gAsRtPEXEOYvV964g0D9Fvg== X-Received: by 2002:a1c:dc82:: with SMTP id t124mr3344145wmg.94.1605801149737; Thu, 19 Nov 2020 07:52:29 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id v6sm216927wrb.53.2020.11.19.07.52.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Nov 2020 07:52:29 -0800 (PST) Message-Id: <1d1c2fd23e805e0f25edd324a614715b1d11a2bb.1605801143.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Thu, 19 Nov 2020 15:52:23 +0000 Subject: [PATCH 7/7] maintenance: use 'git config --literal-value' Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Jonathan Nieder , Emily Shaffer , Johannes Schindelin , Jeff King , Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee When a repository's leading directories contain regex glob characters, the config calls for 'git maintenance register' and 'git maintenance unregister' are not careful enough. Use the new --literal-value option to direct the config machinery to use exact string matches. This is a more robust option than excaping these arguments in a piecemeal fashion. Reported-by: Emily Shaffer Reported-by: Jonathan Nieder Signed-off-by: Derrick Stolee --- builtin/gc.c | 5 +++-- t/t7900-maintenance.sh | 12 ++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/builtin/gc.c b/builtin/gc.c index e3098ef6a1..0784bbdc6a 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -1452,7 +1452,8 @@ static int maintenance_register(void) git_config_set("maintenance.strategy", "incremental"); config_get.git_cmd = 1; - strvec_pushl(&config_get.args, "config", "--global", "--get", "maintenance.repo", + strvec_pushl(&config_get.args, "config", "--global", "--get", + "--literal-value", "maintenance.repo", the_repository->worktree ? the_repository->worktree : the_repository->gitdir, NULL); @@ -1483,7 +1484,7 @@ static int maintenance_unregister(void) config_unset.git_cmd = 1; strvec_pushl(&config_unset.args, "config", "--global", "--unset", - "maintenance.repo", + "--literal-value", "maintenance.repo", the_repository->worktree ? the_repository->worktree : the_repository->gitdir, NULL); diff --git a/t/t7900-maintenance.sh b/t/t7900-maintenance.sh index 20184e96e1..2ee5512158 100755 --- a/t/t7900-maintenance.sh +++ b/t/t7900-maintenance.sh @@ -367,6 +367,18 @@ test_expect_success 'register and unregister' ' test_cmp before actual ' +test_expect_success 'register and unregister with glob characters' ' + GLOB="a+b*c" && + git init "$GLOB" && + git -C "$GLOB" maintenance register && + git config --get-all --show-origin maintenance.repo && + git config --get-all --global --literal-value \ + maintenance.repo "$(pwd)/$GLOB" && + git -C "$GLOB" maintenance unregister && + test_must_fail git config --get-all --global --literal-value \ + maintenance.repo "$(pwd)/$GLOB" +' + test_expect_success 'start from empty cron table' ' GIT_TEST_CRONTAB="test-tool crontab cron.txt" git maintenance start &&