From patchwork Tue Jan 28 18:26:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver via GitGitGadget X-Patchwork-Id: 11354803 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 E921C13A4 for ; Tue, 28 Jan 2020 18:26:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BDCF92467E for ; Tue, 28 Jan 2020 18:26:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="JJG73N2a" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726842AbgA1S0r (ORCPT ); Tue, 28 Jan 2020 13:26:47 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:37680 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726442AbgA1S0r (ORCPT ); Tue, 28 Jan 2020 13:26:47 -0500 Received: by mail-wr1-f67.google.com with SMTP id w15so17254276wru.4 for ; Tue, 28 Jan 2020 10:26:46 -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=PI7rAlWOADZX5nz+QBMgC5QO55bbe9huYYeZY+alby4=; b=JJG73N2aBFH5jJZAANADgkziLZoWD6LCF3QNVoyABldwX9+yXSdRhli7YOUg1jFwfZ F28/FWEOQnRsLPTsxqSh1hzHq9SUluL+x3ALKltgNdsbZAismqv+lLs2rQ+RWT2Mv0PP tFbTj9Ni7K/Vu+RHBJl950N0mx7od0ZaFOKUdvwfdlZFdzjTvzoUQZoLDDYw76m46beW c9fCWLMHja0LqrrPC5oPLJr7zHCIxFCNSU47NyANGsGAXukM3dYwwX4ka10POkL+fKNr vNsxZGchIP+YOVLM/kiPYGHbGQYod9spe0I84JhqhMxb3PRlPU/sKEbe+wp2jMLaoR2+ sY/g== 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=PI7rAlWOADZX5nz+QBMgC5QO55bbe9huYYeZY+alby4=; b=ZYOCw4u6PKBPeOENwpajpkF9Obp1+0IYwbrDSgz+4cJ0lUGZVTAmuguxzpGmLW2QQz evJcGBILIiwXRseHTaEQ9P9IQfyY9r3HmVcLJmoK6pp2nN+wVrTIvn2zfmF0ET24Fynl RE3rBBepHKUqPWBetZ1bhhwAR4S18nLnIQD8DxghtNrrHdFwwTOuqjidG98aWCPYy84V iNa8YSRjY9bfnHREDHMBebSWu2FH3hFB1D7lRj9w1P0aYvRp8HaUnpAGcdtmlKr1hnOp G0QUN9fKKVLnrtTTq41KeBUnafNMUzYsGzbp4ytc8r7SRCO5icsQ/Xj9vZwMI8UyoU/y LWAA== X-Gm-Message-State: APjAAAWzWfGenUQG67/t6hMuPmE6erqFNujJZs1see2UTexR4qw1E/O+ rgCidk0xZQvHeodnaTVgnFMDpuNv X-Google-Smtp-Source: APXvYqyUNsQpfxacEa469ZqrWJTuW6pmMNVndI5mtqyRkpYPzwputDv558ViSKktcFMAhtG+csGpUw== X-Received: by 2002:a5d:55c1:: with SMTP id i1mr2089704wrw.347.1580236005538; Tue, 28 Jan 2020 10:26:45 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id k13sm25676925wrx.59.2020.01.28.10.26.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Jan 2020 10:26:44 -0800 (PST) Message-Id: <1cc825412f0f2b66f7b89ed5ce33bcda937f4ee6.1580236003.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Derrick Stolee via GitGitGadget" Date: Tue, 28 Jan 2020 18:26:32 +0000 Subject: [PATCH v3 01/12] t1091: use check_files to reduce boilerplate Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: me@ttaylorr.com, peff@peff.net, newren@gmail.com, Derrick Stolee , Derrick Stolee Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee When testing the sparse-checkout feature, we need to compare the contents of the working-directory against some expected output. Using here-docs was useful in the beginning, but became repetetive as the test script grew. Create a check_files helper to make the tests simpler and easier to extend. It also reduces instances of bad here-doc whitespace. Signed-off-by: Derrick Stolee --- t/t1091-sparse-checkout-builtin.sh | 117 ++++++----------------------- 1 file changed, 22 insertions(+), 95 deletions(-) diff --git a/t/t1091-sparse-checkout-builtin.sh b/t/t1091-sparse-checkout-builtin.sh index ff7f8f7a1f..e058a20ad6 100755 --- a/t/t1091-sparse-checkout-builtin.sh +++ b/t/t1091-sparse-checkout-builtin.sh @@ -12,6 +12,13 @@ list_files() { (cd "$1" && printf '%s\n' *) } +check_files() { + list_files "$1" >actual && + shift && + printf "%s\n" $@ >expect && + test_cmp expect actual +} + test_expect_success 'setup' ' git init repo && ( @@ -58,9 +65,7 @@ test_expect_success 'git sparse-checkout init' ' EOF test_cmp expect repo/.git/info/sparse-checkout && test_cmp_config -C repo true core.sparsecheckout && - list_files repo >dir && - echo a >expect && - test_cmp expect dir + check_files repo a ' test_expect_success 'git sparse-checkout list after init' ' @@ -81,13 +86,7 @@ test_expect_success 'init with existing sparse-checkout' ' *folder* EOF test_cmp expect repo/.git/info/sparse-checkout && - list_files repo >dir && - cat >expect <<-EOF && - a - folder1 - folder2 - EOF - test_cmp expect dir + check_files repo a folder1 folder2 ' test_expect_success 'clone --sparse' ' @@ -98,9 +97,7 @@ test_expect_success 'clone --sparse' ' !/*/ EOF test_cmp expect actual && - list_files clone >dir && - echo a >expect && - test_cmp expect dir + check_files clone a ' test_expect_success 'set enables config' ' @@ -127,13 +124,7 @@ test_expect_success 'set sparse-checkout using builtin' ' git -C repo sparse-checkout list >actual && test_cmp expect actual && test_cmp expect repo/.git/info/sparse-checkout && - list_files repo >dir && - cat >expect <<-EOF && - a - folder1 - folder2 - EOF - test_cmp expect dir + check_files repo a folder1 folder2 ' test_expect_success 'set sparse-checkout using --stdin' ' @@ -147,13 +138,7 @@ test_expect_success 'set sparse-checkout using --stdin' ' git -C repo sparse-checkout list >actual && test_cmp expect actual && test_cmp expect repo/.git/info/sparse-checkout && - list_files repo >dir && - cat >expect <<-EOF && - a - folder1 - folder2 - EOF - test_cmp expect dir + check_files repo "a folder1 folder2" ' test_expect_success 'cone mode: match patterns' ' @@ -162,13 +147,7 @@ test_expect_success 'cone mode: match patterns' ' git -C repo read-tree -mu HEAD 2>err && test_i18ngrep ! "disabling cone patterns" err && git -C repo reset --hard && - list_files repo >dir && - cat >expect <<-EOF && - a - folder1 - folder2 - EOF - test_cmp expect dir + check_files repo a folder1 folder2 ' test_expect_success 'cone mode: warn on bad pattern' ' @@ -185,14 +164,7 @@ test_expect_success 'sparse-checkout disable' ' test_path_is_file repo/.git/info/sparse-checkout && git -C repo config --list >config && test_must_fail git config core.sparseCheckout && - list_files repo >dir && - cat >expect <<-EOF && - a - deep - folder1 - folder2 - EOF - test_cmp expect dir + check_files repo a deep folder1 folder2 ' test_expect_success 'cone mode: init and set' ' @@ -204,24 +176,9 @@ test_expect_success 'cone mode: init and set' ' test_cmp expect dir && git -C repo sparse-checkout set deep/deeper1/deepest/ 2>err && test_must_be_empty err && - list_files repo >dir && - cat >expect <<-EOF && - a - deep - EOF - test_cmp expect dir && - list_files repo/deep >dir && - cat >expect <<-EOF && - a - deeper1 - EOF - test_cmp expect dir && - list_files repo/deep/deeper1 >dir && - cat >expect <<-EOF && - a - deepest - EOF - test_cmp expect dir && + check_files repo a deep && + check_files repo/deep a deeper1 && + check_files repo/deep/deeper1 a deepest && cat >expect <<-EOF && /* !/*/ @@ -237,13 +194,7 @@ test_expect_success 'cone mode: init and set' ' folder2 EOF test_must_be_empty err && - cat >expect <<-EOF && - a - folder1 - folder2 - EOF - list_files repo >dir && - test_cmp expect dir + check_files repo a folder1 folder2 ' test_expect_success 'cone mode: list' ' @@ -275,13 +226,7 @@ test_expect_success 'revert to old sparse-checkout on bad update' ' test_must_fail git -C repo sparse-checkout set deep/deeper1 2>err && test_i18ngrep "cannot set sparse-checkout patterns" err && test_cmp repo/.git/info/sparse-checkout expect && - list_files repo/deep >dir && - cat >expect <<-EOF && - a - deeper1 - deeper2 - EOF - test_cmp dir expect + check_files repo/deep a deeper1 deeper2 ' test_expect_success 'revert to old sparse-checkout on empty update' ' @@ -332,12 +277,7 @@ test_expect_success 'cone mode: set with core.ignoreCase=true' ' /folder1/ EOF test_cmp expect repo/.git/info/sparse-checkout && - list_files repo >dir && - cat >expect <<-EOF && - a - folder1 - EOF - test_cmp expect dir + check_files repo a folder1 ' test_expect_success 'interaction with submodules' ' @@ -351,21 +291,8 @@ test_expect_success 'interaction with submodules' ' git sparse-checkout init --cone && git sparse-checkout set folder1 ) && - list_files super >dir && - cat >expect <<-\EOF && - a - folder1 - modules - EOF - test_cmp expect dir && - list_files super/modules/child >dir && - cat >expect <<-\EOF && - a - deep - folder1 - folder2 - EOF - test_cmp expect dir + check_files super a folder1 modules && + check_files super/modules/child a deep folder1 folder2 ' test_done From patchwork Tue Jan 28 18:26:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver via GitGitGadget X-Patchwork-Id: 11354807 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 6CB84112B for ; Tue, 28 Jan 2020 18:26:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3F22524681 for ; Tue, 28 Jan 2020 18:26:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="TFU2aTtZ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726916AbgA1S0v (ORCPT ); Tue, 28 Jan 2020 13:26:51 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:39690 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726496AbgA1S0t (ORCPT ); Tue, 28 Jan 2020 13:26:49 -0500 Received: by mail-wm1-f65.google.com with SMTP id c84so3651482wme.4 for ; Tue, 28 Jan 2020 10:26:47 -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=FZrkWwoOV3NNkcvOwJlM7IbVcGOH3Js85ThSFj7lETA=; b=TFU2aTtZP0KfxY7fHwxT3xRZoXrRKynWeVcCri5I89BMGnXoiP8zeNMeaM+82QMcER G1OgjtHn2Ul89OnO1s+B8u0Zw/4ASQri+kKSEjBJ+38kYfwFqYwCP+o7MnMqRHRmxrVz nc+KKQpKnZUWL8cB3qVV2Agsb3bMHWa2bFWJfwtkS5Rex+GZIoaTvcNAtypGnKKHCfyK w1ois0I2gQoEEJKUnhw2ZgsR60twVfnq4Ubi1eNH0JJ5WlshdNrN/WlOtGetrS0hzLE0 RqdYxg5n7z+fT8nKeM5cuKloVuXQF+P9XRE6ZKJTLvf6eVKRgqIPa1WA6U8eUrZTbQCT Sb+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=FZrkWwoOV3NNkcvOwJlM7IbVcGOH3Js85ThSFj7lETA=; b=BVAfta6AUY1Kv8rbVCVCkE+eKSDLtMuW0b32Rbrs62WOrOXxMpUcpy40eeMSikpAyW UIBk+lDG2TxNlILd32wS03qSfEpnQ4b2ee03k9sN85WrFfHpDMud2CVyWpcssRo5eWBx UGT6Ez0HFwqHpeT0tHjWzmST3KzKzRQweE224kMGHHK17QbiRe1Pk+2R0MEjQhZaWbAJ gOFk4PfFqW6YdkWShLeh7cDEQ5cDvnguUmsErq1V+bkJM+M5FiYZrm09EzpDi3Q/rBkM oePKld1C7Kat1eaMmCXwWA+gZ4ZRcXfPtWUHKLIx2Qqq8Q+X0/dGrVj9vfAsDEj3DLHC 4u+w== X-Gm-Message-State: APjAAAUpp+iiAz+pEvEdGWa0DQS7AU9OxCjoFV63rYZsDRbev6qhCTmd Gypoyg8k+bQi+JU532RevbFjLiaI X-Google-Smtp-Source: APXvYqxzWpsDMzk660U0pn6nJfkwihtMWq0psIuKI7VPzWateSvHu5Y2UyMdWlWg6YillibiGu6UFg== X-Received: by 2002:a7b:c416:: with SMTP id k22mr6741469wmi.25.1580236006355; Tue, 28 Jan 2020 10:26:46 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id g2sm26093567wrw.76.2020.01.28.10.26.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Jan 2020 10:26:45 -0800 (PST) Message-Id: In-Reply-To: References: From: "Derrick Stolee via GitGitGadget" Date: Tue, 28 Jan 2020 18:26:33 +0000 Subject: [PATCH v3 02/12] t1091: improve here-docs Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: me@ttaylorr.com, peff@peff.net, newren@gmail.com, Derrick Stolee , Derrick Stolee Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee t1091-sparse-checkout-builtin.sh uses here-docs to populate the expected contents of the sparse-checkout file. These do not use shell interpolation, so use "-\EOF" instead of "-EOF". Also use proper tabbing. Signed-off-by: Derrick Stolee --- t/t1091-sparse-checkout-builtin.sh | 98 +++++++++++++++--------------- 1 file changed, 49 insertions(+), 49 deletions(-) diff --git a/t/t1091-sparse-checkout-builtin.sh b/t/t1091-sparse-checkout-builtin.sh index e058a20ad6..e28e1c797f 100755 --- a/t/t1091-sparse-checkout-builtin.sh +++ b/t/t1091-sparse-checkout-builtin.sh @@ -46,11 +46,11 @@ test_expect_success 'git sparse-checkout list (empty)' ' test_expect_success 'git sparse-checkout list (populated)' ' test_when_finished rm -f repo/.git/info/sparse-checkout && - cat >repo/.git/info/sparse-checkout <<-EOF && - /folder1/* - /deep/ - **/a - !*bin* + cat >repo/.git/info/sparse-checkout <<-\EOF && + /folder1/* + /deep/ + **/a + !*bin* EOF cp repo/.git/info/sparse-checkout expect && git -C repo sparse-checkout list >list && @@ -59,9 +59,9 @@ test_expect_success 'git sparse-checkout list (populated)' ' test_expect_success 'git sparse-checkout init' ' git -C repo sparse-checkout init && - cat >expect <<-EOF && - /* - !/*/ + cat >expect <<-\EOF && + /* + !/*/ EOF test_cmp expect repo/.git/info/sparse-checkout && test_cmp_config -C repo true core.sparsecheckout && @@ -70,9 +70,9 @@ test_expect_success 'git sparse-checkout init' ' test_expect_success 'git sparse-checkout list after init' ' git -C repo sparse-checkout list >actual && - cat >expect <<-EOF && - /* - !/*/ + cat >expect <<-\EOF && + /* + !/*/ EOF test_cmp expect actual ' @@ -80,10 +80,10 @@ test_expect_success 'git sparse-checkout list after init' ' test_expect_success 'init with existing sparse-checkout' ' echo "*folder*" >> repo/.git/info/sparse-checkout && git -C repo sparse-checkout init && - cat >expect <<-EOF && - /* - !/*/ - *folder* + cat >expect <<-\EOF && + /* + !/*/ + *folder* EOF test_cmp expect repo/.git/info/sparse-checkout && check_files repo a folder1 folder2 @@ -92,9 +92,9 @@ test_expect_success 'init with existing sparse-checkout' ' test_expect_success 'clone --sparse' ' git clone --sparse repo clone && git -C clone sparse-checkout list >actual && - cat >expect <<-EOF && - /* - !/*/ + cat >expect <<-\EOF && + /* + !/*/ EOF test_cmp expect actual && check_files clone a @@ -116,10 +116,10 @@ test_expect_success 'set enables config' ' test_expect_success 'set sparse-checkout using builtin' ' git -C repo sparse-checkout set "/*" "!/*/" "*folder*" && - cat >expect <<-EOF && - /* - !/*/ - *folder* + cat >expect <<-\EOF && + /* + !/*/ + *folder* EOF git -C repo sparse-checkout list >actual && test_cmp expect actual && @@ -128,11 +128,11 @@ test_expect_success 'set sparse-checkout using builtin' ' ' test_expect_success 'set sparse-checkout using --stdin' ' - cat >expect <<-EOF && - /* - !/*/ - /folder1/ - /folder2/ + cat >expect <<-\EOF && + /* + !/*/ + /folder1/ + /folder2/ EOF git -C repo sparse-checkout set --stdin actual && @@ -179,28 +179,28 @@ test_expect_success 'cone mode: init and set' ' check_files repo a deep && check_files repo/deep a deeper1 && check_files repo/deep/deeper1 a deepest && - cat >expect <<-EOF && - /* - !/*/ - /deep/ - !/deep/*/ - /deep/deeper1/ - !/deep/deeper1/*/ - /deep/deeper1/deepest/ + cat >expect <<-\EOF && + /* + !/*/ + /deep/ + !/deep/*/ + /deep/deeper1/ + !/deep/deeper1/*/ + /deep/deeper1/deepest/ EOF test_cmp expect repo/.git/info/sparse-checkout && - git -C repo sparse-checkout set --stdin 2>err <<-EOF && - folder1 - folder2 + git -C repo sparse-checkout set --stdin 2>err <<-\EOF && + folder1 + folder2 EOF test_must_be_empty err && check_files repo a folder1 folder2 ' test_expect_success 'cone mode: list' ' - cat >expect <<-EOF && - folder1 - folder2 + cat >expect <<-\EOF && + folder1 + folder2 EOF git -C repo sparse-checkout set --stdin actual 2>err && @@ -211,10 +211,10 @@ test_expect_success 'cone mode: list' ' test_expect_success 'cone mode: set with nested folders' ' git -C repo sparse-checkout set deep deep/deeper1/deepest 2>err && test_line_count = 0 err && - cat >expect <<-EOF && - /* - !/*/ - /deep/ + cat >expect <<-\EOF && + /* + !/*/ + /deep/ EOF test_cmp repo/.git/info/sparse-checkout expect ' @@ -271,10 +271,10 @@ test_expect_success 'sparse-checkout (init|set|disable) fails with dirty status' test_expect_success 'cone mode: set with core.ignoreCase=true' ' git -C repo sparse-checkout init --cone && git -C repo -c core.ignoreCase=true sparse-checkout set folder1 && - cat >expect <<-EOF && - /* - !/*/ - /folder1/ + cat >expect <<-\EOF && + /* + !/*/ + /folder1/ EOF test_cmp expect repo/.git/info/sparse-checkout && check_files repo a folder1 From patchwork Tue Jan 28 18:26:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver via GitGitGadget X-Patchwork-Id: 11354813 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 1B47F1395 for ; Tue, 28 Jan 2020 18:26:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id EDEA524683 for ; Tue, 28 Jan 2020 18:26:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="BMpNdT5P" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726912AbgA1S0v (ORCPT ); Tue, 28 Jan 2020 13:26:51 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:36659 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726442AbgA1S0t (ORCPT ); Tue, 28 Jan 2020 13:26:49 -0500 Received: by mail-wr1-f67.google.com with SMTP id z3so17241586wru.3 for ; Tue, 28 Jan 2020 10:26:47 -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=LHv3OUouiSWEjPl69LIDx7kK+8FoKtUJpN5eFvZqOEw=; b=BMpNdT5PNGH+mUk8BNVJNYYdBrtsLEdx6SUDFQcSS8/4mttTwEzp7GyP9jPSbH2lNZ yyS+/drFN2UqtjD8b9uXYVYDYUUBz3FzOf7UoXqci4ObvXoz8gA5rbdgEPg79H/+UheB ekXt6Rot6KUdceCYiVfwmEV3eGlsdsYF9Dz9ZVkD1RSB+m10FYNO2QGjrjKCj+mHW1wM r4OEv9LvudwB7bB5YgFCBFD3OH6Z4ruymNdcKJGN+DpxqOSRqxwXelBX2UfGTomPY2yD ZwrumcWvf3Kd9gdgGIKW59PlQvQksbGbTlkfLg8qmgrl2PCKyOLo8AVobVQnjoPIXIax YB3A== 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=LHv3OUouiSWEjPl69LIDx7kK+8FoKtUJpN5eFvZqOEw=; b=Xwokp8JE45OG3JqBlyVxkBfENCdln5rm4LRZ2RTjGAWbuwIM/AZq4s26ua3eIp7Eus yp/l76xa8KuVDMbGot+/ZznN/kp+VJvTbuKJAQaa9IbBdemSo41N+vz8OkTSUkvNW6q6 9n0Vs5uqsvSKPLDEDSS9UeOH4lAsTss8P67KijseILLcpQy18BSi6FeMmkwYC2JIqa3t Xpa9JWTVWWfQUo39tfGPzOLmGssP0ho6wBCAjnFFz96V/34ddy377mqXciKDR0s3/7eA dZy/tjbDN6heY6puc/I4eIumsucIMZ6bMqerAa4Wv6L/Vf3LpmSqtuP9yHvcSiuNN/UR Jvlw== X-Gm-Message-State: APjAAAVys+NhCSCyWvV2UPO5IWIoLlTR58FN1nsLx8OsY3soUvbApd8y 4SUcs2AwreiIAvff9UqQlkiZuSBI X-Google-Smtp-Source: APXvYqyI3Pp5vZKmo5IrWJaoXTs8+Z6cUH4c+YDaeKN7V73Yo5xyHpgPmCN4FZXvJSiAzR9TMXhxLQ== X-Received: by 2002:adf:ef49:: with SMTP id c9mr31765163wrp.292.1580236007181; Tue, 28 Jan 2020 10:26:47 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id v17sm26172113wrt.91.2020.01.28.10.26.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Jan 2020 10:26:46 -0800 (PST) Message-Id: <5497ad8778c29ca936206d2ded6773758c236c12.1580236003.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Derrick Stolee via GitGitGadget" Date: Tue, 28 Jan 2020 18:26:34 +0000 Subject: [PATCH v3 03/12] sparse-checkout: create leading directories Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: me@ttaylorr.com, peff@peff.net, newren@gmail.com, Derrick Stolee , Derrick Stolee Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee The 'git init' command creates the ".git/info" directory and fills it with some default files. However, 'git worktree add' does not create the info directory for that worktree. This causes a problem when running "git sparse-checkout init" inside a worktree. While care was taken to allow the sparse-checkout config to be specific to a worktree, this initialization was untested. Safely create the leading directories for the sparse-checkout file. This is the safest thing to do even without worktrees, as a user could delete their ".git/info" directory and expect Git to recover safely. Signed-off-by: Derrick Stolee --- builtin/sparse-checkout.c | 4 ++++ t/t1091-sparse-checkout-builtin.sh | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/builtin/sparse-checkout.c b/builtin/sparse-checkout.c index b3bed891cb..3cee8ab46e 100644 --- a/builtin/sparse-checkout.c +++ b/builtin/sparse-checkout.c @@ -199,6 +199,10 @@ static int write_patterns_and_update(struct pattern_list *pl) int result; sparse_filename = get_sparse_checkout_filename(); + + if (safe_create_leading_directories(sparse_filename)) + die(_("failed to create directory for sparse-checkout file")); + fd = hold_lock_file_for_update(&lk, sparse_filename, LOCK_DIE_ON_ERROR); diff --git a/t/t1091-sparse-checkout-builtin.sh b/t/t1091-sparse-checkout-builtin.sh index e28e1c797f..43d1f7520c 100755 --- a/t/t1091-sparse-checkout-builtin.sh +++ b/t/t1091-sparse-checkout-builtin.sh @@ -295,4 +295,14 @@ test_expect_success 'interaction with submodules' ' check_files super/modules/child a deep folder1 folder2 ' +test_expect_success 'different sparse-checkouts with worktrees' ' + git -C repo worktree add --detach ../worktree && + check_files worktree "a deep folder1 folder2" && + git -C worktree sparse-checkout init --cone && + git -C repo sparse-checkout set folder1 && + git -C worktree sparse-checkout set deep/deeper1 && + check_files repo a folder1 && + check_files worktree a deep +' + test_done From patchwork Tue Jan 28 18:26:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver via GitGitGadget X-Patchwork-Id: 11354809 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 E7208188B for ; Tue, 28 Jan 2020 18:26:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C5E8124681 for ; Tue, 28 Jan 2020 18:26:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="FyLqBmQa" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726947AbgA1S0v (ORCPT ); Tue, 28 Jan 2020 13:26:51 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:46437 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726276AbgA1S0t (ORCPT ); Tue, 28 Jan 2020 13:26:49 -0500 Received: by mail-wr1-f67.google.com with SMTP id z7so17177351wrl.13 for ; Tue, 28 Jan 2020 10:26:48 -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=KDhiP/nTsJtYltovU0qLNJhnLe1wUUQjqGoJo1gXOog=; b=FyLqBmQaP8DukXvPt0x5os6o/PdYnQ4LLeJVjOvrg0NtfzFlZmWGQEnJNEjHOXELG7 kfLFy1ndsSjOtnQJwCmIH9zCLO3CVBn564Mqi8XZqeSGBqYu9yszfaM0zG9oAeHbCJKh l5iaW+/OxEeqBJIayiX6HIc7Cjm1xGt5J01qLX3yJO/s8gi8QEdq6FLScZIYg57e5QtS zvE2Jzvhgc+L4Ygte4H2rfFNFz+MA3HRLOBjsUsh5LwFyl3xxbL3iytY96feVUTYjHiM BCEClHfNOaixIHgQiVLBVmuRaU25gL6A1qTCapWo4e8c7Qypl+RDCxMWBVqZAAySRx7+ dDGQ== 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=KDhiP/nTsJtYltovU0qLNJhnLe1wUUQjqGoJo1gXOog=; b=nm3YugBrjN9vLxO5quL6UM0+KqgPPHdd3o3ejnq1rrSEbhFJ+/lraEwPRpbgZAlFR9 a6KnrLvzDMFxr7FFRzzh2hcaT3uW+WM93eiqDLtgePthyYgLSLwBdvmS1al+NwYtD/WQ gyD9Lr6h7kZHl2/FNwi3XH9Ah0MKgFiCglFCJh9Z6oYXtx/ye5pz06D3p2Mts/YWzVTa xiLRObtc4EIepJifoCa8hJy40CdV1Sn33UUa38xs+nVwW6t97KqppIT8eTSQM4Nwi+r2 yqdUpbYdcxHDUkQtjxrqxIA7mEXPe769L/40uLkUudOzSXZrEwwf6j/9mJ9EJSNPml1R pekg== X-Gm-Message-State: APjAAAXxDAAdHT7qtU/OwmxwUrVdurF2aCH4kza5G9YV9XHr4BFf0+Ye J1nscveA5a3pDgHGfypmalnIfpRQ X-Google-Smtp-Source: APXvYqzrV8gr+E0y+emmzs0oKtTaGs7R8eZleQyFAn3D1TgUZpoi6cTTtH3FlIdKjpMeeAf8aybj0g== X-Received: by 2002:a5d:56ca:: with SMTP id m10mr31258993wrw.313.1580236007908; Tue, 28 Jan 2020 10:26:47 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id d10sm27127510wrw.64.2020.01.28.10.26.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Jan 2020 10:26:47 -0800 (PST) Message-Id: <4991a51f6d5d840eaa3bb830e68f1530c2ee08e4.1580236003.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Derrick Stolee via GitGitGadget" Date: Tue, 28 Jan 2020 18:26:35 +0000 Subject: [PATCH v3 04/12] clone: fix --sparse option with URLs Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: me@ttaylorr.com, peff@peff.net, newren@gmail.com, Derrick Stolee , Derrick Stolee Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee The --sparse option was added to the clone builtin in d89f09c (clone: add --sparse mode, 2019-11-21) and was tested with a local path clone in t1091-sparse-checkout-builtin.sh. However, due to a difference in how local paths are handled versus URLs, this mechanism does not work with URLs. Modify the test to use a "file://" URL, which would output this error before the code change: Cloning into 'clone'... fatal: cannot change to 'file://.../repo': No such file or directory error: failed to initialize sparse-checkout These errors are due to using a "-C " option to call 'git -C sparse-checkout init' but the URL is being given instead of the target directory. Update that target directory to evaluate this correctly. I have also manually tested that https:// URLs are handled correctly as well. Acked-by: Taylor Blau Signed-off-by: Derrick Stolee --- builtin/clone.c | 2 +- t/t1091-sparse-checkout-builtin.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/builtin/clone.c b/builtin/clone.c index 4348d962c9..2caefc44fb 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -1130,7 +1130,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix) if (option_required_reference.nr || option_optional_reference.nr) setup_reference(); - if (option_sparse_checkout && git_sparse_checkout_init(repo)) + if (option_sparse_checkout && git_sparse_checkout_init(dir)) return 1; remote = remote_get(option_origin); diff --git a/t/t1091-sparse-checkout-builtin.sh b/t/t1091-sparse-checkout-builtin.sh index 43d1f7520c..cf4a595c86 100755 --- a/t/t1091-sparse-checkout-builtin.sh +++ b/t/t1091-sparse-checkout-builtin.sh @@ -90,7 +90,7 @@ test_expect_success 'init with existing sparse-checkout' ' ' test_expect_success 'clone --sparse' ' - git clone --sparse repo clone && + git clone --sparse "file://$(pwd)/repo" clone && git -C clone sparse-checkout list >actual && cat >expect <<-\EOF && /* From patchwork Tue Jan 28 18:26:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver via GitGitGadget X-Patchwork-Id: 11354811 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 AA0281395 for ; Tue, 28 Jan 2020 18:26:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 88B1C24681 for ; Tue, 28 Jan 2020 18:26:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="bsNuP9zd" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726940AbgA1S0v (ORCPT ); Tue, 28 Jan 2020 13:26:51 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:35986 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726900AbgA1S0u (ORCPT ); Tue, 28 Jan 2020 13:26:50 -0500 Received: by mail-wm1-f66.google.com with SMTP id p17so3673600wma.1 for ; Tue, 28 Jan 2020 10:26:49 -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=pl9kK0IVJdtZMHXu52/f8Sm0g3stqkcV9VxPh4NkuJo=; b=bsNuP9zd9zk4+cpClSH9mpG6UrmlxBUaMdLDXourUztDzE+XtAUO5hWq4Kq2qaG4Rf pj5d8DzIq5ZLHK/ZnrdwdrdWDZobj6C3FKq6ZPKQjhEKwt9hKPm1hhGOqCihKj/yS1HH 4xRvtoRUZiKUdpBcbAnz9J8hM7CYomXVRqvke5oqxA3MfED0swda57viG1/9ZU+fxyvt 5iGZNdUkCFDeq/rP0k/FCkRRyDrBXE+lna6Ft9xVGmTgKKcQjxjRTzkPzwQV6xeXEnEX vxH8w48effC1DysGhCDTY1BhYyUH1VgSJI3XW1F1JV1i7xTvOCtCbqcns4qfGrZmbfQk /GMQ== 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=pl9kK0IVJdtZMHXu52/f8Sm0g3stqkcV9VxPh4NkuJo=; b=AHivT9yYPT6AUOnVZUs44OcOzx9lupd8E/wgSkYVbVo5/ObwxGWIlIaP4g06g9hXr8 XwI8RViwui3GoiS3G+Bjsd2fFUHmkPW+FYDeomww8UuvDaiKR+4v9MSgLBsOBp0uoqD1 pLbYBHRX+dFllAdM8B/z7S4gH0pY8y5fKn2Fs8MoGvwYlaUs8vrr7cgLWC8PMvfcvZTe BaJ8vamJZrD18NHh42GLxWYrhLtqTMByhWqv5Dm7U55bV+8K4g6JY5kxcdnFqTSvDEMJ eN+48ZswQy6Gj9j2xG6tCIp1QOM8n7j1JYUNR7NSUEanoQXgYrGpaVqGFjqxKjXjXVl+ Cv1Q== X-Gm-Message-State: APjAAAWRIJ9yzoIIUCmAjDTpZPwpQcWM4Wk8OdfiHz/ith5uEjiWx3+G IIdpd9m21yIk2/7poeepFLiko22F X-Google-Smtp-Source: APXvYqz8Zc1zsNqSLJ3Ichp+C5an9L1CxMoTXH3TlDXqldkqFSv/41DfuXm4fI7GF07Qsk8INyY3lQ== X-Received: by 2002:a05:600c:2409:: with SMTP id 9mr6388758wmp.109.1580236008582; Tue, 28 Jan 2020 10:26:48 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id n14sm4075092wmi.26.2020.01.28.10.26.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Jan 2020 10:26:48 -0800 (PST) Message-Id: In-Reply-To: References: From: "Jeff King via GitGitGadget" Date: Tue, 28 Jan 2020 18:26:36 +0000 Subject: [PATCH v3 05/12] sparse-checkout: fix documentation typo for core.sparseCheckoutCone Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: me@ttaylorr.com, peff@peff.net, newren@gmail.com, Derrick Stolee , Jeff King Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Jeff King Signed-off-by: Jeff King Signed-off-by: Derrick Stolee --- Documentation/git-sparse-checkout.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Documentation/git-sparse-checkout.txt b/Documentation/git-sparse-checkout.txt index 3b341cf0fc..4834fb434d 100644 --- a/Documentation/git-sparse-checkout.txt +++ b/Documentation/git-sparse-checkout.txt @@ -106,7 +106,7 @@ The full pattern set allows for arbitrary pattern matches and complicated inclusion/exclusion rules. These can result in O(N*M) pattern matches when updating the index, where N is the number of patterns and M is the number of paths in the index. To combat this performance issue, a more restricted -pattern set is allowed when `core.spareCheckoutCone` is enabled. +pattern set is allowed when `core.sparseCheckoutCone` is enabled. The accepted patterns in the cone pattern set are: From patchwork Tue Jan 28 18:26:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver via GitGitGadget X-Patchwork-Id: 11354815 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 B54ED112B for ; Tue, 28 Jan 2020 18:26:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9404324681 for ; Tue, 28 Jan 2020 18:26:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ftnYDszc" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726967AbgA1S0y (ORCPT ); Tue, 28 Jan 2020 13:26:54 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:41805 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726885AbgA1S0v (ORCPT ); Tue, 28 Jan 2020 13:26:51 -0500 Received: by mail-wr1-f68.google.com with SMTP id c9so17219760wrw.8 for ; Tue, 28 Jan 2020 10:26:50 -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=pp+putYic/YPhOPXhgtuPLfFxxGHo2lzSEwyNyMGA0M=; b=ftnYDszcnRlJJ+eYW3WytlncJv/TgxQC/kKOr2QpKQl94hcZuBmjIAygyM09vR6kGF 9cBh3eC4pg4avpwjD4WRaowd+Qux56r+O0YPqO3zWk3j3xpsEXLOr3xXOq8ttS0zJzys 7XbVKvN8Ofg76Oe/5rq7l0w4uhRdBL2vO818ewT34eP3hFv69u9aYYGDaLIHYRGppHZr oFHH29Vcg8UR+AbLTwUmqg8r2v704TYv1SHoWmOUCjXc+2lBC0gIONRny4U2LIBtoiVW aaQselNt4el3jqyKIwSx3psKMyVGZHge48BXKxMyC/QzTXRHbnrFkuL2AqHcv3jMJQR9 R+uw== 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=pp+putYic/YPhOPXhgtuPLfFxxGHo2lzSEwyNyMGA0M=; b=jNNuu25ytcHa6w0S92jqqbMY66k6kPQIcyDmwSoeQsWzg3QJYKVuUkxX1QOHJsYijS iWxarL11jqFU52eS4QhoTSKpNZzXhP4Y1XhgKqRphaySUobcDSOFS8Jm5PpzxhhCfniq pHP2IJjC0lropw65kRmnBf55VI28sFjBcPhsE2Eo66ik38Af8FkArpajJFz9n5AOqPZZ 7DkpxMh2RnYQehCSnwOaKsSF2J9Qr0e1LT17ikUrUnHp1WdS4Ha5FzwG7HTzyKMamZpo EQd9kJWgSCgXI6v16qD7EGFIl4n7pdHuvtwixehhXEMtXK2Ppz2U3Xhr84/vaeP9zF+O Umkg== X-Gm-Message-State: APjAAAWeMyo9dESPvH0xF8SC4OkAI6TBi9pg5ZuEAiyVRW59vFPfckJ6 jwrNjGZLP6iS1BhwXjoqTiRlM9HF X-Google-Smtp-Source: APXvYqxdc/q+ddEc1V2hhN65KO9lAztsfu4Fdga3F1cYR8a44aH/kzkeY9mGiMsMZdJ/HDWBiVjwFA== X-Received: by 2002:a05:6000:1252:: with SMTP id j18mr330646wrx.103.1580236009282; Tue, 28 Jan 2020 10:26:49 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id a184sm4088889wmf.29.2020.01.28.10.26.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Jan 2020 10:26:48 -0800 (PST) Message-Id: <2ad4d3e467a7e2be679de4084e54f426aa242bd6.1580236003.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Derrick Stolee via GitGitGadget" Date: Tue, 28 Jan 2020 18:26:37 +0000 Subject: [PATCH v3 06/12] sparse-checkout: cone mode does not recognize "**" Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: me@ttaylorr.com, peff@peff.net, newren@gmail.com, Derrick Stolee , Derrick Stolee Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee When core.sparseCheckoutCone is enabled, the 'git sparse-checkout set' command creates a restricted set of possible patterns that are used by a custom algorithm to quickly match those patterns. If a user manually edits the sparse-checkout file, then they could create patterns that do not match these expectations. The cone-mode matching algorithm can return incorrect results. The solution is to detect these incorrect patterns, warn that we do not recognize them, and revert to the standard algorithm. Check each pattern for the "**" substring, and revert to the old logic if seen. While technically a "//**" pattern matches the meaning of "//", it is not one that would be written by the sparse-checkout builtin in cone mode. Attempting to accept that pattern change complicates the logic and instead we punt and do not accept any instance of "**". Signed-off-by: Derrick Stolee --- dir.c | 7 +++++- t/t1091-sparse-checkout-builtin.sh | 34 ++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/dir.c b/dir.c index 22d08e61c2..40fed73a94 100644 --- a/dir.c +++ b/dir.c @@ -651,11 +651,16 @@ static void add_pattern_to_hashsets(struct pattern_list *pl, struct path_pattern return; } + if (strstr(given->pattern, "**")) { + /* Not a cone pattern. */ + warning(_("unrecognized pattern: '%s'"), given->pattern); + goto clear_hashmaps; + } + if (given->patternlen > 2 && !strcmp(given->pattern + given->patternlen - 2, "/*")) { if (!(given->flags & PATTERN_FLAG_NEGATIVE)) { /* Not a cone pattern. */ - pl->use_cone_patterns = 0; warning(_("unrecognized pattern: '%s'"), given->pattern); goto clear_hashmaps; } diff --git a/t/t1091-sparse-checkout-builtin.sh b/t/t1091-sparse-checkout-builtin.sh index cf4a595c86..e2e45dc7fd 100755 --- a/t/t1091-sparse-checkout-builtin.sh +++ b/t/t1091-sparse-checkout-builtin.sh @@ -305,4 +305,38 @@ test_expect_success 'different sparse-checkouts with worktrees' ' check_files worktree a deep ' +check_read_tree_errors () { + REPO=$1 + FILES=$2 + ERRORS=$3 + git -C $REPO read-tree -mu HEAD 2>err && + if test -z "$ERRORS" + then + test_must_be_empty err + else + test_i18ngrep "$ERRORS" err + fi && + check_files $REPO $FILES +} + +test_expect_success 'pattern-checks: /A/**' ' + cat >repo/.git/info/sparse-checkout <<-\EOF && + /* + !/*/ + /folder1/** + EOF + check_read_tree_errors repo "a folder1" "disabling cone pattern matching" +' + +test_expect_success 'pattern-checks: /A/**/B/' ' + cat >repo/.git/info/sparse-checkout <<-\EOF && + /* + !/*/ + /deep/**/deepest + EOF + check_read_tree_errors repo "a deep" "disabling cone pattern matching" && + check_files repo/deep "deeper1" && + check_files repo/deep/deeper1 "deepest" +' + test_done From patchwork Tue Jan 28 18:26:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver via GitGitGadget X-Patchwork-Id: 11354825 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 53C7E1395 for ; Tue, 28 Jan 2020 18:27:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 32CC02467E for ; Tue, 28 Jan 2020 18:27:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="lJgWSHX7" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727067AbgA1S1B (ORCPT ); Tue, 28 Jan 2020 13:27:01 -0500 Received: from mail-wr1-f66.google.com ([209.85.221.66]:42386 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726902AbgA1S0w (ORCPT ); Tue, 28 Jan 2020 13:26:52 -0500 Received: by mail-wr1-f66.google.com with SMTP id k11so2534292wrd.9 for ; Tue, 28 Jan 2020 10:26:50 -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=7g3RInPRozRcqfiodm1wMBj88ZZT+XDAcmQ//AaX4/c=; b=lJgWSHX7TDrSc1e09R6TUF4el8i5aIHY0U0OXTT10fhm6vK4493tZPtRqVz0rmwQg5 /We+0ERfTgwXqc1AHg3zu0iDpqH0IVguQOdtxPNG0665fWNyBcmEZtO3WkCEtYSsHi4j bfbvThofMArfLR1djxW58wTIfUcKyLqsnf5styULFj6Xy1GnLLhA/hJPiif/DpL3ghcW JNJqJPpiZbrNz1LWRSNraw7M0YkElolAFswRXJ9d1Rx1lAGnvFTvkpEWnHkTsnc/eIBc mmTSR2X9eyNCY6LMZt18rMOR2nScm/Sr5ohdmbsu0aHvAZDzia5YkqJCVelZittXDNkw LIPQ== 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=7g3RInPRozRcqfiodm1wMBj88ZZT+XDAcmQ//AaX4/c=; b=BPXDcrW/lHE+T1ik4HGZn7BpUt0LIhKuA493c3QB3q50DGbSzdmL4RY7Wjv2FvxbuY gbwcafLnzoe2FmI91PXaUL4ocL8PRIb9VCaIvlfnFFPWpyYoctlNO4pDfS/OMONPg+wV xbw0BmX1MTpqWIhkN3D2vTxBmuH2u788TZCCeAGbHVeYvJV0I7UbJFQruCXxPtAw23Cj qltOmquztYwS6m+G918VAmKRjgcqKUgoZoViwP6hZw6/6U4Mize9YPa29P9oUQ+pprwm rMMtoKrPHZ8HzC5t3bZj8b/LdKEuVWp8QRvkaSOtyud26/zBt7MCHD7TIEdZVDyWrCxJ +4PQ== X-Gm-Message-State: APjAAAUnIl1IIGiHybrLhQEdAyjcc5CkgE7lEIL2QJjWjkTxwyfzSzoX NnYtFhbIhGwwj6Aj84W+c4re2TlK X-Google-Smtp-Source: APXvYqzqx0RvlpF3NL4pjxvLyDi8j+/r0uYwSZAhJicxR2tURGKplMaE4Rg50iGySJaia+O5UWZ0DQ== X-Received: by 2002:a5d:50ce:: with SMTP id f14mr31790245wrt.254.1580236010033; Tue, 28 Jan 2020 10:26:50 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id i10sm27237975wru.16.2020.01.28.10.26.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Jan 2020 10:26:49 -0800 (PST) Message-Id: In-Reply-To: References: From: "Derrick Stolee via GitGitGadget" Date: Tue, 28 Jan 2020 18:26:38 +0000 Subject: [PATCH v3 07/12] sparse-checkout: detect short patterns Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: me@ttaylorr.com, peff@peff.net, newren@gmail.com, Derrick Stolee , Derrick Stolee Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee In cone mode, the shortest pattern the sparse-checkout command will write into the sparse-checkout file is "/*". This is handled carefully in add_pattern_to_hashsets(), so warn if any other pattern is this short. This will assist future pattern checks by allowing us to assume there are at least three characters in the pattern. Signed-off-by: Derrick Stolee --- dir.c | 3 ++- t/t1091-sparse-checkout-builtin.sh | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/dir.c b/dir.c index 40fed73a94..c2e585607e 100644 --- a/dir.c +++ b/dir.c @@ -651,7 +651,8 @@ static void add_pattern_to_hashsets(struct pattern_list *pl, struct path_pattern return; } - if (strstr(given->pattern, "**")) { + if (given->patternlen <= 2 || + strstr(given->pattern, "**")) { /* Not a cone pattern. */ warning(_("unrecognized pattern: '%s'"), given->pattern); goto clear_hashmaps; diff --git a/t/t1091-sparse-checkout-builtin.sh b/t/t1091-sparse-checkout-builtin.sh index e2e45dc7fd..2e57534799 100755 --- a/t/t1091-sparse-checkout-builtin.sh +++ b/t/t1091-sparse-checkout-builtin.sh @@ -339,4 +339,13 @@ test_expect_success 'pattern-checks: /A/**/B/' ' check_files repo/deep/deeper1 "deepest" ' +test_expect_success 'pattern-checks: too short' ' + cat >repo/.git/info/sparse-checkout <<-\EOF && + /* + !/*/ + /a + EOF + check_read_tree_errors repo "a" "disabling cone pattern matching" +' + test_done From patchwork Tue Jan 28 18:26:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver via GitGitGadget X-Patchwork-Id: 11354823 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 488E91395 for ; Tue, 28 Jan 2020 18:27:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 27E9A2467E for ; Tue, 28 Jan 2020 18:27:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="EOk4jeN0" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727080AbgA1S1C (ORCPT ); Tue, 28 Jan 2020 13:27:02 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:40032 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726496AbgA1S0w (ORCPT ); Tue, 28 Jan 2020 13:26:52 -0500 Received: by mail-wr1-f65.google.com with SMTP id j104so1312836wrj.7 for ; Tue, 28 Jan 2020 10:26:51 -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=XNhZKH2DWroFtn02NgQ9WdR9JWMJu16ac61ekE1F9EM=; b=EOk4jeN0vrUxFLtEGRsUqODqVFkNOZriQ4mIJbpZyA6mdCCQOWRhPm4GUAEBxvZ+kT 9GFnAYBPC9TgMz+HwJ5ph/MwZJr4yMZ3/vuUsUaif7EZ249uuDhkwKGfSPA4W/deo+zA 6klsjchX4mvqGs/Tj23qizILiqyzrTWuYaDqb6CR0x0fvNohiXdiVs3ydVoe43tzKm/h gK/8yl6baJk9pU7wuqUXEZ80YF3Q+hA82Guco3aSRib31eIwExKe7fhmGJ6i0v2OmUXr FUabuiGSjEXwTvqvwIjJb0HbWwK3Ww767+czG6is3ZHGH27rG1J/c/vl854I0199ZpKL 0fJQ== 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=XNhZKH2DWroFtn02NgQ9WdR9JWMJu16ac61ekE1F9EM=; b=ZWwEUVlgV+LUxJq4+BJb3VOYKL1nFADkr+0aBu+WiHMLF2AT2s/KaEj84kzDNQFXt0 82uUjhnWHfQXNldKG+di6g+k4FhQgTiHZEl1K7GHMDdMcppUin7o+gUH03IBzrNf/4PU 16PKxo4GPQifbJs8eSGAugh7UBz5gLHzdbhaQHKqt3SSvB2RpbgR05iMOK+SdS5yEitK 66FnmtL9KAOgB9C/Cgw1OQZHqB9ZKxgChioOErlNhUTOXLAewNoFyXRg4dazjuT4LSYz WM4KNjLiSxSdPBuQ0xQ0rwBUg44kkBQzhKZ1nrD3WhC5ObD9W8FuYyGBlveXVWWektN1 UpUg== X-Gm-Message-State: APjAAAU8DqtDlI6nBZzUBuXPuaQ6rRBHHw7v2sZECk6g03fuoNNnI0sB UTe8BKIdxCzZwLr2ZSsqZYWfQhUz X-Google-Smtp-Source: APXvYqz6pAPjnY2OnKSrLA1GUBrYRHeGienEiChvsPDuEuPi4zxRMtMZ8Wjr+YOibDBdnlHArLDbeg== X-Received: by 2002:adf:e58d:: with SMTP id l13mr30226562wrm.135.1580236010743; Tue, 28 Jan 2020 10:26:50 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id k16sm29045891wru.0.2020.01.28.10.26.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Jan 2020 10:26:50 -0800 (PST) Message-Id: In-Reply-To: References: From: "Derrick Stolee via GitGitGadget" Date: Tue, 28 Jan 2020 18:26:39 +0000 Subject: [PATCH v3 08/12] sparse-checkout: warn on incorrect '*' in patterns Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: me@ttaylorr.com, peff@peff.net, newren@gmail.com, Derrick Stolee , Derrick Stolee Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee In cone mode, the sparse-checkout commmand will write patterns that allow faster pattern matching. This matching only works if the patterns in the sparse-checkout file are those written by that command. Users can edit the sparse-checkout file and create patterns that cause the cone mode matching to fail. The cone mode patterns may end in "/*" but otherwise an un-escaped asterisk is invalid. Add checks to disable cone mode when seeing these values. A later change will properly handle escaped asterisks. Signed-off-by: Derrick Stolee --- dir.c | 29 +++++++++++++++++++++++++++++ t/t1091-sparse-checkout-builtin.sh | 27 +++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/dir.c b/dir.c index c2e585607e..7cb78c8b87 100644 --- a/dir.c +++ b/dir.c @@ -635,6 +635,7 @@ static void add_pattern_to_hashsets(struct pattern_list *pl, struct path_pattern struct pattern_entry *translated; char *truncated; char *data = NULL; + const char *prev, *cur, *next; if (!pl->use_cone_patterns) return; @@ -652,12 +653,40 @@ static void add_pattern_to_hashsets(struct pattern_list *pl, struct path_pattern } if (given->patternlen <= 2 || + *given->pattern == '*' || strstr(given->pattern, "**")) { /* Not a cone pattern. */ warning(_("unrecognized pattern: '%s'"), given->pattern); goto clear_hashmaps; } + prev = given->pattern; + cur = given->pattern + 1; + next = given->pattern + 2; + + while (*cur) { + /* We care about *cur == '*' */ + if (*cur != '*') + goto increment; + + /* But only if *prev != '\\' */ + if (*prev == '\\') + goto increment; + + /* But a trailing '/' then '*' is fine */ + if (*prev == '/' && *next == 0) + goto increment; + + /* Not a cone pattern. */ + warning(_("unrecognized pattern: '%s'"), given->pattern); + goto clear_hashmaps; + + increment: + prev++; + cur++; + next++; + } + if (given->patternlen > 2 && !strcmp(given->pattern + given->patternlen - 2, "/*")) { if (!(given->flags & PATTERN_FLAG_NEGATIVE)) { diff --git a/t/t1091-sparse-checkout-builtin.sh b/t/t1091-sparse-checkout-builtin.sh index 2e57534799..470900f6f4 100755 --- a/t/t1091-sparse-checkout-builtin.sh +++ b/t/t1091-sparse-checkout-builtin.sh @@ -348,4 +348,31 @@ test_expect_success 'pattern-checks: too short' ' check_read_tree_errors repo "a" "disabling cone pattern matching" ' +test_expect_success 'pattern-checks: trailing "*"' ' + cat >repo/.git/info/sparse-checkout <<-\EOF && + /* + !/*/ + /a* + EOF + check_read_tree_errors repo "a" "disabling cone pattern matching" +' + +test_expect_success 'pattern-checks: starting "*"' ' + cat >repo/.git/info/sparse-checkout <<-\EOF && + /* + !/*/ + *eep/ + EOF + check_read_tree_errors repo "a deep" "disabling cone pattern matching" +' + +test_expect_success 'pattern-checks: escaped "*"' ' + cat >repo/.git/info/sparse-checkout <<-\EOF && + /* + !/*/ + /does\*not\*exist/ + EOF + check_read_tree_errors repo "a" "" +' + test_done From patchwork Tue Jan 28 18:26:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver via GitGitGadget X-Patchwork-Id: 11354827 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 820B2112B for ; Tue, 28 Jan 2020 18:27:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 609BF2467E for ; Tue, 28 Jan 2020 18:27:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="goKYHhmq" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727074AbgA1S1B (ORCPT ); Tue, 28 Jan 2020 13:27:01 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:37693 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726276AbgA1S0x (ORCPT ); Tue, 28 Jan 2020 13:26:53 -0500 Received: by mail-wr1-f68.google.com with SMTP id w15so17254551wru.4 for ; Tue, 28 Jan 2020 10:26:52 -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=DxrJYJpH3S8elWu+k2UNvr3+ZBuJrRhBZVScRnz59WY=; b=goKYHhmqBZAEg4PzClUy3ENBUUlz24oEvpiq8a4WX7AMTvMFame5lVnWUjgz3P1YeS JRpCQpmtcXsxVTFmzVQyOKX+ivQ/kIIUC9AuGYhjIFb7IisEoXUP3oxjw1g3F1x3Qgk2 lKoW61vS/IEjXFz7JIaAdn89hsVpS5oWyyLsLWawC8npdsar9BM8nrDyQbZRoxvWAk4Y 6aa6vBodtloXfiyTmmmFYExZjCA9F7r9PJC0jfty/+3zXGoNsKGsjFSmAzpC3KPLMlcw BB0cmmzx1BL972YIPEnobcQybc7jcfO403fjcvm1hYbUfSkRVC6EZl0VgUwIGDNEuzXl nENQ== 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=DxrJYJpH3S8elWu+k2UNvr3+ZBuJrRhBZVScRnz59WY=; b=f5RnrXnxcG6OKMQthSxvwCFi3VQ/Olwlsh8uxj46CG5m5FLVXo5Nzn/DiEoZTvTJb5 6SOGajDVneWNHbdM4KhAFSeLM66M8aOZQfqxLs26ySgJwoTVYYfuBy6zRvaYgNC3Zkh7 iLgOawLO5Z18M94Oelfz/2rh6/q/cdkrV80LHi5KYLA5/NzuUY7pFsQLmAs/sE6xWZ// 3sVm99obWxa+DHnPiSmHTGyUnh2fEA571EOzvfPHr17wUE+XOjwpuX237caOw3lWBsxY DaPCOrrbch48v3nTGeCaZPBfbiJDmXaRGtTInplsa0E6MwvO1LmwsWnapq2Jk7D1UWId mj4w== X-Gm-Message-State: APjAAAWmTQV120O9WDe87DCrgzuXh1Q1ClmOZJQk7Rw+LDD8Wn7JMG6K RppRS4OR/wividfn/QSCC1zBqHee X-Google-Smtp-Source: APXvYqykIngmJj6szF93O9RhyZsviXSzu0M/YJxYPRpNGokwJcPtLdTi59/k7oGrwOTvCG2OP16lmQ== X-Received: by 2002:adf:ce87:: with SMTP id r7mr29812661wrn.245.1580236011390; Tue, 28 Jan 2020 10:26:51 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id c9sm4288635wme.41.2020.01.28.10.26.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Jan 2020 10:26:51 -0800 (PST) Message-Id: <9ea69e90694e53842acd68d3ac85c9a00c4bd343.1580236003.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Derrick Stolee via GitGitGadget" Date: Tue, 28 Jan 2020 18:26:40 +0000 Subject: [PATCH v3 09/12] sparse-checkout: properly match escaped characters Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: me@ttaylorr.com, peff@peff.net, newren@gmail.com, Derrick Stolee , Derrick Stolee Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee In cone mode, the sparse-checkout feature uses hashset containment queries to match paths. Make this algorithm respect escaped asterisk (*) and backslash (\) characters. Create dup_and_filter_pattern() method to convert a pattern by removing escape characters and dropping an optional "/*" at the end. This method is available in dir.h as we will use it in builtin/sparse-checkout.c in a later change. Signed-off-by: Derrick Stolee --- dir.c | 31 +++++++++++++++++++++++++++--- t/t1091-sparse-checkout-builtin.sh | 22 +++++++++++++++++---- 2 files changed, 46 insertions(+), 7 deletions(-) diff --git a/dir.c b/dir.c index 7cb78c8b87..579f274d13 100644 --- a/dir.c +++ b/dir.c @@ -630,6 +630,32 @@ int pl_hashmap_cmp(const void *unused_cmp_data, return strncmp(ee1->pattern, ee2->pattern, min_len); } +static char *dup_and_filter_pattern(const char *pattern) +{ + char *set, *read; + char *result = xstrdup(pattern); + + set = result; + read = result; + + while (*read) { + /* skip escape characters (once) */ + if (*read == '\\') + read++; + + *set = *read; + + set++; + read++; + } + *set = 0; + + if (*(read - 2) == '/' && *(read - 1) == '*') + *(read - 2) = 0; + + return result; +} + static void add_pattern_to_hashsets(struct pattern_list *pl, struct path_pattern *given) { struct pattern_entry *translated; @@ -695,8 +721,7 @@ static void add_pattern_to_hashsets(struct pattern_list *pl, struct path_pattern goto clear_hashmaps; } - truncated = xstrdup(given->pattern); - truncated[given->patternlen - 2] = 0; + truncated = dup_and_filter_pattern(given->pattern); translated = xmalloc(sizeof(struct pattern_entry)); translated->pattern = truncated; @@ -730,7 +755,7 @@ static void add_pattern_to_hashsets(struct pattern_list *pl, struct path_pattern translated = xmalloc(sizeof(struct pattern_entry)); - translated->pattern = xstrdup(given->pattern); + translated->pattern = dup_and_filter_pattern(given->pattern); translated->patternlen = given->patternlen; hashmap_entry_init(&translated->ent, ignore_case ? diff --git a/t/t1091-sparse-checkout-builtin.sh b/t/t1091-sparse-checkout-builtin.sh index 470900f6f4..0a21a5e15d 100755 --- a/t/t1091-sparse-checkout-builtin.sh +++ b/t/t1091-sparse-checkout-builtin.sh @@ -366,13 +366,27 @@ test_expect_success 'pattern-checks: starting "*"' ' check_read_tree_errors repo "a deep" "disabling cone pattern matching" ' -test_expect_success 'pattern-checks: escaped "*"' ' - cat >repo/.git/info/sparse-checkout <<-\EOF && +test_expect_success BSLASHPSPEC 'pattern-checks: escaped "*"' ' + git clone repo escaped && + TREEOID=$(git -C escaped rev-parse HEAD:folder1) && + NEWTREE=$(git -C escaped mktree <<-EOF + $(git -C escaped ls-tree HEAD) + 040000 tree $TREEOID zbad\\dir + 040000 tree $TREEOID zdoes*exist + EOF + ) && + COMMIT=$(git -C escaped commit-tree $NEWTREE -p HEAD) && + git -C escaped reset --hard $COMMIT && + check_files escaped "a deep folder1 folder2 zbad\\dir zdoes*exist" && + git -C escaped sparse-checkout init --cone && + cat >escaped/.git/info/sparse-checkout <<-\EOF && /* !/*/ - /does\*not\*exist/ + /zbad\\dir/ + /zdoes\*not\*exist/ + /zdoes\*exist/ EOF - check_read_tree_errors repo "a" "" + check_read_tree_errors escaped "a zbad\\dir zdoes*exist" ' test_done From patchwork Tue Jan 28 18:26:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver via GitGitGadget X-Patchwork-Id: 11354821 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 6994C112B for ; Tue, 28 Jan 2020 18:26:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3DF0624681 for ; Tue, 28 Jan 2020 18:26:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="YB+W1Kew" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727052AbgA1S06 (ORCPT ); Tue, 28 Jan 2020 13:26:58 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:34093 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726949AbgA1S0y (ORCPT ); Tue, 28 Jan 2020 13:26:54 -0500 Received: by mail-wr1-f68.google.com with SMTP id t2so17212457wrr.1 for ; Tue, 28 Jan 2020 10:26:52 -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=ajb6A/XjF+nig/8pWW4JsKbi+gbolc3gWDFeR5Hxuxc=; b=YB+W1KewotPpGDahZ5E67kvmBsPMW/vJwDIS5aLiZgYIiuLgXmAs8IAO7thslqXXec zHfI0PPilquiikTdopJi/WAaXSyNObKsZj3UoMfUXgWvgTB4NB8Yx1PdcXbknT3FmI+j xETaOQ3jKNZF1MmKkiEoi4ilR85IXjyEhniyfaU/st8Coe0JflPQa/V421MaocH1BeB1 px0DRG3HIrYRTq7pkGM5AosyKcZclXnxJjPp5/M1i2lZPD4escAInZsr2/DI8fR13bWA YhPPk6eAEIQMcbthkZSEw9cLv5x6bFNYPySFimB7Uiwnrlxs2t6p3VXbMaLGmCaqyMqu dFxA== 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=ajb6A/XjF+nig/8pWW4JsKbi+gbolc3gWDFeR5Hxuxc=; b=GRezsEfIsjF8wBTaqbsmTTUDsL+IH8UmwyZPkIn5qmcn9FBsthbCHFiWtbOOfHZs1r vFbpPtJB2jPQot2A05fkSlP49P03U11G1aP2tYMzqQupoGqpaoTAuQEW5KtZL0SBgAur BAPXR4cepFrE0dSZZRynsQpKdxuzdM+ZVuRvWXADyOWvgs/iCW1+P3PGZME5wt4caPxB FpautpMrt6sH3o8Gm6lrOlseVzjdxzRwyXdeavGuxyUJM0R+hIEoK793EYQBnzaVD8ip gmkXKC23RN0c55dSYrqAtFFXfyw60xxWgwQcXNur6foyz2+l440vR9BTmfjeHskl1Nzg mvtA== X-Gm-Message-State: APjAAAWe+O8WAsK4au33pIZ6DkDo1cwUTgakDUQNbiX8XgwMFaRqiT1z wj1YLbfsNBa8uwsrP/GLG+vNOs9S X-Google-Smtp-Source: APXvYqwwicMm9jND+8pImlgMgbCK/f01KXwosbhjBTi/0fQ8tNsIFO9S4hLQTZP/3/Bg8hZIvxylnw== X-Received: by 2002:a5d:4f90:: with SMTP id d16mr30076048wru.395.1580236012091; Tue, 28 Jan 2020 10:26:52 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id s139sm4233810wme.35.2020.01.28.10.26.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Jan 2020 10:26:51 -0800 (PST) Message-Id: In-Reply-To: References: From: "Derrick Stolee via GitGitGadget" Date: Tue, 28 Jan 2020 18:26:41 +0000 Subject: [PATCH v3 10/12] sparse-checkout: write escaped patterns in cone mode Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: me@ttaylorr.com, peff@peff.net, newren@gmail.com, Derrick Stolee , Derrick Stolee Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee If a user somehow creates a directory with an asterisk (*) or backslash (\), then the "git sparse-checkout set" command will struggle to provide the correct pattern in the sparse-checkout file. When not in cone mode, the provided pattern is written directly into the sparse-checkout file. However, in cone mode we expect a list of paths to directories and then we convert those into patterns. Even more specifically, the goal is to always allow the following from the root of a repo: git ls-tree --name-only -d HEAD | git sparse-checkout set --stdin The ls-tree command provides directory names with an unescaped asterisk. It also quotes the directories that contain an escaped backslash. We must remove these quotes, then keep the escaped backslashes. However, there is some care needed for the timing of these escapes. The in-memory pattern list is used to update the working directory before writing the patterns to disk. Thus, we need the command to have the unescaped names in the hashsets for the cone comparisons, then escape the patterns later. Use unquote_c_style() when parsing lines from stdin. Command-line arguments will be parsed as-is, assuming the user can do the correct level of escaping from their environment to match the exact directory names. Signed-off-by: Derrick Stolee --- builtin/sparse-checkout.c | 38 +++++++++++++++++++++++++++--- t/t1091-sparse-checkout-builtin.sh | 21 +++++++++++++++-- 2 files changed, 54 insertions(+), 5 deletions(-) diff --git a/builtin/sparse-checkout.c b/builtin/sparse-checkout.c index 3cee8ab46e..61414fef18 100644 --- a/builtin/sparse-checkout.c +++ b/builtin/sparse-checkout.c @@ -13,6 +13,7 @@ #include "resolve-undo.h" #include "unpack-trees.h" #include "wt-status.h" +#include "quote.h" static const char *empty_base = ""; @@ -140,6 +141,22 @@ static int update_working_directory(struct pattern_list *pl) return result; } +static char *escaped_pattern(char *pattern) +{ + char *p = pattern; + struct strbuf final = STRBUF_INIT; + + while (*p) { + if (*p == '*' || *p == '\\') + strbuf_addch(&final, '\\'); + + strbuf_addch(&final, *p); + p++; + } + + return strbuf_detach(&final, NULL); +} + static void write_cone_to_file(FILE *fp, struct pattern_list *pl) { int i; @@ -164,10 +181,11 @@ static void write_cone_to_file(FILE *fp, struct pattern_list *pl) fprintf(fp, "/*\n!/*/\n"); for (i = 0; i < sl.nr; i++) { - char *pattern = sl.items[i].string; + char *pattern = escaped_pattern(sl.items[i].string); if (strlen(pattern)) fprintf(fp, "%s/\n!%s/*/\n", pattern, pattern); + free(pattern); } string_list_clear(&sl, 0); @@ -185,8 +203,9 @@ static void write_cone_to_file(FILE *fp, struct pattern_list *pl) string_list_remove_duplicates(&sl, 0); for (i = 0; i < sl.nr; i++) { - char *pattern = sl.items[i].string; + char *pattern = escaped_pattern(sl.items[i].string); fprintf(fp, "%s/\n", pattern); + free(pattern); } } @@ -423,8 +442,21 @@ static int sparse_checkout_set(int argc, const char **argv, const char *prefix) pl.use_cone_patterns = 1; if (set_opts.use_stdin) { - while (!strbuf_getline(&line, stdin)) + struct strbuf unquoted = STRBUF_INIT; + while (!strbuf_getline(&line, stdin)) { + if (line.buf[0] == '"') { + strbuf_setlen(&unquoted, 0); + if (unquote_c_style(&unquoted, line.buf, NULL)) + die(_("unable to unquote C-style string '%s'"), + line.buf); + + strbuf_swap(&unquoted, &line); + } + strbuf_to_cone_pattern(&line, &pl); + } + + strbuf_release(&unquoted); } else { for (i = 0; i < argc; i++) { strbuf_setlen(&line, 0); diff --git a/t/t1091-sparse-checkout-builtin.sh b/t/t1091-sparse-checkout-builtin.sh index 0a21a5e15d..459715d541 100755 --- a/t/t1091-sparse-checkout-builtin.sh +++ b/t/t1091-sparse-checkout-builtin.sh @@ -309,6 +309,9 @@ check_read_tree_errors () { REPO=$1 FILES=$2 ERRORS=$3 + git -C $REPO -c core.sparseCheckoutCone=false read-tree -mu HEAD 2>err && + test_must_be_empty err && + check_files $REPO "$FILES" && git -C $REPO read-tree -mu HEAD 2>err && if test -z "$ERRORS" then @@ -379,14 +382,28 @@ test_expect_success BSLASHPSPEC 'pattern-checks: escaped "*"' ' git -C escaped reset --hard $COMMIT && check_files escaped "a deep folder1 folder2 zbad\\dir zdoes*exist" && git -C escaped sparse-checkout init --cone && - cat >escaped/.git/info/sparse-checkout <<-\EOF && + git -C escaped sparse-checkout set zbad\\dir "zdoes*not*exist" "zdoes*exist" && + cat >expect <<-\EOF && /* !/*/ /zbad\\dir/ + /zdoes\*exist/ /zdoes\*not\*exist/ + EOF + test_cmp expect escaped/.git/info/sparse-checkout && + check_read_tree_errors escaped "a zbad\\dir zdoes*exist" && + git -C escaped ls-tree -d --name-only HEAD | git -C escaped sparse-checkout set --stdin && + cat >expect <<-\EOF && + /* + !/*/ + /deep/ + /folder1/ + /folder2/ + /zbad\\dir/ /zdoes\*exist/ EOF - check_read_tree_errors escaped "a zbad\\dir zdoes*exist" + test_cmp expect escaped/.git/info/sparse-checkout && + check_files escaped "a deep folder1 folder2 zbad\\dir zdoes*exist" ' test_done From patchwork Tue Jan 28 18:26:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver via GitGitGadget X-Patchwork-Id: 11354817 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 803B813A4 for ; Tue, 28 Jan 2020 18:26:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5E8D624681 for ; Tue, 28 Jan 2020 18:26:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="a8JSonop" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726996AbgA1S04 (ORCPT ); Tue, 28 Jan 2020 13:26:56 -0500 Received: from mail-wr1-f47.google.com ([209.85.221.47]:41519 "EHLO mail-wr1-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726952AbgA1S0y (ORCPT ); Tue, 28 Jan 2020 13:26:54 -0500 Received: by mail-wr1-f47.google.com with SMTP id c9so17219961wrw.8 for ; Tue, 28 Jan 2020 10:26:53 -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=sEiFWOSlQ42jvfb1L5PRzdSfTmJ8VuICjLeI6WuAohQ=; b=a8JSonopEM+fHml86JpD3yKByrfXijEHUbv/Dii+nZnXjeHdg/gYh+jOBNo65l+MaT uzdAN4T8jac8b8jXm9PpZJvngKOBAMRJn4YyhJwytA1ehodTUl/CSK8DWkzksKIeLTad TY5Q316tSXNrcXLhtamyhzo8srhfyggJOY9nUSAHF9XwgOwE1og70TmavK952EKB1R3G 1SqA6Af0jEasEbJFMxFQJYeCtX8DcAlYNUAUof1GhgnW9sEg4peSKg/uzFehGvXX/vXN LMrXbcSg3KaXTw44+sp2g/mDZJsLTeTWUtyccwmVHpJLmSvCQdP5S67No96qZwL1PHx4 b+lw== 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=sEiFWOSlQ42jvfb1L5PRzdSfTmJ8VuICjLeI6WuAohQ=; b=cNRzdrRpOKVV90h0cMAGGgXnJhVweARZOjE38BUQ81nG3TVHFJDmigqbU9flRc+YRN fXv+PxvzLBIbWu6hq8lpw/73tKmgVK3Ng+EQkwlfTsEke0v5MusXs8/U4w5RL0T8g9bC 0PQILjj7h8E1WrTPkYe4RjrXKuuQgtexNJ6caev3MI4YW9jCgI9lnBkXx+sDoCSvB30Y nybquN9NjOU+tDBOISHiz6Vq1unF+53CLeKH8pbCM9CtHnu4vp35NKAOG06h/Ql6r+MA igZtg1/cLJjdBu5eZwHNj2z+Oi4ycH52LeR0/xL2VI8avcMekvEXHEy6/d3mH8Q3zaYZ F5Mw== X-Gm-Message-State: APjAAAV1XSGvItFI2+pHHhNhJwvxz09q0skjU9+FHXCjL/VlkcuyAg42 DnBMk93qbdhIWTEDyF12N4NYx8Xv X-Google-Smtp-Source: APXvYqxnaggKpQhrw1c85lpWWJdAkKoV3+PXu1rmqj2KofjUfBypRnO0kzZAfnc2Wx1kDNf0CXKxGA== X-Received: by 2002:adf:eb8e:: with SMTP id t14mr29588803wrn.384.1580236012802; Tue, 28 Jan 2020 10:26:52 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id z6sm27924281wrw.36.2020.01.28.10.26.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Jan 2020 10:26:52 -0800 (PST) Message-Id: In-Reply-To: References: From: "Derrick Stolee via GitGitGadget" Date: Tue, 28 Jan 2020 18:26:42 +0000 Subject: [PATCH v3 11/12] sparse-checkout: use C-style quotes in 'list' subcommand Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: me@ttaylorr.com, peff@peff.net, newren@gmail.com, Derrick Stolee , Derrick Stolee Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee When in cone mode, the 'git sparse-checkout list' subcommand lists the directories included in the sparse cone. When these directories contain odd characters, such as a backslash, then we need to use C-style quotes similar to 'git ls-tree'. Signed-off-by: Derrick Stolee --- builtin/sparse-checkout.c | 6 ++++-- t/t1091-sparse-checkout-builtin.sh | 7 +++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/builtin/sparse-checkout.c b/builtin/sparse-checkout.c index 61414fef18..b3c1e97dba 100644 --- a/builtin/sparse-checkout.c +++ b/builtin/sparse-checkout.c @@ -78,8 +78,10 @@ static int sparse_checkout_list(int argc, const char **argv) string_list_sort(&sl); - for (i = 0; i < sl.nr; i++) - printf("%s\n", sl.items[i].string); + for (i = 0; i < sl.nr; i++) { + quote_c_style(sl.items[i].string, NULL, stdout, 0); + printf("\n"); + } return 0; } diff --git a/t/t1091-sparse-checkout-builtin.sh b/t/t1091-sparse-checkout-builtin.sh index 459715d541..7617fb027a 100755 --- a/t/t1091-sparse-checkout-builtin.sh +++ b/t/t1091-sparse-checkout-builtin.sh @@ -392,7 +392,8 @@ test_expect_success BSLASHPSPEC 'pattern-checks: escaped "*"' ' EOF test_cmp expect escaped/.git/info/sparse-checkout && check_read_tree_errors escaped "a zbad\\dir zdoes*exist" && - git -C escaped ls-tree -d --name-only HEAD | git -C escaped sparse-checkout set --stdin && + git -C escaped ls-tree -d --name-only HEAD >list-expect && + git -C escaped sparse-checkout set --stdin expect <<-\EOF && /* !/*/ @@ -403,7 +404,9 @@ test_expect_success BSLASHPSPEC 'pattern-checks: escaped "*"' ' /zdoes\*exist/ EOF test_cmp expect escaped/.git/info/sparse-checkout && - check_files escaped "a deep folder1 folder2 zbad\\dir zdoes*exist" + check_files escaped "a deep folder1 folder2 zbad\\dir zdoes*exist" && + git -C escaped sparse-checkout list >list-actual && + test_cmp list-expect list-actual ' test_done From patchwork Tue Jan 28 18:26:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Arver via GitGitGadget X-Patchwork-Id: 11354819 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 871EE112B for ; Tue, 28 Jan 2020 18:26:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 65CBB24681 for ; Tue, 28 Jan 2020 18:26:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="D4o7JmGB" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727027AbgA1S05 (ORCPT ); Tue, 28 Jan 2020 13:26:57 -0500 Received: from mail-wr1-f66.google.com ([209.85.221.66]:38554 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726962AbgA1S0z (ORCPT ); Tue, 28 Jan 2020 13:26:55 -0500 Received: by mail-wr1-f66.google.com with SMTP id y17so17220369wrh.5 for ; Tue, 28 Jan 2020 10:26:54 -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=7OIxkWhiTuACvbhbr0mgY5mdi0HMxPaJU+8Iq5N0peE=; b=D4o7JmGBs/N4W9aftDNt8RxPNjkdXwV3DAd7hAsHjyfeiIWKAtl3PEb1Tk2+05+dQR ASfu72IIUk5usp0jlv0cPFB3cQFQMKqBC2ZJ6aXHBx8qcAALvd0vQWM+7iSrFUUd/cN2 sI1V2P7e+KwVi9hoyS/f8kk3sWICVpHKUVPc2HZvmhuNTVNhvexfjDpcNK3sQrhOPIOg U1GHr83BiR9d+x9aT+KdfSlkbRr03QisGBPPUQuj6/oxOb/Xz7xXh/EiEhGu2ChjLr0K erMkMK6yJKwIBWOXQjuo/EokrMll06V8Peom+kpsireR4x2kcCWZyhQ677CCI0K1qaU2 hrSQ== 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=7OIxkWhiTuACvbhbr0mgY5mdi0HMxPaJU+8Iq5N0peE=; b=osg1m7Rl4C5QgRfkdHsdnXAljMuvJkUSWazJih795l8cXNgVe+kzMJtUJ2woouBEGL fnEkMRIJBla8tcQzIjjtaLb268sDjQUucvukH7Al+bQ5LiTQ5lcEPxDTzq/qv9gJG4nn ET8p5OreDN3h/M0sFwLtupDNT8Pn+K0g2KwLBdPeiYtplo19dIw+nkTge7yTFkHtyNCD RmpRXzJJ70LyKZAJJNfDCw8OnlU0nBO5Ma6TkcvATHIIGLFgDoPAhSxa5sXB3NlP4kyt BeIDvIe5GZFviX/4KFz9P6rgUXDz4fDLzj74a7Ts58svvFl2l0xPMwxXjawZ4CRWBI4y VScQ== X-Gm-Message-State: APjAAAUi3cY3b33a+uKwkldrp1OppMpHES+sEkR6u8tP1yIlVow1dbd0 6cucPoIWGY2pK5WtapOCv+ZO5E9F X-Google-Smtp-Source: APXvYqwxYEjV3NWa6dYwscMzzkpCLealXTi1YqRVOEcfsRUtR9tuy5su7T3bn8ZqY3wc187gdQ829Q== X-Received: by 2002:a05:6000:f:: with SMTP id h15mr30769982wrx.90.1580236013504; Tue, 28 Jan 2020 10:26:53 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id o129sm4236185wmb.1.2020.01.28.10.26.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Jan 2020 10:26:53 -0800 (PST) Message-Id: <1867746d97c5e3d5d738f12aeb0e1ab739a6b8c1.1580236003.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Derrick Stolee via GitGitGadget" Date: Tue, 28 Jan 2020 18:26:43 +0000 Subject: [PATCH v3 12/12] sparse-checkout: improve docs around 'set' in cone mode Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: me@ttaylorr.com, peff@peff.net, newren@gmail.com, Derrick Stolee , Derrick Stolee Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee The existing documentation does not clarify how the 'set' subcommand changes when core.sparseCheckoutCone is enabled. Correct this by changing some language around the "A/B/C" example. Also include a description of the input format matching the output of 'git ls-tree --name-only'. Helped-by: Jeff King Signed-off-by: Derrick Stolee --- Documentation/git-sparse-checkout.txt | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/Documentation/git-sparse-checkout.txt b/Documentation/git-sparse-checkout.txt index 4834fb434d..0914619881 100644 --- a/Documentation/git-sparse-checkout.txt +++ b/Documentation/git-sparse-checkout.txt @@ -50,6 +50,14 @@ To avoid interfering with other worktrees, it first enables the + When the `--stdin` option is provided, the patterns are read from standard in as a newline-delimited list instead of from the arguments. ++ +When `core.sparseCheckoutCone` is enabled, the input list is considered a +list of directories instead of sparse-checkout patterns. The command writes +patterns to the sparse-checkout file to include all files contained in those +directories (recursively) as well as files that are siblings of ancestor +directories. The input format matches the output of `git ls-tree --name-only`. +This includes interpreting pathnames that begin with a double quote (") as +C-style quoted strings. 'disable':: Disable the `core.sparseCheckout` config setting, and restore the @@ -128,9 +136,12 @@ the following patterns: ---------------- This says "include everything in root, but nothing two levels below root." -If we then add the folder `A/B/C` as a recursive pattern, the folders `A` and -`A/B` are added as parent patterns. The resulting sparse-checkout file is -now + +When in cone mode, the `git sparse-checkout set` subcommand takes a list of +directories instead of a list of sparse-checkout patterns. In this mode, +the command `git sparse-checkout set A/B/C` sets the directory `A/B/C` as +a recursive pattern, the directories `A` and `A/B` are added as parent +patterns. The resulting sparse-checkout file is now ---------------- /*