From patchwork Mon Dec 16 15:47:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee via GitGitGadget X-Patchwork-Id: 11294449 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0F902138C for ; Mon, 16 Dec 2019 15:48:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D896C20726 for ; Mon, 16 Dec 2019 15:48:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="azgu1Vnd" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728522AbfLPPsO (ORCPT ); Mon, 16 Dec 2019 10:48:14 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:44599 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728443AbfLPPsM (ORCPT ); Mon, 16 Dec 2019 10:48:12 -0500 Received: by mail-wr1-f68.google.com with SMTP id q10so7833539wrm.11 for ; Mon, 16 Dec 2019 07:48:09 -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=KA5j4LtwpCjFs4/8owngf7Wk8TZUNENof/E9MKDmQ7M=; b=azgu1VndGR2vslbCV32OdR4Ybj3deU9cXmaBtt5ry+SBM8fWfl18qk/FVk4Ku4/hoH yK4UFeFZ+uk0nEANzkAvIPlYmmAddER13TNX+TSQnknBCVIaMqTSJQdY24hlDcdiy0Cn EtvcPnxe4VO1HHlHIu3Vja/YIj4rvYzMJf5Q6hmwqYVJiNukhKCKV8GjUFHUk2DDSFgM 6FKbBAPujwOCSwacR2926l4Kejva19VQAveGJUf407dbGw5w7MiqnoJz9lt2nqNc34++ Wfc6ThIdeU6H0jFY/vkm/TY3lUexEiizZIwYATQBYk9LQaiDd0SZkXBgyGXmPXB33vS5 qeHg== 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=KA5j4LtwpCjFs4/8owngf7Wk8TZUNENof/E9MKDmQ7M=; b=ciMEIzrR+zq9Py3pVBcwPou7d27XpjRaXG4yF48G3lCuI3yDEmiM7yVfF6jfzQdi/D TAUv6n4roTp5MJOdD1O2egSi4a0DD+XtTGARdf49I87b67NUrYFXoRDTNGgm2bcVnjDU xdxp/Q8XojIZ2nIoMagddZNXg+RAbPouu89N/W2fZYactzkYBLonx2QEimZ6tGblI9Or 9MhYOMNOa0OWy9JkvPZYjJ95dSHfDapJ/OU5/TQM2z5yesHAUZZ7G3AREvlkKc0NgZR9 x9UytwaFrH6qe2ZHq9hB2OHbsLrCaI4+yu1ghQqE8R32SXGnoCsJWJKSzJSZ0pH9GGI0 V1mw== X-Gm-Message-State: APjAAAXDGv2CkvIzgwv0Auoh0auedttKxELlA1zKMg+ECVQfEEQNLwQD IvJhtnY0xAnGNAerkeKetTzf82YY X-Google-Smtp-Source: APXvYqziKk56p+tTfKHcLM7B41HSrYSk7h/mYoYJpyxumCOtcrbQuP6qysAxAQayR1vGcnfSsmfBMw== X-Received: by 2002:adf:e6cb:: with SMTP id y11mr31750592wrm.345.1576511288704; Mon, 16 Dec 2019 07:48:08 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id t8sm21980286wrp.69.2019.12.16.07.48.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 16 Dec 2019 07:48:08 -0800 (PST) Message-Id: <8d5fb9f40b8fc766ef022f910529e6308d9c2d80.1576511287.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Alexandr Miloslavskiy via GitGitGadget" Date: Mon, 16 Dec 2019 15:47:49 +0000 Subject: [PATCH v2 01/18] t7107, t7526: directly test parse_pathspec_file() Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Phillip Wood , Junio C Hamano , Emily Shaffer , Derrick Stolee , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Alexandr Miloslavskiy , Junio C Hamano , Alexandr Miloslavskiy Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Alexandr Miloslavskiy In my previous patches, `parse_pathspec_file()` was tested indirectly by invoking `git reset` and `git commit` with properly crafted inputs. This has some disadvantages: 1) A number of tests are copy&pasted for every command where `--pathspec-from-file` is supported. With just two commands, it wasn't too bad, but I'm going to extend support to many more commands, which would make a handful of low-value tests. 2) Tests are located in suboptimal test packages 3) Tests are indirect Fix this by testing `parse_pathspec_file()` directly via a new test helper. While working on it, I also noticed that quotes testing via `"\"file\\101.t\""` was somewhat incorrect: I escaped `\` one time while I had to escape it two times! Tests still worked due to `"` which prevented pathspec from matching files. Fix this by properly escaping one more time. Signed-off-by: Alexandr Miloslavskiy --- Makefile | 1 + t/helper/test-parse-pathspec-file.c | 34 +++++++++++ t/helper/test-tool.c | 1 + t/helper/test-tool.h | 1 + t/t0067-parse_pathspec_file.sh | 89 +++++++++++++++++++++++++++ t/t7107-reset-pathspec-file.sh | 94 +++-------------------------- t/t7526-commit-pathspec-file.sh | 70 +-------------------- 7 files changed, 136 insertions(+), 154 deletions(-) create mode 100644 t/helper/test-parse-pathspec-file.c create mode 100755 t/t0067-parse_pathspec_file.sh diff --git a/Makefile b/Makefile index b7d7374dac..fd7bcaac9c 100644 --- a/Makefile +++ b/Makefile @@ -721,6 +721,7 @@ TEST_BUILTINS_OBJS += test-mktemp.o TEST_BUILTINS_OBJS += test-oidmap.o TEST_BUILTINS_OBJS += test-online-cpus.o TEST_BUILTINS_OBJS += test-parse-options.o +TEST_BUILTINS_OBJS += test-parse-pathspec-file.o TEST_BUILTINS_OBJS += test-path-utils.o TEST_BUILTINS_OBJS += test-pkt-line.o TEST_BUILTINS_OBJS += test-prio-queue.o diff --git a/t/helper/test-parse-pathspec-file.c b/t/helper/test-parse-pathspec-file.c new file mode 100644 index 0000000000..e7f525feb9 --- /dev/null +++ b/t/helper/test-parse-pathspec-file.c @@ -0,0 +1,34 @@ +#include "test-tool.h" +#include "parse-options.h" +#include "pathspec.h" +#include "gettext.h" + +int cmd__parse_pathspec_file(int argc, const char **argv) +{ + struct pathspec pathspec; + const char *pathspec_from_file = 0; + int pathspec_file_nul = 0, i; + + static const char *const usage[] = { + "test-tool parse-pathspec-file --pathspec-from-file [--pathspec-file-nul]", + NULL + }; + + struct option options[] = { + OPT_PATHSPEC_FROM_FILE(&pathspec_from_file), + OPT_PATHSPEC_FILE_NUL(&pathspec_file_nul), + OPT_END() + }; + + parse_options(argc, argv, 0, options, usage, 0); + + parse_pathspec_file(&pathspec, 0, 0, 0, pathspec_from_file, + pathspec_file_nul); + + for (i = 0; i < pathspec.nr; i++) { + printf("%s\n", pathspec.items[i].original); + } + + clear_pathspec(&pathspec); + return 0; +} diff --git a/t/helper/test-tool.c b/t/helper/test-tool.c index f20989d449..c9a232d238 100644 --- a/t/helper/test-tool.c +++ b/t/helper/test-tool.c @@ -39,6 +39,7 @@ static struct test_cmd cmds[] = { { "oidmap", cmd__oidmap }, { "online-cpus", cmd__online_cpus }, { "parse-options", cmd__parse_options }, + { "parse-pathspec-file", cmd__parse_pathspec_file }, { "path-utils", cmd__path_utils }, { "pkt-line", cmd__pkt_line }, { "prio-queue", cmd__prio_queue }, diff --git a/t/helper/test-tool.h b/t/helper/test-tool.h index 8ed2af71d1..c8549fd87f 100644 --- a/t/helper/test-tool.h +++ b/t/helper/test-tool.h @@ -29,6 +29,7 @@ int cmd__mktemp(int argc, const char **argv); int cmd__oidmap(int argc, const char **argv); int cmd__online_cpus(int argc, const char **argv); int cmd__parse_options(int argc, const char **argv); +int cmd__parse_pathspec_file(int argc, const char** argv); int cmd__path_utils(int argc, const char **argv); int cmd__pkt_line(int argc, const char **argv); int cmd__prio_queue(int argc, const char **argv); diff --git a/t/t0067-parse_pathspec_file.sh b/t/t0067-parse_pathspec_file.sh new file mode 100755 index 0000000000..df7b319713 --- /dev/null +++ b/t/t0067-parse_pathspec_file.sh @@ -0,0 +1,89 @@ +#!/bin/sh + +test_description='Test parse_pathspec_file()' + +. ./test-lib.sh + +test_expect_success 'one item from stdin' ' + echo fileA.t | test-tool parse-pathspec-file --pathspec-from-file=- >actual && + + cat >expect <<-\EOF && + fileA.t + EOF + test_cmp expect actual +' + +test_expect_success 'one item from file' ' + echo fileA.t >list && + test-tool parse-pathspec-file --pathspec-from-file=list >actual && + + cat >expect <<-\EOF && + fileA.t + EOF + test_cmp expect actual +' + +test_expect_success 'NUL delimiters' ' + printf "fileA.t\0fileB.t\0" | test-tool parse-pathspec-file --pathspec-from-file=- --pathspec-file-nul >actual && + + cat >expect <<-\EOF && + fileA.t + fileB.t + EOF + test_cmp expect actual +' + +test_expect_success 'LF delimiters' ' + printf "fileA.t\nfileB.t\n" | test-tool parse-pathspec-file --pathspec-from-file=- >actual && + + cat >expect <<-\EOF && + fileA.t + fileB.t + EOF + test_cmp expect actual +' + +test_expect_success 'no trailing delimiter' ' + printf "fileA.t\nfileB.t" | test-tool parse-pathspec-file --pathspec-from-file=- >actual && + + cat >expect <<-\EOF && + fileA.t + fileB.t + EOF + test_cmp expect actual +' + +test_expect_success 'CRLF delimiters' ' + printf "fileA.t\r\nfileB.t\r\n" | test-tool parse-pathspec-file --pathspec-from-file=- >actual && + + cat >expect <<-\EOF && + fileA.t + fileB.t + EOF + test_cmp expect actual +' + +test_expect_success 'quotes' ' + # shell takes \\\\101 and spits \\101 + # printf takes \\101 and spits \101 + # git takes \101 and spits A + printf "\"file\\\\101.t\"" | test-tool parse-pathspec-file --pathspec-from-file=- >actual && + + cat >expect <<-\EOF && + fileA.t + EOF + test_cmp expect actual +' + +test_expect_success '--pathspec-file-nul takes quotes literally' ' + # shell takes \\\\101 and spits \\101 + # printf takes \\101 and spits \101 + printf "\"file\\\\101.t\"" | test-tool parse-pathspec-file --pathspec-from-file=- --pathspec-file-nul >actual && + + cat >expect <<-\EOF && + "file\101.t" + EOF + test_cmp expect actual +' + +test_done diff --git a/t/t7107-reset-pathspec-file.sh b/t/t7107-reset-pathspec-file.sh index 6b1a731fff..f36fce27b9 100755 --- a/t/t7107-reset-pathspec-file.sh +++ b/t/t7107-reset-pathspec-file.sh @@ -25,7 +25,7 @@ verify_expect () { test_cmp expect actual } -test_expect_success '--pathspec-from-file from stdin' ' +test_expect_success 'simplest' ' restore_checkpoint && git rm fileA.t && @@ -37,20 +37,7 @@ test_expect_success '--pathspec-from-file from stdin' ' verify_expect ' -test_expect_success '--pathspec-from-file from file' ' - restore_checkpoint && - - git rm fileA.t && - echo fileA.t >list && - git reset --pathspec-from-file=list && - - cat >expect <<-\EOF && - D fileA.t - EOF - verify_expect -' - -test_expect_success 'NUL delimiters' ' +test_expect_success '--pathspec-file-nul' ' restore_checkpoint && git rm fileA.t fileB.t && @@ -63,71 +50,21 @@ test_expect_success 'NUL delimiters' ' verify_expect ' -test_expect_success 'LF delimiters' ' - restore_checkpoint && - - git rm fileA.t fileB.t && - printf "fileA.t\nfileB.t\n" | git reset --pathspec-from-file=- && - - cat >expect <<-\EOF && - D fileA.t - D fileB.t - EOF - verify_expect -' - -test_expect_success 'no trailing delimiter' ' - restore_checkpoint && - - git rm fileA.t fileB.t && - printf "fileA.t\nfileB.t" | git reset --pathspec-from-file=- && - - cat >expect <<-\EOF && - D fileA.t - D fileB.t - EOF - verify_expect -' - -test_expect_success 'CRLF delimiters' ' +test_expect_success 'only touches what was listed' ' restore_checkpoint && - git rm fileA.t fileB.t && - printf "fileA.t\r\nfileB.t\r\n" | git reset --pathspec-from-file=- && + git rm fileA.t fileB.t fileC.t fileD.t && + printf "fileB.t\nfileC.t\n" | git reset --pathspec-from-file=- && cat >expect <<-\EOF && - D fileA.t + D fileA.t D fileB.t + D fileC.t + D fileD.t EOF verify_expect ' -test_expect_success 'quotes' ' - restore_checkpoint && - - git rm fileA.t && - printf "\"file\\101.t\"" | git reset --pathspec-from-file=- && - - cat >expect <<-\EOF && - D fileA.t - EOF - verify_expect -' - -test_expect_success 'quotes not compatible with --pathspec-file-nul' ' - restore_checkpoint && - - git rm fileA.t && - printf "\"file\\101.t\"" >list && - # Note: "git reset" has not yet learned to fail on wrong pathspecs - git reset --pathspec-from-file=list --pathspec-file-nul && - - cat >expect <<-\EOF && - D fileA.t - EOF - test_must_fail verify_expect -' - test_expect_success '--pathspec-from-file is not compatible with --soft or --hard' ' restore_checkpoint && @@ -137,19 +74,4 @@ test_expect_success '--pathspec-from-file is not compatible with --soft or --har test_must_fail git reset --hard --pathspec-from-file=list ' -test_expect_success 'only touches what was listed' ' - restore_checkpoint && - - git rm fileA.t fileB.t fileC.t fileD.t && - printf "fileB.t\nfileC.t\n" | git reset --pathspec-from-file=- && - - cat >expect <<-\EOF && - D fileA.t - D fileB.t - D fileC.t - D fileD.t - EOF - verify_expect -' - test_done diff --git a/t/t7526-commit-pathspec-file.sh b/t/t7526-commit-pathspec-file.sh index a06b683534..4e592f7472 100755 --- a/t/t7526-commit-pathspec-file.sh +++ b/t/t7526-commit-pathspec-file.sh @@ -26,7 +26,7 @@ verify_expect () { test_cmp expect actual } -test_expect_success '--pathspec-from-file from stdin' ' +test_expect_success 'simplest' ' restore_checkpoint && echo fileA.t | git commit --pathspec-from-file=- -m "Commit" && @@ -37,19 +37,7 @@ test_expect_success '--pathspec-from-file from stdin' ' verify_expect ' -test_expect_success '--pathspec-from-file from file' ' - restore_checkpoint && - - echo fileA.t >list && - git commit --pathspec-from-file=list -m "Commit" && - - cat >expect <<-\EOF && - A fileA.t - EOF - verify_expect -' - -test_expect_success 'NUL delimiters' ' +test_expect_success '--pathspec-file-nul' ' restore_checkpoint && printf "fileA.t\0fileB.t\0" | git commit --pathspec-from-file=- --pathspec-file-nul -m "Commit" && @@ -61,60 +49,6 @@ test_expect_success 'NUL delimiters' ' verify_expect ' -test_expect_success 'LF delimiters' ' - restore_checkpoint && - - printf "fileA.t\nfileB.t\n" | git commit --pathspec-from-file=- -m "Commit" && - - cat >expect <<-\EOF && - A fileA.t - A fileB.t - EOF - verify_expect -' - -test_expect_success 'no trailing delimiter' ' - restore_checkpoint && - - printf "fileA.t\nfileB.t" | git commit --pathspec-from-file=- -m "Commit" && - - cat >expect <<-\EOF && - A fileA.t - A fileB.t - EOF - verify_expect -' - -test_expect_success 'CRLF delimiters' ' - restore_checkpoint && - - printf "fileA.t\r\nfileB.t\r\n" | git commit --pathspec-from-file=- -m "Commit" && - - cat >expect <<-\EOF && - A fileA.t - A fileB.t - EOF - verify_expect -' - -test_expect_success 'quotes' ' - restore_checkpoint && - - printf "\"file\\101.t\"" | git commit --pathspec-from-file=- -m "Commit" && - - cat >expect <<-\EOF && - A fileA.t - EOF - verify_expect expect -' - -test_expect_success 'quotes not compatible with --pathspec-file-nul' ' - restore_checkpoint && - - printf "\"file\\101.t\"" >list && - test_must_fail git commit --pathspec-from-file=list --pathspec-file-nul -m "Commit" -' - test_expect_success 'only touches what was listed' ' restore_checkpoint && From patchwork Mon Dec 16 15:47:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee via GitGitGadget X-Patchwork-Id: 11294441 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E97A3138C for ; Mon, 16 Dec 2019 15:48:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C391320725 for ; Mon, 16 Dec 2019 15:48:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="GiO/J+Ty" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728499AbfLPPsL (ORCPT ); Mon, 16 Dec 2019 10:48:11 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:35351 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728487AbfLPPsL (ORCPT ); Mon, 16 Dec 2019 10:48:11 -0500 Received: by mail-wr1-f68.google.com with SMTP id g17so7870639wro.2 for ; Mon, 16 Dec 2019 07:48:10 -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=H0W2IHMkwNuzWHBmhT0DY+Y6Xi/xz/EJUmh6xgLGtTY=; b=GiO/J+TyfTqlgvO4qDBjwZ7DMEIhFLaP+eyZjxq7qTSba35+nzVxRaGtYFlQqkNsTW 3hZmblJ7wjKQQzNjFXyaJ3Bk+HZVU7CSVKjbs4rMqPwkhkjiMr5j4utNLEIKhahifDq4 K1rMrsXaO/4pNbPesJEuKjT7YfOEPSa94DK7k0HTmUa6886gASAJXXpRQVB42c5ZwFFn ecodTnhYsxLQEsurEIOWwT5g82V0mcLoFsGBnxJC9g25/kK3qXXXQDuWFCWG/LbW6szz RY6Z/SwNPNYu4+WSVEL/inAAraQAy1kakaIwSVXYVApmViw0wFIYTq29hWV6etH+YOjv zQJw== 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=H0W2IHMkwNuzWHBmhT0DY+Y6Xi/xz/EJUmh6xgLGtTY=; b=XwFx6kR1RIz/GW3+UaXqn5EY5ni8s8hrqPDjJXasuzXAkdiTWkydAR5+gss7nLaCyj RNdCGIGBcm+QTCRKWeT3zgDBj9i+JPpiQnZgHm+ceZpRUYj3nibrtCcu9vXCByC2KHVm gAMG1uyCN8a06h0fR8D0HtTFPmCCL8eJ0XCj1FRO+h9S3Rnmw0X1u+wF5SW1ZKA69rrg u3MgDCTxsJmIoFQOiTCZjpry9NcBJUB2QO3lCIAzgLr6bgtJzaWe+fIo4HINvCGJNinG f+8IobiZrtvJ7hfAff8ZfzK+qOJripN7/UunuNsiYIbc6feiiJ/yTh5kFx2+x9d+og98 diag== X-Gm-Message-State: APjAAAVfARAYpkQEaIjLIECx7Un0sUNKk5s4W4+FiX44q2dXI2Z6Q3ko pQfFUdNemOSAGq3YEy5catQDW47+ X-Google-Smtp-Source: APXvYqxcj0hJVSFMKX5gAeoG0qPARuBkt1s12dYwBR+lcHsZwZMbJ/B8QTm3fn5vxf+u5Vi+XQscJA== X-Received: by 2002:adf:ea4e:: with SMTP id j14mr32079554wrn.101.1576511289462; Mon, 16 Dec 2019 07:48:09 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id u14sm22385296wrm.51.2019.12.16.07.48.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 16 Dec 2019 07:48:08 -0800 (PST) Message-Id: In-Reply-To: References: From: "Alexandr Miloslavskiy via GitGitGadget" Date: Mon, 16 Dec 2019 15:47:50 +0000 Subject: [PATCH v2 02/18] t7526: add tests for error conditions Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Phillip Wood , Junio C Hamano , Emily Shaffer , Derrick Stolee , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Alexandr Miloslavskiy , Junio C Hamano , Alexandr Miloslavskiy Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Alexandr Miloslavskiy Suggested-By: Phillip Wood Signed-off-by: Alexandr Miloslavskiy --- t/t7526-commit-pathspec-file.sh | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/t/t7526-commit-pathspec-file.sh b/t/t7526-commit-pathspec-file.sh index 4e592f7472..68920e8ff9 100755 --- a/t/t7526-commit-pathspec-file.sh +++ b/t/t7526-commit-pathspec-file.sh @@ -61,4 +61,28 @@ test_expect_success 'only touches what was listed' ' verify_expect ' +test_expect_success 'error conditions' ' + restore_checkpoint && + echo fileA.t >list && + >empty_list && + + test_must_fail git commit --pathspec-from-file=- --interactive -m "Commit" err && + test_i18ngrep "\-\-pathspec-from-file is incompatible with \-\-interactive/\-\-patch" err && + + test_must_fail git commit --pathspec-from-file=- --patch -m "Commit" err && + test_i18ngrep "\-\-pathspec-from-file is incompatible with \-\-interactive/\-\-patch" err && + + test_must_fail git commit --pathspec-from-file=- -m "Commit" -- fileA.t err && + test_i18ngrep "\-\-pathspec-from-file is incompatible with pathspec arguments" err && + + test_must_fail git commit --pathspec-file-nul -m "Commit" 2>err && + test_i18ngrep "\-\-pathspec-file-nul requires \-\-pathspec-from-file" err && + + test_must_fail git commit --pathspec-from-file=- --include -m "Commit" err && + test_i18ngrep "No paths with \-\-include/\-\-only does not make sense." err && + + test_must_fail git commit --pathspec-from-file=- --only -m "Commit" err && + test_i18ngrep "No paths with \-\-include/\-\-only does not make sense." err +' + test_done From patchwork Mon Dec 16 15:47:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee via GitGitGadget X-Patchwork-Id: 11294477 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 434F0138C for ; Mon, 16 Dec 2019 15:48:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1F4AD206E0 for ; Mon, 16 Dec 2019 15:48:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Gjh7UYYZ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728512AbfLPPsO (ORCPT ); Mon, 16 Dec 2019 10:48:14 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:50556 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728492AbfLPPsM (ORCPT ); Mon, 16 Dec 2019 10:48:12 -0500 Received: by mail-wm1-f67.google.com with SMTP id a5so7269191wmb.0 for ; Mon, 16 Dec 2019 07:48:10 -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=DQ2eGuP+iM2s02E2HkXytysJUPRhIcOh0Uk/p0Rz6co=; b=Gjh7UYYZz1wlzipp9giy6n4OYVCaUXgvMhOpA6alRggN83bcMWKP0b4MF/nQcryVnA dPI9EUP1WHr+XtKLZEiN+DWm4qyQ2jirawB3HmMjHASZM3q1ja8MyDucDCTlhbT2YmSU 3t1PUQRJMGhAcmAWS427WRwL3KymWLvz1jHPar1DwaEXTGR8jlxBG8ze6aBdnPDORvw2 cfyTsZI1ttDJJL/7Dyb4PWlzohICs+myuT4vK81dGKNQzYq+S9c4leJ1ayVXpE5DFXOL qPAo302MHqOWJmvQtXR0Uw9nF43c5yLjShiMA2bvKo9AF3zzfhYt/Eiv6Qrd1iBdP7/C si1A== 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=DQ2eGuP+iM2s02E2HkXytysJUPRhIcOh0Uk/p0Rz6co=; b=jzW3e0zyexKopCLtDyY8qphugJD9LgFreSCYxMdWej1Nbejo/wrFXROkY867QQue7d 6FkxARab+5zVrgNb1QAyxPJ8WrRta9A3m8K+WXw9FpFEfWmow/9zlXIhEinfQWFHxdFc Q4G6PMeyO8bnQVLZ4r+sJLY2EkEUr8ZZVuKBgD5UWI8/El1L5IWMZm92myNYnOQ1DSXh OWd+9PrunYHnlxzMNzGlWFqbkR//vSziNE6Y+CO3k+Y+BttO9KdjSFbf8L5paGC2jImU djiL7qmyOTND8W1fDEVslSrVC2H1YXt7KsH7UHRBZIWIpsokKEYZuulGw04qFWZhgyY0 SBqA== X-Gm-Message-State: APjAAAUMuc0CHyQvvAUrGQta1Hx+y5ybGcSdZNqKlMO4bjEfYhC2Qf4w rlKiAfhsV8/9J/rdZfn/T54AGcU8 X-Google-Smtp-Source: APXvYqxSO4a4KBbZ43uBrtGW4dKmRLmAHKMNXaOtrq9/DasSekJC2lusD7dKP3C5N77FvAPNYMA3kA== X-Received: by 2002:a1c:a406:: with SMTP id n6mr25646126wme.40.1576511290237; Mon, 16 Dec 2019 07:48:10 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id b16sm22497233wrj.23.2019.12.16.07.48.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 16 Dec 2019 07:48:09 -0800 (PST) Message-Id: In-Reply-To: References: From: "Alexandr Miloslavskiy via GitGitGadget" Date: Mon, 16 Dec 2019 15:47:51 +0000 Subject: [PATCH v2 03/18] t7107: add tests for error conditions Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Phillip Wood , Junio C Hamano , Emily Shaffer , Derrick Stolee , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Alexandr Miloslavskiy , Junio C Hamano , Alexandr Miloslavskiy Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Alexandr Miloslavskiy Suggested-By: Phillip Wood Signed-off-by: Alexandr Miloslavskiy --- t/t7107-reset-pathspec-file.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/t/t7107-reset-pathspec-file.sh b/t/t7107-reset-pathspec-file.sh index f36fce27b9..da833925a6 100755 --- a/t/t7107-reset-pathspec-file.sh +++ b/t/t7107-reset-pathspec-file.sh @@ -74,4 +74,18 @@ test_expect_success '--pathspec-from-file is not compatible with --soft or --har test_must_fail git reset --hard --pathspec-from-file=list ' +test_expect_success 'error conditions' ' + restore_checkpoint && + echo fileA.t >list && + + test_must_fail git reset --pathspec-from-file=- --patch err && + test_i18ngrep "\-\-pathspec-from-file is incompatible with \-\-patch" err && + + test_must_fail git reset --pathspec-from-file=- -- fileA.t err && + test_i18ngrep "\-\-pathspec-from-file is incompatible with pathspec arguments" err && + + test_must_fail git reset --pathspec-file-nul 2>err && + test_i18ngrep "\-\-pathspec-file-nul requires \-\-pathspec-from-file" err +' + test_done From patchwork Mon Dec 16 15:47:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee via GitGitGadget X-Patchwork-Id: 11294443 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 66253138C for ; Mon, 16 Dec 2019 15:48:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 43A8920726 for ; Mon, 16 Dec 2019 15:48:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="MMmakrJP" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728520AbfLPPsO (ORCPT ); Mon, 16 Dec 2019 10:48:14 -0500 Received: from mail-wr1-f66.google.com ([209.85.221.66]:45753 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728487AbfLPPsM (ORCPT ); Mon, 16 Dec 2019 10:48:12 -0500 Received: by mail-wr1-f66.google.com with SMTP id j42so3661924wrj.12 for ; Mon, 16 Dec 2019 07:48:11 -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=iCpCodiwQL5DzQGyiJhFi2eJdzpDVIO7zGr+qkEqLpU=; b=MMmakrJPOKu2aJBhOvx/LUyCdm/q85ikjD38UgVeMSVVb+atU58TpR8UXyZDrk+IYi MHlfhl60hRLGyAlbiehOGEfEolVjULazREeObqEpHEDEUxDksdNqoNj5+rySmtr11mnU OjUYK5CjTFUNMpcW6Pans2fLTBxp3yHzmSvVaivFoGfeGnGUlcVnMp4GpLkKpwgoDtJc hQSQDIHJAoxPqSTkr1+0Oe5EqW2UCxIYCxoTPOzTS7EUWJD7xk5JDJitaYX+qbXS7EmC ThCLE0xEHp0kkMApYtMqOjTWYjhoAs0HNUjBSneXrSxqjwxJu4IneZd5XTMlGa4fa9aq jq5w== 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=iCpCodiwQL5DzQGyiJhFi2eJdzpDVIO7zGr+qkEqLpU=; b=oTOnLy9dsqBIvdB+qBRF+WFafsuqpqOYaOKg5O1mOKiX8wy9ESHQMOsxCs9MxSjR45 T3mJUcbz6fzGPgZtIyXjMrDO/TYVbRrAFkIENwa2RRvocn/EajZEEla9TPCtOLuRY40i LnX+i+IE+A/A12kbRfMGrI8/WMu5C0mv17YDJX8VIA1H/SawcBHxa9j9FVxXupMUuwhD lEeORSSEeXyQy/4Vg+Qu/cZHA0G+W+640YC78+ZZjsXD/YNPwLki2Vk7pP1GxzlXH8zc YT74vIaFL7Ax2w59FbJ4qH9wDda7rXB3kwRlBrl5RttyOAXmZbPugzThPaExwChEAFXy Lr0A== X-Gm-Message-State: APjAAAVJxGxL5X4lBtqbZL22SKTFQzDMrivbUmRdXijiAvtzdUypq9WQ xXmorg7MEyFpjOWNsQ6n9F1d6DRX X-Google-Smtp-Source: APXvYqxjglWlAupIa30xIC1UOVghLUUWXLh4kbBMC7uKSFJ8xH1WHS8uj9K7Olf/zujNR2oXbkXG0Q== X-Received: by 2002:adf:eb0a:: with SMTP id s10mr27860720wrn.320.1576511290898; Mon, 16 Dec 2019 07:48:10 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id q11sm21925522wrp.24.2019.12.16.07.48.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 16 Dec 2019 07:48:10 -0800 (PST) Message-Id: In-Reply-To: References: From: "Alexandr Miloslavskiy via GitGitGadget" Date: Mon, 16 Dec 2019 15:47:52 +0000 Subject: [PATCH v2 04/18] commit: forbid --pathspec-from-file --all Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Phillip Wood , Junio C Hamano , Emily Shaffer , Derrick Stolee , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Alexandr Miloslavskiy , Junio C Hamano , Alexandr Miloslavskiy Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Alexandr Miloslavskiy I forgot this in my previous patch `--pathspec-from-file` for `git commit` [1]. When both `--pathspec-from-file` and `--all` were specified, `--all` took precedence and `--pathspec-from-file` was ignored. Before `--pathspec-from-file` was implemented, this case was prevented by this check in `parse_and_validate_options()` : die(_("paths '%s ...' with -a does not make sense"), argv[0]); It is unfortunate that these two cases are disconnected. This came as result of how the code was laid out before my patches, where `pathspec` is parsed outside of `parse_and_validate_options()`. This branch is already full of refactoring patches and I did not dare to go for another one. Fix by mirroring `die()` for `--pathspec-from-file` as well. [1] Commit e440fc58 ("commit: support the --pathspec-from-file option" 2019-11-19) Reported-by: Phillip Wood Signed-off-by: Alexandr Miloslavskiy Reported-by: Phillip Wood Signed-off-by: Alexandr Miloslavskiy Signed-off-by: Junio C Hamano --- builtin/commit.c | 3 +++ t/t7526-commit-pathspec-file.sh | 3 +++ 2 files changed, 6 insertions(+) diff --git a/builtin/commit.c b/builtin/commit.c index 2db2ad0de4..893a9f29b2 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -347,6 +347,9 @@ static const char *prepare_index(int argc, const char **argv, const char *prefix if (interactive) die(_("--pathspec-from-file is incompatible with --interactive/--patch")); + if (all) + die(_("--pathspec-from-file with -a does not make sense")); + if (pathspec.nr) die(_("--pathspec-from-file is incompatible with pathspec arguments")); diff --git a/t/t7526-commit-pathspec-file.sh b/t/t7526-commit-pathspec-file.sh index 68920e8ff9..ba769e0e5d 100755 --- a/t/t7526-commit-pathspec-file.sh +++ b/t/t7526-commit-pathspec-file.sh @@ -72,6 +72,9 @@ test_expect_success 'error conditions' ' test_must_fail git commit --pathspec-from-file=- --patch -m "Commit" err && test_i18ngrep "\-\-pathspec-from-file is incompatible with \-\-interactive/\-\-patch" err && + test_must_fail git commit --pathspec-from-file=- --all -m "Commit" err && + test_i18ngrep "\-\-pathspec-from-file with \-a does not make sense" err && + test_must_fail git commit --pathspec-from-file=- -m "Commit" -- fileA.t err && test_i18ngrep "\-\-pathspec-from-file is incompatible with pathspec arguments" err && From patchwork Mon Dec 16 15:47:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee via GitGitGadget X-Patchwork-Id: 11294447 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6BE1717F0 for ; Mon, 16 Dec 2019 15:48:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4002F2072B for ; Mon, 16 Dec 2019 15:48:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="AJ9ct4OF" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728526AbfLPPsP (ORCPT ); Mon, 16 Dec 2019 10:48:15 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:46290 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728502AbfLPPsO (ORCPT ); Mon, 16 Dec 2019 10:48:14 -0500 Received: by mail-wr1-f65.google.com with SMTP id z7so7811390wrl.13 for ; Mon, 16 Dec 2019 07:48:12 -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=/50tsg0WF1RPAKWO+eD4BpY/4M3EHrjNNjTZh3wRJNU=; b=AJ9ct4OF3clBEGKLbj8nPWPkUMpOUnvb9GVS3rOn72/vhhfChf5nLVbeCS50PbOt89 bVTlAKDUWVM1g/udutUziB3Y0dXu2QFyAH4SAfD2nlD00eX7gvdbPzBQ8JfeScES2gw2 psahgOymI64GQH0u0Iiy0COgx75K1SLTctyTK1lUtNQFoY8lIFktl6lZ3wUcWq1Ul077 mpTnErdKB5gEhfF18nPOp+vY6KCyw0IRpaY0Zb6MmGRExe78UblVDgZRcYaCodZC+skA Xa6s6HIqgpJ+RsaiaNOY5a9o+3KPb5fFA1ZfYRpUT/XbHbTTHUGnYf4AwecNcCuF6anB fF+w== 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=/50tsg0WF1RPAKWO+eD4BpY/4M3EHrjNNjTZh3wRJNU=; b=E1B9IYIMhAbL4Rv71uXzBCQccUq/M+74+ooV3zn18ydv5WAsvsnf6RzDK/7y3gFDzt +HrSTmTB6+D9dwHu2Lvj52tZ4tjVYz+JzCuxgVUzGNjZpD4ABm7RmID9Vkj6Q62FLGSd V2Co6BwMeh6YvrJxcnkOYuZTUQbVxpVinmC44J7o5nb/LfcLlCG0hs2ji3M7p1GAT/+l sFDr4HBtzcQCViUzVT/L8jE32BBm5I8ZUzFqd/XObnyDSy7Wm17haqIAEfETUKfsDFPa S1hVxFVvjTL/aZeqBZyfIS1S+RZaE/uzEpzcSfS8zMC/7C1apug8kdl5l3knDjHL48Nf /Hzw== X-Gm-Message-State: APjAAAW9+hdp56FUQXNBReRMxnPthSCT9uTo31CaU5Gi5iQAaE/x0ndR M5AyMJQLrqrxMDIbA5/KAD4fQuBJ X-Google-Smtp-Source: APXvYqwPotTZZ3aP50PJTuMb7gjcas+Nnbm2eySzFjoiTAgE4Uvw+oZD/Vu87XUi8sDzdxAvB/6Pcw== X-Received: by 2002:adf:f586:: with SMTP id f6mr30157958wro.46.1576511291599; Mon, 16 Dec 2019 07:48:11 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id h2sm21970277wrv.66.2019.12.16.07.48.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 16 Dec 2019 07:48:11 -0800 (PST) Message-Id: <204a0a4446942ac89a59aba672a7646f55185985.1576511287.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Alexandr Miloslavskiy via GitGitGadget" Date: Mon, 16 Dec 2019 15:47:53 +0000 Subject: [PATCH v2 05/18] cmd_add: prepare for next patch Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Phillip Wood , Junio C Hamano , Emily Shaffer , Derrick Stolee , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Alexandr Miloslavskiy , Junio C Hamano , Alexandr Miloslavskiy Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Alexandr Miloslavskiy Some code blocks were moved down to be able to test for `pathspec.nr` in the next patch. Blocks are moved as is without any changes. This is done as separate patch to reduce the amount of diffs in next patch. Signed-off-by: Alexandr Miloslavskiy --- builtin/add.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/builtin/add.c b/builtin/add.c index d4686d5218..3d1791dd82 100644 --- a/builtin/add.c +++ b/builtin/add.c @@ -430,10 +430,6 @@ int cmd_add(int argc, const char **argv, const char *prefix) if (addremove && take_worktree_changes) die(_("-A and -u are mutually incompatible")); - if (!take_worktree_changes && addremove_explicit < 0 && argc) - /* Turn "git add pathspec..." to "git add -A pathspec..." */ - addremove = 1; - if (!show_only && ignore_missing) die(_("Option --ignore-missing can only be used together with --dry-run")); @@ -446,19 +442,6 @@ int cmd_add(int argc, const char **argv, const char *prefix) hold_locked_index(&lock_file, LOCK_DIE_ON_ERROR); - flags = ((verbose ? ADD_CACHE_VERBOSE : 0) | - (show_only ? ADD_CACHE_PRETEND : 0) | - (intent_to_add ? ADD_CACHE_INTENT : 0) | - (ignore_add_errors ? ADD_CACHE_IGNORE_ERRORS : 0) | - (!(addremove || take_worktree_changes) - ? ADD_CACHE_IGNORE_REMOVAL : 0)); - - if (require_pathspec && argc == 0) { - fprintf(stderr, _("Nothing specified, nothing added.\n")); - fprintf(stderr, _("Maybe you wanted to say 'git add .'?\n")); - return 0; - } - /* * Check the "pathspec '%s' did not match any files" block * below before enabling new magic. @@ -468,6 +451,23 @@ int cmd_add(int argc, const char **argv, const char *prefix) PATHSPEC_SYMLINK_LEADING_PATH, prefix, argv); + if (require_pathspec && argc == 0) { + fprintf(stderr, _("Nothing specified, nothing added.\n")); + fprintf(stderr, _("Maybe you wanted to say 'git add .'?\n")); + return 0; + } + + if (!take_worktree_changes && addremove_explicit < 0 && argc) + /* Turn "git add pathspec..." to "git add -A pathspec..." */ + addremove = 1; + + flags = ((verbose ? ADD_CACHE_VERBOSE : 0) | + (show_only ? ADD_CACHE_PRETEND : 0) | + (intent_to_add ? ADD_CACHE_INTENT : 0) | + (ignore_add_errors ? ADD_CACHE_IGNORE_ERRORS : 0) | + (!(addremove || take_worktree_changes) + ? ADD_CACHE_IGNORE_REMOVAL : 0)); + if (read_cache_preload(&pathspec) < 0) die(_("index file corrupt")); From patchwork Mon Dec 16 15:47:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee via GitGitGadget X-Patchwork-Id: 11294445 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 36BDA13B6 for ; Mon, 16 Dec 2019 15:48:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 09D94206E0 for ; Mon, 16 Dec 2019 15:48:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="faas1IkW" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728528AbfLPPsQ (ORCPT ); Mon, 16 Dec 2019 10:48:16 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:53762 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728504AbfLPPsP (ORCPT ); Mon, 16 Dec 2019 10:48:15 -0500 Received: by mail-wm1-f67.google.com with SMTP id m24so5872960wmc.3 for ; Mon, 16 Dec 2019 07:48:13 -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=BbmTKXfYbxk0jVu3XfFKXCJJJhcswMTc8YPxtcV/Yzw=; b=faas1IkWcSN6pT3z4XJ0+q7fgP0wKOTubwFCkHnP1bs75SxVgU9y5mUvyUsCjbOkTb a0ak9OILyNkjcbY9icCsLdcF8zKc5gdrIFWqTnVfR9SHZiSK2nOGLmNasmnma0pb4rvT BP9r92sAm6u1O/DDw92LASlelsq9C2iCkD3eHsLYJu1ReXf/H3LUrXT3i9ak6nhOXm3m IAQihIiScZfhY0z586DhYgn4BvO6vJptjrA81iu8xnXWYwMqgUiNrjU7o9comB3KsQTH vAa8XO1nR5ZGOdKd8cwG0yHxaIPs7hJ0eINp76vWT+RiXroYSTP/rOWlguwoHfsWg22B b0rA== 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=BbmTKXfYbxk0jVu3XfFKXCJJJhcswMTc8YPxtcV/Yzw=; b=AuZjnOhlug53EiNAEUMnCFVvhnFRXVELmj/sbA9X6jAW6fTsSKETAcAiQWYLxfTC2B Ea/zFmXgK607pIvmmUsKEkcZQTYhcJDQyNF4czNK2uEvW45C7SZhb4lVr/YJV5UKZyT4 NaMRj9nhwnOa5ZSXIL9SP2y9pjhLpRd6HF+7utuIUQyfhLq4u1VTIPP7jdI1R/fxu0uj lLTfyWVZf4DGuxLjfP/k+bNhMIX3v5XwJzDs4NiHVoLi9ScgoFfrz7tDY7qGm8ngAMdZ 7wat/ibxyzENabkMKFHGfi7Ht1mx28pfOsCeMiJz6zahhHTub1GfPP958dT/hDJ3i1rm +CWg== X-Gm-Message-State: APjAAAXRVNTWAsKV2xfr5ea60cd5kzJrwUuzKnnxvzNf53rQ93r0vU/w a5O52myj7E/05rYN1Msg+fVnPYJw X-Google-Smtp-Source: APXvYqyyFV73ZZRAHLtZcUxy51jAq22s66rHMzodk4690doFD3x6L5895CyMsb1uK3wLAEgqO4i8WQ== X-Received: by 2002:a1c:486:: with SMTP id 128mr32015905wme.163.1576511292347; Mon, 16 Dec 2019 07:48:12 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id s16sm22113852wrn.78.2019.12.16.07.48.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 16 Dec 2019 07:48:11 -0800 (PST) Message-Id: <1ea5f1784774e19987a08a6b5214000681b34ae1.1576511287.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Alexandr Miloslavskiy via GitGitGadget" Date: Mon, 16 Dec 2019 15:47:54 +0000 Subject: [PATCH v2 06/18] add: support the --pathspec-from-file option Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Phillip Wood , Junio C Hamano , Emily Shaffer , Derrick Stolee , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Alexandr Miloslavskiy , Junio C Hamano , Alexandr Miloslavskiy Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Alexandr Miloslavskiy Decisions taken for simplicity: 1) For now, `--pathspec-from-file` is declared incompatible with `--interactive/--patch/--edit`, even when is not `stdin`. Such use case it not really expected. Also, it would require changes to `interactive_add()` and `edit_patch()`. 2) It is not allowed to pass pathspec in both args and file. Signed-off-by: Alexandr Miloslavskiy --- Documentation/git-add.txt | 16 ++++++- builtin/add.c | 30 +++++++++++-- t/t3704-add-pathspec-file.sh | 86 ++++++++++++++++++++++++++++++++++++ 3 files changed, 127 insertions(+), 5 deletions(-) create mode 100755 t/t3704-add-pathspec-file.sh diff --git a/Documentation/git-add.txt b/Documentation/git-add.txt index 8b0e4c7fa8..be5e3ac54b 100644 --- a/Documentation/git-add.txt +++ b/Documentation/git-add.txt @@ -11,7 +11,8 @@ SYNOPSIS 'git add' [--verbose | -v] [--dry-run | -n] [--force | -f] [--interactive | -i] [--patch | -p] [--edit | -e] [--[no-]all | --[no-]ignore-removal | [--update | -u]] [--intent-to-add | -N] [--refresh] [--ignore-errors] [--ignore-missing] [--renormalize] - [--chmod=(+|-)x] [--] [...] + [--chmod=(+|-)x] [--pathspec-from-file= [--pathspec-file-nul]] + [--] [...] DESCRIPTION ----------- @@ -187,6 +188,19 @@ for "git add --no-all ...", i.e. ignored removed files. bit is only changed in the index, the files on disk are left unchanged. +--pathspec-from-file=:: + Pathspec is passed in `` instead of commandline args. If + `` is exactly `-` then standard input is used. Pathspec + elements are separated by LF or CR/LF. Pathspec elements can be + quoted as explained for the configuration variable `core.quotePath` + (see linkgit:git-config[1]). See also `--pathspec-file-nul` and + global `--literal-pathspecs`. + +--pathspec-file-nul:: + Only meaningful with `--pathspec-from-file`. Pathspec elements are + separated with NUL character and all other characters are taken + literally (including newlines and quotes). + \--:: This option can be used to separate command-line options from the list of files, (useful when filenames might be mistaken diff --git a/builtin/add.c b/builtin/add.c index 3d1791dd82..7c21ad492b 100644 --- a/builtin/add.c +++ b/builtin/add.c @@ -29,6 +29,8 @@ static const char * const builtin_add_usage[] = { static int patch_interactive, add_interactive, edit_interactive; static int take_worktree_changes; static int add_renormalize; +static int pathspec_file_nul; +static const char *pathspec_from_file; struct update_callback_data { int flags; @@ -320,6 +322,8 @@ static struct option builtin_add_options[] = { N_("override the executable bit of the listed files")), OPT_HIDDEN_BOOL(0, "warn-embedded-repo", &warn_on_embedded_repo, N_("warn when adding an embedded repository")), + OPT_PATHSPEC_FROM_FILE(&pathspec_from_file), + OPT_PATHSPEC_FILE_NUL(&pathspec_file_nul), OPT_END(), }; @@ -414,11 +418,17 @@ int cmd_add(int argc, const char **argv, const char *prefix) builtin_add_usage, PARSE_OPT_KEEP_ARGV0); if (patch_interactive) add_interactive = 1; - if (add_interactive) + if (add_interactive) { + if (pathspec_from_file) + die(_("--pathspec-from-file is incompatible with --interactive/--patch")); exit(interactive_add(argc - 1, argv + 1, prefix, patch_interactive)); + } - if (edit_interactive) + if (edit_interactive) { + if (pathspec_from_file) + die(_("--pathspec-from-file is incompatible with --edit")); return(edit_patch(argc, argv, prefix)); + } argc--; argv++; @@ -451,13 +461,25 @@ int cmd_add(int argc, const char **argv, const char *prefix) PATHSPEC_SYMLINK_LEADING_PATH, prefix, argv); - if (require_pathspec && argc == 0) { + if (pathspec_from_file) { + if (pathspec.nr) + die(_("--pathspec-from-file is incompatible with pathspec arguments")); + + parse_pathspec_file(&pathspec, PATHSPEC_ATTR, + PATHSPEC_PREFER_FULL | + PATHSPEC_SYMLINK_LEADING_PATH, + prefix, pathspec_from_file, pathspec_file_nul); + } else if (pathspec_file_nul) { + die(_("--pathspec-file-nul requires --pathspec-from-file")); + } + + if (require_pathspec && pathspec.nr == 0) { fprintf(stderr, _("Nothing specified, nothing added.\n")); fprintf(stderr, _("Maybe you wanted to say 'git add .'?\n")); return 0; } - if (!take_worktree_changes && addremove_explicit < 0 && argc) + if (!take_worktree_changes && addremove_explicit < 0 && pathspec.nr) /* Turn "git add pathspec..." to "git add -A pathspec..." */ addremove = 1; diff --git a/t/t3704-add-pathspec-file.sh b/t/t3704-add-pathspec-file.sh new file mode 100755 index 0000000000..d3a8947dc1 --- /dev/null +++ b/t/t3704-add-pathspec-file.sh @@ -0,0 +1,86 @@ +#!/bin/sh + +test_description='add --pathspec-from-file' + +. ./test-lib.sh + +test_tick + +test_expect_success setup ' + test_commit file0 && + echo A >fileA.t && + echo B >fileB.t && + echo C >fileC.t && + echo D >fileD.t +' + +restore_checkpoint () { + git reset +} + +verify_expect () { + git status --porcelain --untracked-files=no -- fileA.t fileB.t fileC.t fileD.t >actual && + test_cmp expect actual +} + +test_expect_success 'simplest' ' + restore_checkpoint && + + echo fileA.t | git add --pathspec-from-file=- && + + cat >expect <<-\EOF && + A fileA.t + EOF + verify_expect +' + +test_expect_success '--pathspec-file-nul' ' + restore_checkpoint && + + printf "fileA.t\0fileB.t\0" | git add --pathspec-from-file=- --pathspec-file-nul && + + cat >expect <<-\EOF && + A fileA.t + A fileB.t + EOF + verify_expect +' + +test_expect_success 'only touches what was listed' ' + restore_checkpoint && + + printf "fileB.t\nfileC.t\n" | git add --pathspec-from-file=- && + + cat >expect <<-\EOF && + A fileB.t + A fileC.t + EOF + verify_expect +' + +test_expect_success 'error conditions' ' + restore_checkpoint && + echo fileA.t >list && + >empty_list && + + test_must_fail git add --pathspec-from-file=- --interactive err && + test_i18ngrep "\-\-pathspec-from-file is incompatible with \-\-interactive/\-\-patch" err && + + test_must_fail git add --pathspec-from-file=- --patch err && + test_i18ngrep "\-\-pathspec-from-file is incompatible with \-\-interactive/\-\-patch" err && + + test_must_fail git add --pathspec-from-file=- --edit err && + test_i18ngrep "\-\-pathspec-from-file is incompatible with \-\-edit" err && + + test_must_fail git add --pathspec-from-file=- -- fileA.t err && + test_i18ngrep "\-\-pathspec-from-file is incompatible with pathspec arguments" err && + + test_must_fail git add --pathspec-file-nul 2>err && + test_i18ngrep "\-\-pathspec-file-nul requires \-\-pathspec-from-file" err && + + # This case succeeds, but still prints to stderr + git add --pathspec-from-file=- err && + test_i18ngrep "Nothing specified, nothing added." err +' + +test_done From patchwork Mon Dec 16 15:47:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee via GitGitGadget X-Patchwork-Id: 11294471 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E340B17F0 for ; Mon, 16 Dec 2019 15:48:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C194B20725 for ; Mon, 16 Dec 2019 15:48:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="hvjBKW0v" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728572AbfLPPsa (ORCPT ); Mon, 16 Dec 2019 10:48:30 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:50562 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728506AbfLPPsO (ORCPT ); Mon, 16 Dec 2019 10:48:14 -0500 Received: by mail-wm1-f67.google.com with SMTP id a5so7269390wmb.0 for ; Mon, 16 Dec 2019 07:48:13 -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=aYqtUfxrzTqHVRn2pfoo5R2+4lk0OX725HiLpzyYtMg=; b=hvjBKW0v9Qq0NRHw0+761E9gKvGH/0Z+idTxKwIAC2Vun17PdZl5VZKHKZF5ruG8R2 eo2ozVF5ieC4wQ8X2MQ2dsZDvQyGjE54pwxaJAvbYPylPnQndPTg36ausme2cbqrXnhc upMmIWQujlcNjPt508g55+2sITmDShFGSYcejiBF2XOTUxg+sa5VWYOQVT973u84Cvgu WFQgtr/CsyXDYEvgmEgpvav86+bwk5PGaNcvuAVjsTLzspx/urhVLbfAtz6VFJBT6eXZ l6Yg+DVsQmQ7IEuOSOWOTKOri/25BNL+bC/pB1KHghal82ejY2tqn3qUHCYQvf4EeRB9 2LmA== 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=aYqtUfxrzTqHVRn2pfoo5R2+4lk0OX725HiLpzyYtMg=; b=laJcgAnzodDwrij/aez0KRKVRcPTfwN/pWIhSh92tXLkNoVNIWLXmxkN+P0FaQWS2k GuopY6BhXzlyWISByX3lSrnQO1KJ3b/Ix9qXFf9tnkIxhAmC04XEHiEc5w/D6F8lgWhW 1aXkh+epheEImIPzcn+qsg+6n93leXV4n2mexq91hZMZXiwR4MzAz6xHbU0xcYnBdlby ZDkv6Gz/hqTDBUD4U1gbkLA/Ol/ToeyU1vJ04cqmOsfLDBiL/YHLxUAXgc+LmuuFjauA LaX7x97O3su8zWruFmMgy8nfYKkq5wx0FOObgz/XSpMo71XCPkM8ka6LOyw7CCBZxEea UqDg== X-Gm-Message-State: APjAAAXk+57ANtB2VyKK3CbdlO/u9Bj5jSqkC+JpZXP1kZjuEBC/DuL9 SCXAsR0nnz1jh7lpZljM6Otx42+r X-Google-Smtp-Source: APXvYqxLFsFanFfd4yfW/frtx8PA6ZhNUWhXp+jgfYDuEcnvyPJJAHi4x1qlmiGpBmYE/LMxUtNwWA== X-Received: by 2002:a7b:cb02:: with SMTP id u2mr29998344wmj.142.1576511292905; Mon, 16 Dec 2019 07:48:12 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id q15sm22000564wrr.11.2019.12.16.07.48.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 16 Dec 2019 07:48:12 -0800 (PST) Message-Id: <3d0fcf6ba5afce860c6ecec4ca7d3a21ba49a3a6.1576511287.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Alexandr Miloslavskiy via GitGitGadget" Date: Mon, 16 Dec 2019 15:47:55 +0000 Subject: [PATCH v2 07/18] doc: checkout: remove duplicate synopsis Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Phillip Wood , Junio C Hamano , Emily Shaffer , Derrick Stolee , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Alexandr Miloslavskiy , Junio C Hamano , Alexandr Miloslavskiy Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Alexandr Miloslavskiy It was added in [1]. I understand that the duplicate change was not intentional and comes from an oversight. Also, in explanation, there was only one section for two synopsis entries. Fix both problems by removing duplicate synopsis. vs is resolved in next patch. [1] Commit b59698ae ("checkout doc: clarify command line args for "checkout paths" mode" 2017-10-11) Signed-off-by: Alexandr Miloslavskiy --- Documentation/git-checkout.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Documentation/git-checkout.txt b/Documentation/git-checkout.txt index cf3cac0a2b..2011fdbb1d 100644 --- a/Documentation/git-checkout.txt +++ b/Documentation/git-checkout.txt @@ -13,7 +13,6 @@ SYNOPSIS 'git checkout' [-q] [-f] [-m] [--detach] 'git checkout' [-q] [-f] [-m] [[-b|-B|--orphan] ] [] 'git checkout' [-f|--ours|--theirs|-m|--conflict=