From patchwork Mon Oct 4 01:11:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12533123 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id ABC59C433F5 for ; Mon, 4 Oct 2021 01:12:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8CE2D60F9C for ; Mon, 4 Oct 2021 01:12:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232047AbhJDBNx (ORCPT ); Sun, 3 Oct 2021 21:13:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38610 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231965AbhJDBNw (ORCPT ); Sun, 3 Oct 2021 21:13:52 -0400 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 765C5C061780 for ; Sun, 3 Oct 2021 18:12:04 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id r10so11120683wra.12 for ; Sun, 03 Oct 2021 18:12:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=vDgAb/pbxKTQjzPx5caxkUI2+Wq7EcLF6LSJOfzTZrQ=; b=NXBmQASEA3AbC4hguQ5xJSVk3aP5mAnZmmvYRUAE+9UPHgLqYzs7aPGTnYs1Vwgiru Ow/veWRGuGc4HELMUL5I960WMqpDJygO5QYZBiSd19d3kfuqLzDZUMXhWKBHGaR2dQcp 54mHU0GlrbvW7ggvxgYBvo/eMLSYWgJYpALcNFGLwvcTzFFCPbMvr/BXjGZb3JQgvv5S CIApibb/90anHiL+kU2+sK1Q1Qsnm3zOzXJr9CkM4MAi/7RAVXawuScR6V2+J4eaAB2X p1VYqtTw1+BhC5ueB1XwZ2V4Q89I3iqs7TNcJr9tdfpWeeXuTeO4c4R/IC4KHQUhO4Qq A0zg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=vDgAb/pbxKTQjzPx5caxkUI2+Wq7EcLF6LSJOfzTZrQ=; b=2/YGdd7d3CQ+ncbXhgoxU+EJ2ERzvbq8r4aP1WpDs1swDBqjAC2Nun9lDbY40Eucu4 /qobymqPXGD/8jMB751dOj6pAS8Qp1I4cX+dX9mJkA+nmCTrMgLCdPOKW9kMN9aDhOIb //zOnbgdUNhS1lGkkiT3F1MvE+sfAJWrJcJ5lqPjlhOKs7m6s5VdSZBDW0Fe48l42i+R CTDgXDBnN88eqe4F5ydlxcIRUVg100OYpmE3nsk8RTCKfCNdDdVDZbGXMhOjntgFZ/xJ DTrk4nt+oRHdie60T64tS+UX3VZLf4mxoQXUh5DVeXOUK3/lXlrxdVn0ivJAcqjEx3FI s1Lw== X-Gm-Message-State: AOAM5318O4gjB6sA5LVolpQFx9EoTYZ/f+IX8rdkqb63v4QXh+urRhy4 +rcGcm/W7rLdCrouJ4l92/PBbNJChBbYag== X-Google-Smtp-Source: ABdhPJwpzcS5kAtqi57KVeTEnC0ojVXK+LkBaSBMKSrCuxTojHaYWeLHcCzT2bJiXiQWJun/219oDA== X-Received: by 2002:adf:ef10:: with SMTP id e16mr10746567wro.46.1633309922772; Sun, 03 Oct 2021 18:12:02 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id q3sm12384317wmc.25.2021.10.03.18.12.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Oct 2021 18:12:02 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Elijah Newren , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= , =?utf-8?q?Martin_=C3=85gren?= , Andrzej Hunt , Jeff King , Fedor Biryukov , Philip Oakley , Phillip Wood , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= Subject: [RFC PATCH v4 01/10] t2500: add various tests for nuking untracked files Date: Mon, 4 Oct 2021 03:11:50 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.1404.g83021034c5d In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren Noting that unpack_trees treats reset=1 & update=1 as license to nuke untracked files, I looked for code paths that use this combination and tried to generate testcases which demonstrated unintentional loss of untracked files and directories. I found several. I also include testcases for `git reset --{hard,merge,keep}`. A hard reset is perhaps the most direct test of unpack_tree's reset=1 behavior, but we cannot make `git reset --hard` preserve untracked files without some migration work. Also, the two commands `checkout --force` (because of the --force) and `read-tree --reset` (because it's plumbing and we need to keep it backward compatible) were left out as we expect those to continue removing untracked files and directories. Signed-off-by: Elijah Newren Signed-off-by: Ævar Arnfjörð Bjarmason --- t/t2500-untracked-overwriting.sh | 244 +++++++++++++++++++++++++++++++ 1 file changed, 244 insertions(+) create mode 100755 t/t2500-untracked-overwriting.sh diff --git a/t/t2500-untracked-overwriting.sh b/t/t2500-untracked-overwriting.sh new file mode 100755 index 00000000000..2412d121ea8 --- /dev/null +++ b/t/t2500-untracked-overwriting.sh @@ -0,0 +1,244 @@ +#!/bin/sh + +test_description='Test handling of overwriting untracked files' + +. ./test-lib.sh + +test_setup_reset () { + git init reset_$1 && + ( + cd reset_$1 && + test_commit init && + + git branch stable && + git branch work && + + git checkout work && + test_commit foo && + + git checkout stable + ) +} + +test_expect_success 'reset --hard will nuke untracked files/dirs' ' + test_setup_reset hard && + ( + cd reset_hard && + git ls-tree -r stable && + git log --all --name-status --oneline && + git ls-tree -r work && + + mkdir foo.t && + echo precious >foo.t/file && + echo foo >expect && + + git reset --hard work && + + # check that untracked directory foo.t/ was nuked + test_path_is_file foo.t && + test_cmp expect foo.t + ) +' + +test_expect_success 'reset --merge will preserve untracked files/dirs' ' + test_setup_reset merge && + ( + cd reset_merge && + + mkdir foo.t && + echo precious >foo.t/file && + cp foo.t/file expect && + + test_must_fail git reset --merge work 2>error && + test_cmp expect foo.t/file && + grep "Updating .foo.t. would lose untracked files" error + ) +' + +test_expect_success 'reset --keep will preserve untracked files/dirs' ' + test_setup_reset keep && + ( + cd reset_keep && + + mkdir foo.t && + echo precious >foo.t/file && + cp foo.t/file expect && + + test_must_fail git reset --merge work 2>error && + test_cmp expect foo.t/file && + grep "Updating.*foo.t.*would lose untracked files" error + ) +' + +test_setup_checkout_m () { + git init checkout && + ( + cd checkout && + test_commit init && + + test_write_lines file has some >filler && + git add filler && + git commit -m filler && + + git branch stable && + + git switch -c work && + echo stuff >notes.txt && + test_write_lines file has some words >filler && + git add notes.txt filler && + git commit -m filler && + + git checkout stable + ) +} + +test_expect_failure 'checkout -m does not nuke untracked file' ' + test_setup_checkout_m && + ( + cd checkout && + + # Tweak filler + test_write_lines this file has some >filler && + # Make an untracked file, save its contents in "expect" + echo precious >notes.txt && + cp notes.txt expect && + + test_must_fail git checkout -m work && + test_cmp expect notes.txt + ) +' + +test_setup_sequencing () { + git init sequencing_$1 && + ( + cd sequencing_$1 && + test_commit init && + + test_write_lines this file has some words >filler && + git add filler && + git commit -m filler && + + mkdir -p foo/bar && + test_commit foo/bar/baz && + + git branch simple && + git branch fooey && + + git checkout fooey && + git rm foo/bar/baz.t && + echo stuff >>filler && + git add -u && + git commit -m "changes" && + + git checkout simple && + echo items >>filler && + echo newstuff >>newfile && + git add filler newfile && + git commit -m another + ) +} + +test_expect_failure 'git rebase --abort and untracked files' ' + test_setup_sequencing rebase_abort_and_untracked && + ( + cd sequencing_rebase_abort_and_untracked && + git checkout fooey && + test_must_fail git rebase simple && + + cat init.t && + git rm init.t && + echo precious >init.t && + cp init.t expect && + git status --porcelain && + test_must_fail git rebase --abort && + test_cmp expect init.t + ) +' + +test_expect_failure 'git rebase fast forwarding and untracked files' ' + test_setup_sequencing rebase_fast_forward_and_untracked && + ( + cd sequencing_rebase_fast_forward_and_untracked && + git checkout init && + echo precious >filler && + cp filler expect && + test_must_fail git rebase init simple && + test_cmp expect filler + ) +' + +test_expect_failure 'git rebase --autostash and untracked files' ' + test_setup_sequencing rebase_autostash_and_untracked && + ( + cd sequencing_rebase_autostash_and_untracked && + git checkout simple && + git rm filler && + mkdir filler && + echo precious >filler/file && + cp filler/file expect && + git rebase --autostash init && + test_path_is_file filler/file + ) +' + +test_expect_failure 'git stash and untracked files' ' + test_setup_sequencing stash_and_untracked_files && + ( + cd sequencing_stash_and_untracked_files && + git checkout simple && + git rm filler && + mkdir filler && + echo precious >filler/file && + cp filler/file expect && + git status --porcelain && + git stash push && + git status --porcelain && + test_path_is_file filler/file + ) +' + +test_expect_failure 'git am --abort and untracked dir vs. unmerged file' ' + test_setup_sequencing am_abort_and_untracked && + ( + cd sequencing_am_abort_and_untracked && + git format-patch -1 --stdout fooey >changes.mbox && + test_must_fail git am --3way changes.mbox && + + # Delete the conflicted file; we will stage and commit it later + rm filler && + + # Put an unrelated untracked directory there + mkdir filler && + echo foo >filler/file1 && + echo bar >filler/file2 && + + test_must_fail git am --abort 2>errors && + test_path_is_dir filler && + grep "Updating .filler. would lose untracked files in it" errors + ) +' + +test_expect_failure 'git am --skip and untracked dir vs deleted file' ' + test_setup_sequencing am_skip_and_untracked && + ( + cd sequencing_am_skip_and_untracked && + git checkout fooey && + git format-patch -1 --stdout simple >changes.mbox && + test_must_fail git am --3way changes.mbox && + + # Delete newfile + rm newfile && + + # Put an unrelated untracked directory there + mkdir newfile && + echo foo >newfile/file1 && + echo bar >newfile/file2 && + + # Change our mind about resolutions, just skip this patch + test_must_fail git am --skip 2>errors && + test_path_is_dir newfile && + grep "Updating .newfile. would lose untracked files in it" errors + ) +' + +test_done From patchwork Mon Oct 4 01:11:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12533127 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4AC0FC433EF for ; Mon, 4 Oct 2021 01:12:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3533D6115B for ; Mon, 4 Oct 2021 01:12:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232055AbhJDBN5 (ORCPT ); Sun, 3 Oct 2021 21:13:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38614 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232038AbhJDBNx (ORCPT ); Sun, 3 Oct 2021 21:13:53 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 41CDFC061781 for ; Sun, 3 Oct 2021 18:12:05 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id v17so27595556wrv.9 for ; Sun, 03 Oct 2021 18:12:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=M1O9Rp+V8gQl7f7mgK/Le+vmEfRBjxOigDmK638lnMk=; b=eZpOn19dAKkzWKzWKRbLObDoQiY1Ga/ydhr470NgeLytHm4E+qWb/1n+yInnL/G1yQ XVgn7y0hY2vGwe+cRnviArzl72u4w0oTZg2hg3DcrWirQB+BM1juf3NJmYajpARnJ/fd P/tvlUAxb9iJBOUr96lJkzF7yCLvgV9Z4XXR1s/1d8f6pMLJdYnrcDFK8QSaB+yYsdnK NpkJKbFI4ob9l6TTVVtu5c5Tj8jiSvmSa8e3/KCMMaCk5YQrJt4rxArxiTpkjt6hQgYA X30EqtBaCeVzwJm+0gRjcjpQVz4JCBqI9fVabFJcVFJS7p8ojweM1rHSXWpSz7ECTeHn N6OA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=M1O9Rp+V8gQl7f7mgK/Le+vmEfRBjxOigDmK638lnMk=; b=WfkJOCv2/B1Mbr3BxexoojvBHrL5FiAh79RSEInBSpsE8tT9engdmLtEvZJyCMQcUl IZQ6ZHCEXdx//uxdYksquf2vb+bOsIT3KbmwpKvf8gq9SoFAEKElOoLLOge0f9VJXRFP fdQCdGYUFzihW23qh2iZxGi65AHb703UY/dYl6c08BMugxXKUfuQ0xcBpRHQziNZZYLQ /F2JIRVfRxzx1Y7l3YEVMIB2dDVd5dDwGRwWcKHApJSQJcgh+y81eF/d2r7Yz6SuylRg FM+Xw/B7wU1iXt6O2yzEy2IqZ+6IDtSIrPJUdy8iMpqkLeAtqopZ3soN8MPtqSzUWzc9 qkrQ== X-Gm-Message-State: AOAM532+K0dbdsyJvfiVWKH/xxa6hauCfCLfYESEL2C4haGYfV5YanB6 r3Q1+3R+tG4inT4khiXKLZ73KuRqcaAAGw== X-Google-Smtp-Source: ABdhPJyKpt7+Oa/PpA/3AsMMfo0KHCfjcmNTZE6vW7QnL87yxBzDRofwkA8pWb0KYSXCKithcI0+2A== X-Received: by 2002:adf:b350:: with SMTP id k16mr11036330wrd.368.1633309923571; Sun, 03 Oct 2021 18:12:03 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id q3sm12384317wmc.25.2021.10.03.18.12.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Oct 2021 18:12:03 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Elijah Newren , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= , =?utf-8?q?Martin_=C3=85gren?= , Andrzej Hunt , Jeff King , Fedor Biryukov , Philip Oakley , Phillip Wood , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= Subject: [RFC PATCH v4 02/10] read-tree, merge-recursive: overwrite ignored files by default Date: Mon, 4 Oct 2021 03:11:51 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.1404.g83021034c5d In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren This fixes a long-standing patchwork of ignored files handling in read-tree and merge-recursive, called out and suggested by Junio long ago. Quoting from commit dcf0c16ef1 ("core.excludesfile clean-up" 2007-11-16): git-read-tree takes --exclude-per-directory=, not because the flexibility was needed. Again, this was because the option predates the standardization of the ignore files. ... On the other hand, I think it makes perfect sense to fix git-read-tree, git-merge-recursive and git-clean to follow the same rule as other commands. I do not think of a valid use case to give an exclude-per-directory that is nonstandard to read-tree command, outside a "negative" test in the t1004 test script. This patch is the first step to untangle this mess. The next step would be to teach read-tree, merge-recursive and clean (in C) to use setup_standard_excludes(). History shows each of these were partially or fully fixed: * clean was taught the new trick in 1617adc7a0 ("Teach git clean to use setup_standard_excludes()", 2007-11-14). * read-tree was primarily used by checkout & merge scripts. checkout and merge later became builtins and were both fixed to use the new setup_standard_excludes() handling in fc001b526c ("checkout,merge: loosen overwriting untracked file check based on info/exclude", 2011-11-27). So the primary users were fixed, though read-tree itself was not. * merge-recursive has now been replaced as the default merge backend by merge-ort. merge-ort fixed this by using setup_standard_excludes() starting early in its implementation; see commit 6681ce5cf6 ("merge-ort: add implementation of checkout()", 2020-12-13), largely due to its design depending on checkout() and thus being influenced by the checkout code. However, merge-recursive itself was not fixed here, in part because its design meant it had difficulty differentiating between untracked files, ignored files, leftover tracked files that haven't been removed yet due to order of processing files, and files written by itself due to collisions). Make the conversion more complete by now handling read-tree and handling at least the unpack_trees() portion of merge-recursive. While merge-recursive is on its way out, fixing the unpack_trees() portion is easy and facilitates some of the later changes in this series. Note that fixing read-tree makes the --exclude-per-directory option to read-tree useless, so we remove it from the documentation (though we continue to accept it if passed). The read-tree changes happen to fix a bug in t1013. Signed-off-by: Elijah Newren Signed-off-by: Ævar Arnfjörð Bjarmason --- Documentation/git-read-tree.txt | 18 +----------------- builtin/read-tree.c | 21 +++++++++------------ merge-recursive.c | 5 ++++- t/t1013-read-tree-submodule.sh | 1 - 4 files changed, 14 insertions(+), 31 deletions(-) diff --git a/Documentation/git-read-tree.txt b/Documentation/git-read-tree.txt index 5fa8bab64c2..0222a27c5af 100644 --- a/Documentation/git-read-tree.txt +++ b/Documentation/git-read-tree.txt @@ -10,8 +10,7 @@ SYNOPSIS -------- [verse] 'git read-tree' [[-m [--trivial] [--aggressive] | --reset | --prefix=] - [-u [--exclude-per-directory=] | -i]] - [--index-output=] [--no-sparse-checkout] + [-u | -i]] [--index-output=] [--no-sparse-checkout] (--empty | [ []]) @@ -88,21 +87,6 @@ OPTIONS The command will refuse to overwrite entries that already existed in the original index file. ---exclude-per-directory=:: - When running the command with `-u` and `-m` options, the - merge result may need to overwrite paths that are not - tracked in the current branch. The command usually - refuses to proceed with the merge to avoid losing such a - path. However this safety valve sometimes gets in the - way. For example, it often happens that the other - branch added a file that used to be a generated file in - your branch, and the safety valve triggers when you try - to switch to that branch after you ran `make` but before - running `make clean` to remove the generated file. This - option tells the command to read per-directory exclude - file (usually '.gitignore') and allows such an untracked - but explicitly ignored file to be overwritten. - --index-output=:: Instead of writing the results out to `$GIT_INDEX_FILE`, write the resulting index in the named file. While the diff --git a/builtin/read-tree.c b/builtin/read-tree.c index 8f1b8a7e74c..d0f88bbf3e3 100644 --- a/builtin/read-tree.c +++ b/builtin/read-tree.c @@ -38,7 +38,7 @@ static int list_tree(struct object_id *oid) } static const char * const read_tree_usage[] = { - N_("git read-tree [(-m [--trivial] [--aggressive] | --reset | --prefix=) [-u [--exclude-per-directory=] | -i]] [--no-sparse-checkout] [--index-output=] (--empty | [ []])"), + N_("git read-tree [(-m [--trivial] [--aggressive] | --reset | --prefix=) [-u | -i]] [--no-sparse-checkout] [--index-output=] (--empty | [ []])"), NULL }; @@ -59,15 +59,10 @@ static int exclude_per_directory_cb(const struct option *opt, const char *arg, opts = (struct unpack_trees_options *)opt->value; - if (opts->dir.exclude_per_dir) - die("more than one --exclude-per-directory given."); - - opts->dir.flags |= DIR_SHOW_IGNORED; - opts->dir.exclude_per_dir = arg; - /* We do not need to nor want to do read-directory - * here; we are merely interested in reusing the - * per directory ignore stack mechanism. - */ + if (!opts->update) + die("--exclude-per-directory is meaningless unless -u"); + if (strcmp(arg, ".gitignore")) + die("--exclude-per-directory argument must be .gitignore"); return 0; } @@ -206,8 +201,10 @@ int cmd_read_tree(int argc, const char **argv, const char *cmd_prefix) if ((opts.update || opts.index_only) && !opts.merge) die("%s is meaningless without -m, --reset, or --prefix", opts.update ? "-u" : "-i"); - if ((opts.dir.exclude_per_dir && !opts.update)) - die("--exclude-per-directory is meaningless unless -u"); + if (opts.update && !opts.reset) { + opts.dir.flags |= DIR_SHOW_IGNORED; + setup_standard_excludes(&opts.dir); + } if (opts.merge && !opts.index_only) setup_work_tree(); diff --git a/merge-recursive.c b/merge-recursive.c index 316cb2ca907..a4131b8837b 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -408,8 +408,11 @@ static int unpack_trees_start(struct merge_options *opt, unpack_trees_options_init(&opt->priv->unpack_opts); if (opt->priv->call_depth) opt->priv->unpack_opts.index_only = 1; - else + else { opt->priv->unpack_opts.update = 1; + opt->priv->unpack_opts.dir.flags |= DIR_SHOW_IGNORED; + setup_standard_excludes(&opt->priv->unpack_opts.dir); + } opt->priv->unpack_opts.merge = 1; opt->priv->unpack_opts.head_idx = 2; opt->priv->unpack_opts.fn = threeway_merge; diff --git a/t/t1013-read-tree-submodule.sh b/t/t1013-read-tree-submodule.sh index b6df7444c05..bfc90d4cf27 100755 --- a/t/t1013-read-tree-submodule.sh +++ b/t/t1013-read-tree-submodule.sh @@ -6,7 +6,6 @@ test_description='read-tree can handle submodules' . "$TEST_DIRECTORY"/lib-submodule-update.sh KNOWN_FAILURE_DIRECTORY_SUBMODULE_CONFLICTS=1 -KNOWN_FAILURE_SUBMODULE_OVERWRITE_IGNORED_UNTRACKED=1 test_submodule_switch_recursing_with_args "read-tree -u -m" From patchwork Mon Oct 4 01:11:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12533129 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DE357C433FE for ; Mon, 4 Oct 2021 01:12:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B75A36115B for ; Mon, 4 Oct 2021 01:12:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232075AbhJDBN7 (ORCPT ); Sun, 3 Oct 2021 21:13:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38620 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232052AbhJDBNz (ORCPT ); Sun, 3 Oct 2021 21:13:55 -0400 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3A4BFC0613EC for ; Sun, 3 Oct 2021 18:12:06 -0700 (PDT) Received: by mail-wr1-x429.google.com with SMTP id v25so16915750wra.2 for ; Sun, 03 Oct 2021 18:12:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=DYiAc/m4McpM45Boa52PfqupNuEfO2mMHAaUMbKBPFE=; b=kaz4i+9QOYvrM9vpl1ghoPOOyyAWp7obR07KC1Mg+JHXnFwe/rj2oAn5Ywel0LEZrQ mDyH0exL9Vcy3Im3hralHL95Lpo2dbAD/ns2Y7rDFpdSEqT3OorvXEV93Xwt9K9f5YUh +aG47nRJ2wTyjjzY1cC70GWtRnSnQN6bXfGO+ChYChFYV3zKATjE/20snzHoxGXdSaZK SFjTRXiLIJE8l0j/KF6VTwHWX1TTjyYu2MKgjxX6N8/ei8ItUbyCmsKGj4ZQzPHR5F17 xgJOfolksnia+na1Ld/kVBKLGLVmvsgWEoYvuzQPQZBq7ANoSox1idJIbNBnt3BdNJdj jULw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=DYiAc/m4McpM45Boa52PfqupNuEfO2mMHAaUMbKBPFE=; b=Einr/YfaVOBpnNTieJRdhIf6gSS+gnelpcekwfmfSFiEovLponR1Nig0drkPDEFiDG Pk3xYkBpODpByRak3cWqwhCtPCoCW4WRKcyvcJZ2wOSfaApnxa4tLAQtM3YqDEyQ/gUo 0dpFtMJSwVJZe2UESz4gZOASuKt7Yhxb9pS2+kz5insfL0JFp3xEtu3hgROWCFIJlS00 OK3TNu+etHDa1jzGr6vrvQynEY3rEwyfvw5BdcBE4Tp0pBXDL+15JvX3MX3oFkMO3QFu HU3+RgB2269lZkH/k7M106fXFchHZeIUP1sWSN0IgSGPOs5EmkCPIgDifRd+hsJ8Cyzr Psqg== X-Gm-Message-State: AOAM533m8aQI8uTmc+PvtX5H02dQLz8n9Eh5/2qJLGLNstwbs+A4YHPR LGMFgD3DG7CRt0bqBUgKq0bODoDioQ6RDA== X-Google-Smtp-Source: ABdhPJxCubL2ielGYD+Tgq2hLCSVearPnZhzBKXlIrhf6YlK8ecc/RPg/VxeVuggtPR0S0A7zyJDDg== X-Received: by 2002:a5d:4481:: with SMTP id j1mr11333818wrq.6.1633309924526; Sun, 03 Oct 2021 18:12:04 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id q3sm12384317wmc.25.2021.10.03.18.12.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Oct 2021 18:12:03 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Elijah Newren , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= , =?utf-8?q?Martin_=C3=85gren?= , Andrzej Hunt , Jeff King , Fedor Biryukov , Philip Oakley , Phillip Wood , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= Subject: [RFC PATCH v4 03/10] unpack-trees: introduce preserve_ignored to unpack_trees_options Date: Mon, 4 Oct 2021 03:11:52 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.1404.g83021034c5d In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren Currently, every caller of unpack_trees() that wants to ensure ignored files are overwritten by default needs to: * flip the DIR_SHOW_IGNORED flag in unpack_trees_options.dir.flags * call setup_standard_excludes(&unpack_trees_options.dir) Avoid that boilerplate by introducing a new boolean value where the default value (0) does what we want so that new callers of unpack_trees() automatically get the appropriate behavior. And move all the handling of unpack_trees_options.dir into unpack_trees() itself. While preserve_ignored = 0 is the behavior we feel is the appropriate default, we defer fixing commands to use the appropriate default until a later commit. So, this commit introduces several locations where we manually set preserve_ignored=1. This makes it clear where code paths were previously preserving ignored files when they should not have been; a future commit will flip these to instead use a value of 0 to get the behavior we want. Signed-off-by: Elijah Newren Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/am.c | 3 +++ builtin/checkout.c | 6 ++---- builtin/clone.c | 2 ++ builtin/merge.c | 2 ++ builtin/read-tree.c | 7 +++---- builtin/reset.c | 2 ++ builtin/stash.c | 3 +++ merge-ort.c | 5 +---- merge-recursive.c | 4 ++-- merge.c | 6 +----- reset.c | 2 ++ sequencer.c | 2 ++ unpack-trees.c | 5 +++++ unpack-trees.h | 1 + 14 files changed, 31 insertions(+), 19 deletions(-) diff --git a/builtin/am.c b/builtin/am.c index 4d4bb473c0f..3c6efe2a46b 100644 --- a/builtin/am.c +++ b/builtin/am.c @@ -1918,6 +1918,9 @@ static int fast_forward_to(struct tree *head, struct tree *remote, int reset) opts.update = 1; opts.merge = 1; opts.reset = reset; + if (!reset) + /* FIXME: Default should be to remove ignored files */ + opts.preserve_ignored = 1; opts.fn = twoway_merge; init_tree_desc(&t[0], head->buffer, head->size); init_tree_desc(&t[1], remote->buffer, remote->size); diff --git a/builtin/checkout.c b/builtin/checkout.c index fd76b504861..0c5187025c5 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -648,6 +648,7 @@ static int reset_tree(struct tree *tree, const struct checkout_opts *o, opts.skip_unmerged = !worktree; opts.reset = 1; opts.merge = 1; + opts.preserve_ignored = 0; opts.fn = oneway_merge; opts.verbose_update = o->show_progress; opts.src_index = &the_index; @@ -749,10 +750,7 @@ static int merge_working_tree(const struct checkout_opts *opts, new_branch_info->commit ? &new_branch_info->commit->object.oid : &new_branch_info->oid, NULL); - if (opts->overwrite_ignore) { - topts.dir.flags |= DIR_SHOW_IGNORED; - setup_standard_excludes(&topts.dir); - } + topts.preserve_ignored = !opts->overwrite_ignore; tree = parse_tree_indirect(old_branch_info->commit ? &old_branch_info->commit->object.oid : the_hash_algo->empty_tree); diff --git a/builtin/clone.c b/builtin/clone.c index df3bb9a7884..e76c38e4e81 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -686,6 +686,8 @@ static int checkout(int submodule_progress) opts.update = 1; opts.merge = 1; opts.clone = 1; + /* FIXME: Default should be to remove ignored files */ + opts.preserve_ignored = 1; opts.fn = oneway_merge; opts.verbose_update = (option_verbosity >= 0); opts.src_index = &the_index; diff --git a/builtin/merge.c b/builtin/merge.c index 28089e2c5ed..55aac869e5a 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -680,6 +680,8 @@ static int read_tree_trivial(struct object_id *common, struct object_id *head, opts.verbose_update = 1; opts.trivial_merges_only = 1; opts.merge = 1; + /* FIXME: Default should be to remove ignored files */ + opts.preserve_ignored = 1; trees[nr_trees] = parse_tree_indirect(common); if (!trees[nr_trees++]) return -1; diff --git a/builtin/read-tree.c b/builtin/read-tree.c index d0f88bbf3e3..7f3c987b126 100644 --- a/builtin/read-tree.c +++ b/builtin/read-tree.c @@ -201,10 +201,9 @@ int cmd_read_tree(int argc, const char **argv, const char *cmd_prefix) if ((opts.update || opts.index_only) && !opts.merge) die("%s is meaningless without -m, --reset, or --prefix", opts.update ? "-u" : "-i"); - if (opts.update && !opts.reset) { - opts.dir.flags |= DIR_SHOW_IGNORED; - setup_standard_excludes(&opts.dir); - } + if (opts.update && !opts.reset) + opts.preserve_ignored = 0; + /* otherwise, opts.preserve_ignored is irrelevant */ if (opts.merge && !opts.index_only) setup_work_tree(); diff --git a/builtin/reset.c b/builtin/reset.c index 713d084c3eb..73477239146 100644 --- a/builtin/reset.c +++ b/builtin/reset.c @@ -66,6 +66,8 @@ static int reset_index(const char *ref, const struct object_id *oid, int reset_t case KEEP: case MERGE: opts.update = 1; + /* FIXME: Default should be to remove ignored files */ + opts.preserve_ignored = 1; break; case HARD: opts.update = 1; diff --git a/builtin/stash.c b/builtin/stash.c index be6ecb1ae11..78492013529 100644 --- a/builtin/stash.c +++ b/builtin/stash.c @@ -257,6 +257,9 @@ static int reset_tree(struct object_id *i_tree, int update, int reset) opts.merge = 1; opts.reset = reset; opts.update = update; + if (update && !reset) + /* FIXME: Default should be to remove ignored files */ + opts.preserve_ignored = 1; opts.fn = oneway_merge; if (unpack_trees(nr_trees, t, &opts)) { diff --git a/merge-ort.c b/merge-ort.c index 0a5937364c9..e5620bda212 100644 --- a/merge-ort.c +++ b/merge-ort.c @@ -4044,10 +4044,7 @@ static int checkout(struct merge_options *opt, unpack_opts.quiet = 0; /* FIXME: sequencer might want quiet? */ unpack_opts.verbose_update = (opt->verbosity > 2); unpack_opts.fn = twoway_merge; - if (1/* FIXME: opts->overwrite_ignore*/) { - unpack_opts.dir.flags |= DIR_SHOW_IGNORED; - setup_standard_excludes(&unpack_opts.dir); - } + unpack_opts.preserve_ignored = 0; /* FIXME: !opts->overwrite_ignore*/ parse_tree(prev); init_tree_desc(&trees[0], prev->buffer, prev->size); parse_tree(next); diff --git a/merge-recursive.c b/merge-recursive.c index a4131b8837b..5c6b95a79c0 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -410,8 +410,8 @@ static int unpack_trees_start(struct merge_options *opt, opt->priv->unpack_opts.index_only = 1; else { opt->priv->unpack_opts.update = 1; - opt->priv->unpack_opts.dir.flags |= DIR_SHOW_IGNORED; - setup_standard_excludes(&opt->priv->unpack_opts.dir); + /* FIXME: should only do this if !overwrite_ignore */ + opt->priv->unpack_opts.preserve_ignored = 0; } opt->priv->unpack_opts.merge = 1; opt->priv->unpack_opts.head_idx = 2; diff --git a/merge.c b/merge.c index 2e3714ccaa0..e1f3165e407 100644 --- a/merge.c +++ b/merge.c @@ -79,11 +79,7 @@ int checkout_fast_forward(struct repository *r, init_tree_desc(t+i, trees[i]->buffer, trees[i]->size); } - if (overwrite_ignore) { - opts.dir.flags |= DIR_SHOW_IGNORED; - setup_standard_excludes(&opts.dir); - } - + opts.preserve_ignored = !overwrite_ignore; opts.head_idx = 1; opts.src_index = r->index; opts.dst_index = r->index; diff --git a/reset.c b/reset.c index f4bf3fbfac0..cd344f47f13 100644 --- a/reset.c +++ b/reset.c @@ -56,6 +56,8 @@ int reset_head(struct repository *r, struct object_id *oid, const char *action, unpack_tree_opts.fn = reset_hard ? oneway_merge : twoway_merge; unpack_tree_opts.update = 1; unpack_tree_opts.merge = 1; + /* FIXME: Default should be to remove ignored files */ + unpack_tree_opts.preserve_ignored = 1; init_checkout_metadata(&unpack_tree_opts.meta, switch_to_branch, oid, NULL); if (!detach_head) unpack_tree_opts.reset = 1; diff --git a/sequencer.c b/sequencer.c index abd85b6c562..669ea15944c 100644 --- a/sequencer.c +++ b/sequencer.c @@ -3698,6 +3698,8 @@ static int do_reset(struct repository *r, unpack_tree_opts.fn = oneway_merge; unpack_tree_opts.merge = 1; unpack_tree_opts.update = 1; + /* FIXME: Default should be to remove ignored files */ + unpack_tree_opts.preserve_ignored = 1; init_checkout_metadata(&unpack_tree_opts.meta, name, &oid, NULL); if (repo_read_index_unmerged(r)) { diff --git a/unpack-trees.c b/unpack-trees.c index 260e7ec5bb4..02bc999c6c3 100644 --- a/unpack-trees.c +++ b/unpack-trees.c @@ -1711,6 +1711,11 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options ensure_full_index(o->dst_index); } + if (!o->preserve_ignored) { + o->dir.flags |= DIR_SHOW_IGNORED; + setup_standard_excludes(&o->dir); + } + if (!core_apply_sparse_checkout || !o->update) o->skip_sparse_checkout = 1; if (!o->skip_sparse_checkout && !o->pl) { diff --git a/unpack-trees.h b/unpack-trees.h index a8d1f083b33..65a8d99d4ef 100644 --- a/unpack-trees.h +++ b/unpack-trees.h @@ -52,6 +52,7 @@ struct unpack_trees_options { unsigned int reset, merge, update, + preserve_ignored, clone, index_only, nontrivial_merge, From patchwork Mon Oct 4 01:11:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12533131 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EC9DCC433EF for ; Mon, 4 Oct 2021 01:12:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C92B46115C for ; Mon, 4 Oct 2021 01:12:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232091AbhJDBOA (ORCPT ); Sun, 3 Oct 2021 21:14:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38624 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232053AbhJDBNz (ORCPT ); Sun, 3 Oct 2021 21:13:55 -0400 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 42DA6C061780 for ; Sun, 3 Oct 2021 18:12:07 -0700 (PDT) Received: by mail-wm1-x32b.google.com with SMTP id z184-20020a1c7ec1000000b003065f0bc631so17960461wmc.0 for ; Sun, 03 Oct 2021 18:12:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=p48KRnpOfchQnOG9X0rMF/mHh+ir0F6XO5Uhimc1rMQ=; b=mpfXpOit++u1zTb80HYa3P9nNaoWR+708jny3TPEVnPJLvVBoDdqOH9KtyW+gvhKUA 0J8CEy4VeptXibC9CroYD50vH86uDwEQALyrj67+zL6KZ0EbU2Flb9q8PWagXtmrrDSV rM90guBv3L4XXvaW1530enDEeV66+iDWINVF4vRKBSy41LrMbBiu77syCWy1lbuXZ5Lo wWFVIgQGhR4+GjTZF4SDLnzWhQaj2F3BrplSdxtQAgZJKxUMhzc4puJU/ljJpqLwyOJX isVXQ+TaFGzvK8dZJoRCxEnahW60kzd5Yl6SLrBlvgDv7d2OyTumC3zuDDtbWOUb7LQP UE+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=p48KRnpOfchQnOG9X0rMF/mHh+ir0F6XO5Uhimc1rMQ=; b=79Yt7Zlmz9GZ8jtiCI7oHu+Ch3EsKHap7Nhel+2NYSaw9n7C1zOFdB7x8l4cULz/Ar 0aleNU1QaeVVnImN2DpH8socB9THycqQDewAyrAVJCpgxbRPm1NOiQwXGflZenlOdK4Z 8GLBGYD2vDz6JvzV+skZpoHFTC2nJtMBatRxU+p1McKImArSrfEDwLTMJqG4OdTMSeDa mPqJ7U4S8Xg+50iZ9Mh/nEue9YgzamRNhYp3fmvIe0p4N4Tw7lznQVg/dK9p+/vg9elx dR4dgFrkx0F0sJyrwKuYf7pY6G0dnCiqcY1MlicOhv/pcicJnsgALPP95kAQ/oIdi+G+ aMkw== X-Gm-Message-State: AOAM530vvqbuESrpbIVTjxN6WIKn0ufxrzEKUqkXrpK+gy48CFHpURIN 2g9LQs44KXb54GNO2l/wrmE2lkzghFhPEQ== X-Google-Smtp-Source: ABdhPJwtF8aWxusiREVsGwcdpwenQeglba029GIUvRa/NJYRrphWPr2sA5ODB2i3bY1c2W1wlDVtGQ== X-Received: by 2002:a05:600c:1ca8:: with SMTP id k40mr15710389wms.27.1633309925528; Sun, 03 Oct 2021 18:12:05 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id q3sm12384317wmc.25.2021.10.03.18.12.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Oct 2021 18:12:05 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Elijah Newren , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= , =?utf-8?q?Martin_=C3=85gren?= , Andrzej Hunt , Jeff King , Fedor Biryukov , Philip Oakley , Phillip Wood , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= Subject: [RFC PATCH v4 04/10] unpack-trees: rename "dir" to "private_dir" Date: Mon, 4 Oct 2021 03:11:53 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.1404.g83021034c5d In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren Until the introduction of the "preserve_ignored" flag in the preceding commit callers who wanted its behavior needed to adjust "dir.flags" and call setup_standard_excludes() themselves. Now that we have no external users of "dir" anymore let's rename it to "private_dir" and add a comment indicating that we'd like it not to be messed with by external callers. This should avoid avoid accidental misuse or confusion over its ownership. Signed-off-by: Elijah Newren Signed-off-by: Ævar Arnfjörð Bjarmason --- unpack-trees.c | 10 +++++----- unpack-trees.h | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/unpack-trees.c b/unpack-trees.c index 02bc999c6c3..512011cfa42 100644 --- a/unpack-trees.c +++ b/unpack-trees.c @@ -196,7 +196,7 @@ void unpack_trees_options_init(struct unpack_trees_options *o) void unpack_trees_options_release(struct unpack_trees_options *opts) { strvec_clear(&opts->msgs_to_free); - dir_clear(&opts->dir); + dir_clear(&opts->private_dir); } static int do_add_entry(struct unpack_trees_options *o, struct cache_entry *ce, @@ -1712,8 +1712,8 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options } if (!o->preserve_ignored) { - o->dir.flags |= DIR_SHOW_IGNORED; - setup_standard_excludes(&o->dir); + o->private_dir.flags |= DIR_SHOW_IGNORED; + setup_standard_excludes(&o->private_dir); } if (!core_apply_sparse_checkout || !o->update) @@ -2141,7 +2141,7 @@ static int verify_clean_subdirectory(const struct cache_entry *ce, */ pathbuf = xstrfmt("%.*s/", namelen, ce->name); - d.exclude_per_dir = o->dir.exclude_per_dir; + d.exclude_per_dir = o->private_dir.exclude_per_dir; i = read_directory(&d, o->src_index, pathbuf, namelen+1, NULL); dir_clear(&d); free(pathbuf); @@ -2183,7 +2183,7 @@ static int check_ok_to_remove(const char *name, int len, int dtype, if (ignore_case && icase_exists(o, name, len, st)) return 0; - if (is_excluded(&o->dir, o->src_index, name, &dtype)) + if (is_excluded(&o->private_dir, o->src_index, name, &dtype)) /* * ce->name is explicitly excluded, so it is Ok to * overwrite it. diff --git a/unpack-trees.h b/unpack-trees.h index 65a8d99d4ef..2eb633bf771 100644 --- a/unpack-trees.h +++ b/unpack-trees.h @@ -70,7 +70,7 @@ struct unpack_trees_options { dry_run; const char *prefix; int cache_bottom; - struct dir_struct dir; + struct dir_struct private_dir; /* for internal use only */ struct pathspec *pathspec; merge_fn_t fn; const char *msgs[NB_UNPACK_TREES_WARNING_TYPES]; @@ -97,7 +97,7 @@ struct unpack_trees_options { #define UNPACK_TREES_OPTIONS_INIT { \ .msgs_to_free = STRVEC_INIT, \ - .dir = DIR_INIT, \ + .private_dir = DIR_INIT, \ } void unpack_trees_options_init(struct unpack_trees_options *o); From patchwork Mon Oct 4 01:11:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12533133 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DFBD2C433F5 for ; Mon, 4 Oct 2021 01:12:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B54196115C for ; Mon, 4 Oct 2021 01:12:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232110AbhJDBOD (ORCPT ); Sun, 3 Oct 2021 21:14:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38632 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232008AbhJDBN4 (ORCPT ); Sun, 3 Oct 2021 21:13:56 -0400 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 26999C061781 for ; Sun, 3 Oct 2021 18:12:08 -0700 (PDT) Received: by mail-wm1-x329.google.com with SMTP id m42so1609968wms.2 for ; Sun, 03 Oct 2021 18:12:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=QO4N3KhiEHtNiCLFo3m/eIQ8nenzEe7XaPfIPeL5Emw=; b=WL8A7ehIuwoEMGOPBYAlwEiSdphKW8IIhEjNZHVVjJ1Pbv/KfJHiWncwszYjCdZWo3 zPmdovbMWYo3CJwzA4H+gs0nVh9K7rA4ttaLhE876TAVOUkKDr+2h4hqrW32fuiCGIdd Sy1H1D84Qo9+Cc+Q9whUVFfWAgHJ9MdGJQ0aXlD++soK/F3C6rZCYiSttlZg6GbgHO4f SSPrmQ36EQ3vnSJqCZYoujQ8aeJPuY7D1RjCbqSk2EzpK2JB3GpGo2gFmP5+DQk6FcjE IxLp0VhvGayM9hgbc7z9vdB0vg5obylDfJrKbJOH4DaeC1xy3u5wuJVEOqO/tDTqD3MA nivw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=QO4N3KhiEHtNiCLFo3m/eIQ8nenzEe7XaPfIPeL5Emw=; b=pOQMem6erIeO+GE+zlGeJPfwIcmpsHAkXnR7duk6rtjE/7vuVpuaebiOyQJOWJNKrB 2FfabIfEDAbO9n9Ur4cqPHtIElil35hMwVOFXO/f/NkrdQWyD/knIX5JE8u7/VTBUsvw XkFPGmjE/BY2c+iku78qAyCb/5y7LYUua/WwBfu5pWp3kcWip8kTvDDSlk0YdFefo3QZ pfu6qKHwUixlK2B+4Ea1l1Qcj81KWxkDc4Yvi8g8KQI3cBRP7tuip4kFLW9pIp16Ma9W ptQGbUbQzSrZ2uPaa8NDO/OfROgpyxaBr4F7WLJAWFJcrFYk4mDPgxwI7r/Sitv0l/qe W2Bg== X-Gm-Message-State: AOAM533G50VK62vA+u/Y11dCEeDLAnTkm0NXROX14vODTyRjpinjOeTB w+eiGDsDwmna5cvt0mEhfwrjycj8nHn1eA== X-Google-Smtp-Source: ABdhPJy0oy2uAq9dsM+unD9fEALfATETHPcUy/t9T5EiDSd+haB0SRjnAXawFf5bAn4zd903Ke4t7Q== X-Received: by 2002:a05:600c:210f:: with SMTP id u15mr8134515wml.157.1633309926442; Sun, 03 Oct 2021 18:12:06 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id q3sm12384317wmc.25.2021.10.03.18.12.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Oct 2021 18:12:06 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Elijah Newren , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= , =?utf-8?q?Martin_=C3=85gren?= , Andrzej Hunt , Jeff King , Fedor Biryukov , Philip Oakley , Phillip Wood , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= Subject: [RFC PATCH v4 05/10] Remove ignored files by default when they are in the way Date: Mon, 4 Oct 2021 03:11:54 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.1404.g83021034c5d In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren Change several commands to remove ignored files by default when they are in the way. Since some commands (checkout, merge) take a --no-overwrite-ignore option to allow the user to configure this, and it may make sense to add that option to more commands (and in the case of merge, actually plumb that configuration option through to more of the backends than just the fast-forwarding special case), add little comments about where such flags would be used. Incidentally, this fixes a test failure in t7112. Signed-off-by: Elijah Newren Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/am.c | 3 +-- builtin/clone.c | 3 +-- builtin/merge.c | 3 +-- builtin/reset.c | 3 +-- builtin/stash.c | 3 +-- merge-ort.c | 2 +- reset.c | 3 +-- sequencer.c | 3 +-- t/t7112-reset-submodule.sh | 1 - 9 files changed, 8 insertions(+), 16 deletions(-) diff --git a/builtin/am.c b/builtin/am.c index 3c6efe2a46b..8cb7e72e6c5 100644 --- a/builtin/am.c +++ b/builtin/am.c @@ -1919,8 +1919,7 @@ static int fast_forward_to(struct tree *head, struct tree *remote, int reset) opts.merge = 1; opts.reset = reset; if (!reset) - /* FIXME: Default should be to remove ignored files */ - opts.preserve_ignored = 1; + opts.preserve_ignored = 0; /* FIXME: !overwrite_ignore */ opts.fn = twoway_merge; init_tree_desc(&t[0], head->buffer, head->size); init_tree_desc(&t[1], remote->buffer, remote->size); diff --git a/builtin/clone.c b/builtin/clone.c index e76c38e4e81..49edb4a2aaa 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -686,8 +686,7 @@ static int checkout(int submodule_progress) opts.update = 1; opts.merge = 1; opts.clone = 1; - /* FIXME: Default should be to remove ignored files */ - opts.preserve_ignored = 1; + opts.preserve_ignored = 0; opts.fn = oneway_merge; opts.verbose_update = (option_verbosity >= 0); opts.src_index = &the_index; diff --git a/builtin/merge.c b/builtin/merge.c index 55aac869e5a..7f990e36651 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -680,8 +680,7 @@ static int read_tree_trivial(struct object_id *common, struct object_id *head, opts.verbose_update = 1; opts.trivial_merges_only = 1; opts.merge = 1; - /* FIXME: Default should be to remove ignored files */ - opts.preserve_ignored = 1; + opts.preserve_ignored = 0; /* FIXME: !overwrite_ignore */ trees[nr_trees] = parse_tree_indirect(common); if (!trees[nr_trees++]) return -1; diff --git a/builtin/reset.c b/builtin/reset.c index 73477239146..9d1391335a1 100644 --- a/builtin/reset.c +++ b/builtin/reset.c @@ -66,8 +66,7 @@ static int reset_index(const char *ref, const struct object_id *oid, int reset_t case KEEP: case MERGE: opts.update = 1; - /* FIXME: Default should be to remove ignored files */ - opts.preserve_ignored = 1; + opts.preserve_ignored = 0; /* FIXME: !overwrite_ignore */ break; case HARD: opts.update = 1; diff --git a/builtin/stash.c b/builtin/stash.c index 78492013529..92ad3241270 100644 --- a/builtin/stash.c +++ b/builtin/stash.c @@ -258,8 +258,7 @@ static int reset_tree(struct object_id *i_tree, int update, int reset) opts.reset = reset; opts.update = update; if (update && !reset) - /* FIXME: Default should be to remove ignored files */ - opts.preserve_ignored = 1; + opts.preserve_ignored = 0; /* FIXME: !overwrite_ignore */ opts.fn = oneway_merge; if (unpack_trees(nr_trees, t, &opts)) { diff --git a/merge-ort.c b/merge-ort.c index e5620bda212..5c443b2b00d 100644 --- a/merge-ort.c +++ b/merge-ort.c @@ -4044,7 +4044,7 @@ static int checkout(struct merge_options *opt, unpack_opts.quiet = 0; /* FIXME: sequencer might want quiet? */ unpack_opts.verbose_update = (opt->verbosity > 2); unpack_opts.fn = twoway_merge; - unpack_opts.preserve_ignored = 0; /* FIXME: !opts->overwrite_ignore*/ + unpack_opts.preserve_ignored = 0; /* FIXME: !opts->overwrite_ignore */ parse_tree(prev); init_tree_desc(&trees[0], prev->buffer, prev->size); parse_tree(next); diff --git a/reset.c b/reset.c index cd344f47f13..5f69311b9f4 100644 --- a/reset.c +++ b/reset.c @@ -56,8 +56,7 @@ int reset_head(struct repository *r, struct object_id *oid, const char *action, unpack_tree_opts.fn = reset_hard ? oneway_merge : twoway_merge; unpack_tree_opts.update = 1; unpack_tree_opts.merge = 1; - /* FIXME: Default should be to remove ignored files */ - unpack_tree_opts.preserve_ignored = 1; + unpack_tree_opts.preserve_ignored = 0; /* FIXME: !overwrite_ignore */ init_checkout_metadata(&unpack_tree_opts.meta, switch_to_branch, oid, NULL); if (!detach_head) unpack_tree_opts.reset = 1; diff --git a/sequencer.c b/sequencer.c index 669ea15944c..05395db9e01 100644 --- a/sequencer.c +++ b/sequencer.c @@ -3698,8 +3698,7 @@ static int do_reset(struct repository *r, unpack_tree_opts.fn = oneway_merge; unpack_tree_opts.merge = 1; unpack_tree_opts.update = 1; - /* FIXME: Default should be to remove ignored files */ - unpack_tree_opts.preserve_ignored = 1; + unpack_tree_opts.preserve_ignored = 0; /* FIXME: !overwrite_ignore */ init_checkout_metadata(&unpack_tree_opts.meta, name, &oid, NULL); if (repo_read_index_unmerged(r)) { diff --git a/t/t7112-reset-submodule.sh b/t/t7112-reset-submodule.sh index 19830d90365..a3e2413bc33 100755 --- a/t/t7112-reset-submodule.sh +++ b/t/t7112-reset-submodule.sh @@ -6,7 +6,6 @@ test_description='reset can handle submodules' . "$TEST_DIRECTORY"/lib-submodule-update.sh KNOWN_FAILURE_DIRECTORY_SUBMODULE_CONFLICTS=1 -KNOWN_FAILURE_SUBMODULE_OVERWRITE_IGNORED_UNTRACKED=1 test_submodule_switch_recursing_with_args "reset --keep" From patchwork Mon Oct 4 01:11:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12533135 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F05F3C433EF for ; Mon, 4 Oct 2021 01:12:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D7D8F60F9C for ; Mon, 4 Oct 2021 01:12:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232119AbhJDBOG (ORCPT ); Sun, 3 Oct 2021 21:14:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38634 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232038AbhJDBN5 (ORCPT ); Sun, 3 Oct 2021 21:13:57 -0400 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3284FC0613EC for ; Sun, 3 Oct 2021 18:12:09 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id r10so11121102wra.12 for ; Sun, 03 Oct 2021 18:12:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=hRU95OW9Ji2PsrVJUcCyWwLiXZ1FJftyWxzZwjNsR8Y=; b=BS0YdfrN+BlFE+9zo/VML6iTyYqo8pHx5fYbxoqDjfJfDfteWiNpfCkJiNXAgtjyf5 EaSHXNxcHNfyWCYWIc/00rtOLhJrIEenY2S02DnusoE4FuKMAT5NFx6GQd9F/l0wX7pq PDHf/kqkNg3VKWRMli0PdB2xrss257bImkVBpmpcC40mGpp6TPjU3r3lUc1NgLkrNaZ9 WA0xuq2peI4V2UJJpjSrHhKHxlEqKCWd82vRR5W0ZHcB2RRbtkNcA0uLETIwvIGPsiHz My0Nd4euO6uVG+jrsnrcngzd1VDcDs//cDDMB5xzVQ9+SqojybtADg1zplwaWCvZQwnS oQ4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=hRU95OW9Ji2PsrVJUcCyWwLiXZ1FJftyWxzZwjNsR8Y=; b=dvw6FPA8HtQfHhv3CNk33dknjdbRmlgHkxT8NR23N7OUwSc2X9NLXZTbhQFxg4d8NO L9/YNyU/9rgrmJPem+3FAVBMs1RxDOnCOsbEIhzHYx6OI2T21mfwQT4yxsdiNmoVR4X6 c5TnzcdJFgokE1SlH9Pk78ZXfZmpkYMwwiCXIXP7kWRAFk5cdb630z+6/3DCKIesDm9p AMVOOrG3OJoAVil+PPVrpV3QaHA3YylLT/SM5dbZ5tTsM7X6cQbHRXpQEAkKpU/iDFCQ DJ8+HL9EmyiI+KAw6jtYZOZMHjISIkNZ7m5KbtO1ZZkiMG7nEXBpz1eBzrkY1SV8rwFU Io3A== X-Gm-Message-State: AOAM533VH/EkXGWf+lDxfYP+e83HVrZM7yAOTF5752+st3chfTYUFjpj oEYFxprpTQvc5KU4Zb8v/cTZHaXLfSHqOA== X-Google-Smtp-Source: ABdhPJxLWsCg3APrGEYGMmjD4trshDVv2hRtQIe9Dxr6q9KvCARU3DLYWLk2MXasNC7eu6ae11q/+w== X-Received: by 2002:a5d:5234:: with SMTP id i20mr11233181wra.415.1633309927433; Sun, 03 Oct 2021 18:12:07 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id q3sm12384317wmc.25.2021.10.03.18.12.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Oct 2021 18:12:06 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Elijah Newren , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= , =?utf-8?q?Martin_=C3=85gren?= , Andrzej Hunt , Jeff King , Fedor Biryukov , Philip Oakley , Phillip Wood , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= Subject: [RFC PATCH v4 06/10] Change unpack_trees' 'reset' flag into an enum Date: Mon, 4 Oct 2021 03:11:55 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.1404.g83021034c5d In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren Traditionally, unpack_trees_options->reset was used to signal that it was okay to delete any untracked files in the way. This was used by `git read-tree --reset`, but then started appearing in other places as well. However, many of the other uses should not be deleting untracked files in the way. Change this value to an enum so that a value of 1 (i.e. "true") can be split into two: UNPACK_RESET_PROTECT_UNTRACKED, UNPACK_RESET_OVERWRITE_UNTRACKED In order to catch accidental misuses (i.e. where folks call it the way they traditionally used to), define the special enum value of UNPACK_RESET_INVALID = 1 which will trigger a BUG(). Modify existing callers so that read-tree --reset reset --hard checkout --force continue using the UNPACK_RESET_OVERWRITE_UNTRACKED logic, while other callers, including am checkout without --force stash (though currently dead code; reset always had a value of 0) numerous callers from rebase/sequencer to reset_head() will use the new UNPACK_RESET_PROTECT_UNTRACKED value. Also, note that it has been reported that 'git checkout ' currently also allows overwriting untracked files[1]. That case should also be fixed, but it does not use unpack_trees() and thus is outside the scope of the current changes. [1] https://lore.kernel.org/git/15dad590-087e-5a48-9238-5d2826950506@gmail.com/ Signed-off-by: Elijah Newren Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/am.c | 5 ++--- builtin/checkout.c | 5 +++-- builtin/read-tree.c | 3 +++ builtin/reset.c | 9 +++++++-- builtin/stash.c | 4 ++-- reset.c | 2 +- t/t2500-untracked-overwriting.sh | 6 +++--- unpack-trees.c | 10 +++++++++- unpack-trees.h | 11 +++++++++-- 9 files changed, 39 insertions(+), 16 deletions(-) diff --git a/builtin/am.c b/builtin/am.c index 8cb7e72e6c5..dfe2bf207e6 100644 --- a/builtin/am.c +++ b/builtin/am.c @@ -1917,9 +1917,8 @@ static int fast_forward_to(struct tree *head, struct tree *remote, int reset) opts.dst_index = &the_index; opts.update = 1; opts.merge = 1; - opts.reset = reset; - if (!reset) - opts.preserve_ignored = 0; /* FIXME: !overwrite_ignore */ + opts.reset = reset ? UNPACK_RESET_PROTECT_UNTRACKED : 0; + opts.preserve_ignored = 0; /* FIXME: !overwrite_ignore */ opts.fn = twoway_merge; init_tree_desc(&t[0], head->buffer, head->size); init_tree_desc(&t[1], remote->buffer, remote->size); diff --git a/builtin/checkout.c b/builtin/checkout.c index 0c5187025c5..ee3e450537f 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -646,9 +646,10 @@ static int reset_tree(struct tree *tree, const struct checkout_opts *o, opts.head_idx = -1; opts.update = worktree; opts.skip_unmerged = !worktree; - opts.reset = 1; + opts.reset = o->force ? UNPACK_RESET_OVERWRITE_UNTRACKED : + UNPACK_RESET_PROTECT_UNTRACKED; + opts.preserve_ignored = (!o->force && !o->overwrite_ignore); opts.merge = 1; - opts.preserve_ignored = 0; opts.fn = oneway_merge; opts.verbose_update = o->show_progress; opts.src_index = &the_index; diff --git a/builtin/read-tree.c b/builtin/read-tree.c index 7f3c987b126..5e10caeff5a 100644 --- a/builtin/read-tree.c +++ b/builtin/read-tree.c @@ -166,6 +166,9 @@ int cmd_read_tree(int argc, const char **argv, const char *cmd_prefix) if (1 < opts.merge + opts.reset + prefix_set) die("Which one? -m, --reset, or --prefix?"); + if (opts.reset) + opts.reset = UNPACK_RESET_OVERWRITE_UNTRACKED; + /* * NEEDSWORK * diff --git a/builtin/reset.c b/builtin/reset.c index 9d1391335a1..00d2de392a8 100644 --- a/builtin/reset.c +++ b/builtin/reset.c @@ -70,9 +70,14 @@ static int reset_index(const char *ref, const struct object_id *oid, int reset_t break; case HARD: opts.update = 1; - /* fallthrough */ + opts.reset = UNPACK_RESET_OVERWRITE_UNTRACKED; + break; + case MIXED: + opts.reset = UNPACK_RESET_PROTECT_UNTRACKED; + /* but opts.update=0, so working tree not updated */ + break; default: - opts.reset = 1; + BUG("invalid reset_type passed to reset_index"); } read_cache_unmerged(); diff --git a/builtin/stash.c b/builtin/stash.c index 92ad3241270..061237cf9a4 100644 --- a/builtin/stash.c +++ b/builtin/stash.c @@ -255,9 +255,9 @@ static int reset_tree(struct object_id *i_tree, int update, int reset) opts.src_index = &the_index; opts.dst_index = &the_index; opts.merge = 1; - opts.reset = reset; + opts.reset = reset ? UNPACK_RESET_PROTECT_UNTRACKED : 0; opts.update = update; - if (update && !reset) + if (update) opts.preserve_ignored = 0; /* FIXME: !overwrite_ignore */ opts.fn = oneway_merge; diff --git a/reset.c b/reset.c index 5f69311b9f4..5788b1926f3 100644 --- a/reset.c +++ b/reset.c @@ -59,7 +59,7 @@ int reset_head(struct repository *r, struct object_id *oid, const char *action, unpack_tree_opts.preserve_ignored = 0; /* FIXME: !overwrite_ignore */ init_checkout_metadata(&unpack_tree_opts.meta, switch_to_branch, oid, NULL); if (!detach_head) - unpack_tree_opts.reset = 1; + unpack_tree_opts.reset = UNPACK_RESET_PROTECT_UNTRACKED; if (repo_read_index_unmerged(r) < 0) { ret = error(_("could not read index")); diff --git a/t/t2500-untracked-overwriting.sh b/t/t2500-untracked-overwriting.sh index 2412d121ea8..18604360df8 100755 --- a/t/t2500-untracked-overwriting.sh +++ b/t/t2500-untracked-overwriting.sh @@ -92,7 +92,7 @@ test_setup_checkout_m () { ) } -test_expect_failure 'checkout -m does not nuke untracked file' ' +test_expect_success 'checkout -m does not nuke untracked file' ' test_setup_checkout_m && ( cd checkout && @@ -138,7 +138,7 @@ test_setup_sequencing () { ) } -test_expect_failure 'git rebase --abort and untracked files' ' +test_expect_success 'git rebase --abort and untracked files' ' test_setup_sequencing rebase_abort_and_untracked && ( cd sequencing_rebase_abort_and_untracked && @@ -155,7 +155,7 @@ test_expect_failure 'git rebase --abort and untracked files' ' ) ' -test_expect_failure 'git rebase fast forwarding and untracked files' ' +test_expect_success 'git rebase fast forwarding and untracked files' ' test_setup_sequencing rebase_fast_forward_and_untracked && ( cd sequencing_rebase_fast_forward_and_untracked && diff --git a/unpack-trees.c b/unpack-trees.c index 512011cfa42..37f769030ab 100644 --- a/unpack-trees.c +++ b/unpack-trees.c @@ -1699,6 +1699,9 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options struct pattern_list pl; int free_pattern_list = 0; + if (o->reset == UNPACK_RESET_INVALID) + BUG("o->reset had a value of 1; should be UNPACK_TREES_*_UNTRACKED"); + if (len > MAX_UNPACK_TREES) die("unpack_trees takes at most %d trees", MAX_UNPACK_TREES); @@ -1711,6 +1714,10 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options ensure_full_index(o->dst_index); } + if (o->reset == UNPACK_RESET_OVERWRITE_UNTRACKED && + o->preserve_ignored) + BUG("UNPACK_RESET_OVERWRITE_UNTRACKED incompatible with preserved ignored files"); + if (!o->preserve_ignored) { o->private_dir.flags |= DIR_SHOW_IGNORED; setup_standard_excludes(&o->private_dir); @@ -2227,7 +2234,8 @@ static int verify_absent_1(const struct cache_entry *ce, int len; struct stat st; - if (o->index_only || o->reset || !o->update) + if (o->index_only || !o->update || + o->reset == UNPACK_RESET_OVERWRITE_UNTRACKED) return 0; len = check_leading_path(ce->name, ce_namelen(ce), 0); diff --git a/unpack-trees.h b/unpack-trees.h index 2eb633bf771..1582599606a 100644 --- a/unpack-trees.h +++ b/unpack-trees.h @@ -48,9 +48,15 @@ void setup_unpack_trees_porcelain(struct unpack_trees_options *opts, */ void unpack_trees_options_release(struct unpack_trees_options *opts); +enum unpack_trees_reset_type { + UNPACK_RESET_NONE = 0, /* traditional "false" value; still valid */ + UNPACK_RESET_INVALID = 1, /* "true" no longer valid; use below values */ + UNPACK_RESET_PROTECT_UNTRACKED, + UNPACK_RESET_OVERWRITE_UNTRACKED +}; + struct unpack_trees_options { - unsigned int reset, - merge, + unsigned int merge, update, preserve_ignored, clone, @@ -68,6 +74,7 @@ struct unpack_trees_options { exiting_early, show_all_errors, dry_run; + enum unpack_trees_reset_type reset; const char *prefix; int cache_bottom; struct dir_struct private_dir; /* for internal use only */ From patchwork Mon Oct 4 01:11:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12533137 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 63DFEC433FE for ; Mon, 4 Oct 2021 01:12:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 44DA66115C for ; Mon, 4 Oct 2021 01:12:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232076AbhJDBOI (ORCPT ); Sun, 3 Oct 2021 21:14:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38654 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232078AbhJDBOA (ORCPT ); Sun, 3 Oct 2021 21:14:00 -0400 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1283AC061782 for ; Sun, 3 Oct 2021 18:12:10 -0700 (PDT) Received: by mail-wm1-x32c.google.com with SMTP id j10-20020a1c230a000000b0030d523b6693so7377770wmj.2 for ; Sun, 03 Oct 2021 18:12:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=lN7L+4lHq/KYd3KjJqC2UNzO0Nq5OpIFE7MUYs/MQ6I=; b=JbW4nGVNzAXb6mB/wn3LpQAM5cUL9nkD+wSZkQ6b6LKwnEtqhTr/8bvjxnVJI6ustj pjWAD7HCdr1g036wWUQ4y3YA1UTcyx90qwgG6217bDkGJFr5T43QhFy1kIYmZqIrx6a9 PYBeJpp3M5aHm1ls4tOaSatYgaZ+9BnI7eBZTCU6a2z7zwiKgb3M+YQaczYQCSCCfHhD PXF2yCQJvlgNtt/aHW5Z6NPI+QH1rYcD5uVjezByrJzM5KHWTbBxZMLMkk+ZUnKJueQX AVOHEjwtgND1giLUqWzgZDr5ibfIkLjCLS+3jw4OBEFyNFlCkmUCuNNnKBJGZZn0ntfH Ktjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=lN7L+4lHq/KYd3KjJqC2UNzO0Nq5OpIFE7MUYs/MQ6I=; b=aQR6TqRc/zc9VO8pdluXbGcxBkXNrV2FSg1SKfdgkynaloONoBMd6JqHtaY4tJ4j4v q6d8yZpKBOTGlBOXWw7IwV0eTZ3G2u2ZE50EecxQ1aP2/plNcrEwWl/3vfiBq9URLwzX qoFgPrsRBFrTlorAn/NoRNk+OaarNDVOt8YTPbB+UXCvY5CKMsE+nj/9IECLW28GLIuQ Ci1KjsuikPKTBcg1XznKMrFgFapH6qFrA860hZsNQr8K/xhMpPEieeC16YuyYgFzUmkR 1mlFYDUUylIMcrC8M5I8vfvMWOqOiqlnZi2n0a4tTV3PRb8jcZmbRFlYq71UR2ZCo4LG bnYw== X-Gm-Message-State: AOAM533fIqBcQy12OZ9bLnpgSujDaKTYcVDcscmV2pnNuWRbbb0iD7G2 5mLHNN0T4vSouC7UM9bud2MW8Zjpy3OK3A== X-Google-Smtp-Source: ABdhPJxyQttXaGwSC6kkqsDgq3sZWJ3cM3ys4Bnx9goXO4Ofq7Gs721mxfERQGhHGcHCJpBKIg6xGA== X-Received: by 2002:a05:600c:2312:: with SMTP id 18mr16018450wmo.192.1633309928384; Sun, 03 Oct 2021 18:12:08 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id q3sm12384317wmc.25.2021.10.03.18.12.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Oct 2021 18:12:07 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Elijah Newren , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= , =?utf-8?q?Martin_=C3=85gren?= , Andrzej Hunt , Jeff King , Fedor Biryukov , Philip Oakley , Phillip Wood , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= Subject: [RFC PATCH v4 07/10] unpack-trees: avoid nuking untracked dir in way of unmerged file Date: Mon, 4 Oct 2021 03:11:56 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.1404.g83021034c5d In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren Signed-off-by: Elijah Newren Signed-off-by: Ævar Arnfjörð Bjarmason --- t/t2500-untracked-overwriting.sh | 2 +- unpack-trees.c | 35 ++++++++++++++++++++++++++++---- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/t/t2500-untracked-overwriting.sh b/t/t2500-untracked-overwriting.sh index 18604360df8..5ec66058cfc 100755 --- a/t/t2500-untracked-overwriting.sh +++ b/t/t2500-untracked-overwriting.sh @@ -197,7 +197,7 @@ test_expect_failure 'git stash and untracked files' ' ) ' -test_expect_failure 'git am --abort and untracked dir vs. unmerged file' ' +test_expect_success 'git am --abort and untracked dir vs. unmerged file' ' test_setup_sequencing am_abort_and_untracked && ( cd sequencing_am_abort_and_untracked && diff --git a/unpack-trees.c b/unpack-trees.c index 37f769030ab..8408a8fcfff 100644 --- a/unpack-trees.c +++ b/unpack-trees.c @@ -2173,9 +2173,15 @@ static int icase_exists(struct unpack_trees_options *o, const char *name, int le return src && !ie_match_stat(o->src_index, src, st, CE_MATCH_IGNORE_VALID|CE_MATCH_IGNORE_SKIP_WORKTREE); } +enum absent_checking_type { + COMPLETELY_ABSENT, + ABSENT_ANY_DIRECTORY +}; + static int check_ok_to_remove(const char *name, int len, int dtype, const struct cache_entry *ce, struct stat *st, enum unpack_trees_error_types error_type, + enum absent_checking_type absent_type, struct unpack_trees_options *o) { const struct cache_entry *result; @@ -2209,6 +2215,10 @@ static int check_ok_to_remove(const char *name, int len, int dtype, return 0; } + /* If we only care about directories, then we can remove */ + if (absent_type == ABSENT_ANY_DIRECTORY) + return 0; + /* * The previous round may already have decided to * delete this path, which is in a subdirectory that @@ -2229,6 +2239,7 @@ static int check_ok_to_remove(const char *name, int len, int dtype, */ static int verify_absent_1(const struct cache_entry *ce, enum unpack_trees_error_types error_type, + enum absent_checking_type absent_type, struct unpack_trees_options *o) { int len; @@ -2255,7 +2266,8 @@ static int verify_absent_1(const struct cache_entry *ce, NULL, o); else ret = check_ok_to_remove(path, len, DT_UNKNOWN, NULL, - &st, error_type, o); + &st, error_type, + absent_type, o); } free(path); return ret; @@ -2270,7 +2282,7 @@ static int verify_absent_1(const struct cache_entry *ce, return check_ok_to_remove(ce->name, ce_namelen(ce), ce_to_dtype(ce), ce, &st, - error_type, o); + error_type, absent_type, o); } } @@ -2280,14 +2292,23 @@ static int verify_absent(const struct cache_entry *ce, { if (!o->skip_sparse_checkout && (ce->ce_flags & CE_NEW_SKIP_WORKTREE)) return 0; - return verify_absent_1(ce, error_type, o); + return verify_absent_1(ce, error_type, COMPLETELY_ABSENT, o); +} + +static int verify_absent_if_directory(const struct cache_entry *ce, + enum unpack_trees_error_types error_type, + struct unpack_trees_options *o) +{ + if (!o->skip_sparse_checkout && (ce->ce_flags & CE_NEW_SKIP_WORKTREE)) + return 0; + return verify_absent_1(ce, error_type, ABSENT_ANY_DIRECTORY, o); } static int verify_absent_sparse(const struct cache_entry *ce, enum unpack_trees_error_types error_type, struct unpack_trees_options *o) { - return verify_absent_1(ce, error_type, o); + return verify_absent_1(ce, error_type, COMPLETELY_ABSENT, o); } static int merged_entry(const struct cache_entry *ce, @@ -2361,6 +2382,12 @@ static int merged_entry(const struct cache_entry *ce, * Previously unmerged entry left as an existence * marker by read_index_unmerged(); */ + if (verify_absent_if_directory(merge, + ERROR_WOULD_LOSE_UNTRACKED_OVERWRITTEN, o)) { + discard_cache_entry(merge); + return -1; + } + invalidate_ce_path(old, o); } From patchwork Mon Oct 4 01:11:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12533139 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3C405C433FE for ; Mon, 4 Oct 2021 01:12:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1F2D26115B for ; Mon, 4 Oct 2021 01:12:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232151AbhJDBOJ (ORCPT ); Sun, 3 Oct 2021 21:14:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38658 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232086AbhJDBOA (ORCPT ); Sun, 3 Oct 2021 21:14:00 -0400 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DFCA1C061786 for ; Sun, 3 Oct 2021 18:12:10 -0700 (PDT) Received: by mail-wr1-x429.google.com with SMTP id e12so7375139wra.4 for ; Sun, 03 Oct 2021 18:12:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=rSJZyY8aVgNm185JUDFOszyU662k30q9xI+uXP7vo2I=; b=T2St2Qu7kTYhrJ6uRAFxUOCO88SVlr6fU5EA+1eN8iQSzraSD2rKojdIj6MZghVCpV 0RjqWZpqmjOJKQcEQfuIvW4nRBsM6r6z9TrZx8D98SHigWR1KVUxWGPHuhB69iBOt8yM rymtcLTkjmYTIq0V7rAr9cwns1KOItqNQgim/Kq5LCckF4TtL49Lpm2juyyV4OT6qoHo 5VqUhchBXtCWlLxv6TVcqs058ixNwzbmDvEkrH+ivV7HCl8pNh0IBD6zEdoIsE3stJC6 ZFiM/6hHWPy/+R6RZIs1wX8++JpUWkIf5nuf+hWW9/f4MWvGRO1sG82ZyOt2ALJ4AwlK gMjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=rSJZyY8aVgNm185JUDFOszyU662k30q9xI+uXP7vo2I=; b=uiJLFmwGxfzOb+KV8BYWz86LwunOwjYGmSQrDbhio017FDITcC20YyPn1GiZyqofda nLPwrUN9yjSK33hqQNYSUmOMaUV3NjK1Ua0DzOhmjh2KGVS/nmL2C8f2EogZP//hW/w6 d3nUZgLEfefzAnrjfDe1Hxi+5PBxlgAxZKkXfutBEw9t6SBRUmkrP8aEG1hzpMTaTS7E zDYGgsOJeUb7Ipz63orXGQcof5FaFS15yGna5zp5Jq673OC3NxBmXhpVM4OPXRZLzk4l rG79qAF4PuSFvyazlwgGm2tvwPeU4xVFahEoUV+4z+XITV26lMQkbzBIk8r0JlO9dbYp o0LQ== X-Gm-Message-State: AOAM530Sp1BoSZttJ6WyeqmNtfQD/mhVrA7LNG4Enkyxpmz1G+awekcV 3XKs+TOaJxK4nyStogWEnSzthjznQc0Vbw== X-Google-Smtp-Source: ABdhPJyEulCDbuNhYcoLM0kO9r3MtFEc7npBCAbh30AOxJCwjczbi4aO9xvBIxrFMXJ8JxoEtki9yw== X-Received: by 2002:a05:6000:188d:: with SMTP id a13mr6166839wri.243.1633309929319; Sun, 03 Oct 2021 18:12:09 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id q3sm12384317wmc.25.2021.10.03.18.12.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Oct 2021 18:12:08 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Elijah Newren , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= , =?utf-8?q?Martin_=C3=85gren?= , Andrzej Hunt , Jeff King , Fedor Biryukov , Philip Oakley , Phillip Wood , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= Subject: [RFC PATCH v4 08/10] unpack-trees: avoid nuking untracked dir in way of locally deleted file Date: Mon, 4 Oct 2021 03:11:57 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.1404.g83021034c5d In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren Signed-off-by: Elijah Newren Signed-off-by: Ævar Arnfjörð Bjarmason --- t/t2500-untracked-overwriting.sh | 2 +- unpack-trees.c | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/t/t2500-untracked-overwriting.sh b/t/t2500-untracked-overwriting.sh index 5ec66058cfc..5c0bf4d21fc 100755 --- a/t/t2500-untracked-overwriting.sh +++ b/t/t2500-untracked-overwriting.sh @@ -218,7 +218,7 @@ test_expect_success 'git am --abort and untracked dir vs. unmerged file' ' ) ' -test_expect_failure 'git am --skip and untracked dir vs deleted file' ' +test_expect_success 'git am --skip and untracked dir vs deleted file' ' test_setup_sequencing am_skip_and_untracked && ( cd sequencing_am_skip_and_untracked && diff --git a/unpack-trees.c b/unpack-trees.c index 8408a8fcfff..703e7953d62 100644 --- a/unpack-trees.c +++ b/unpack-trees.c @@ -2405,7 +2405,10 @@ static int deleted_entry(const struct cache_entry *ce, if (verify_absent(ce, ERROR_WOULD_LOSE_UNTRACKED_REMOVED, o)) return -1; return 0; + } else if (verify_absent_if_directory(ce, ERROR_WOULD_LOSE_UNTRACKED_REMOVED, o)) { + return -1; } + if (!(old->ce_flags & CE_CONFLICTED) && verify_uptodate(old, o)) return -1; add_entry(o, ce, CE_REMOVE, 0); From patchwork Mon Oct 4 01:11:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12533141 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9C940C433F5 for ; Mon, 4 Oct 2021 01:12:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 85BCE6115B for ; Mon, 4 Oct 2021 01:12:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232199AbhJDBOM (ORCPT ); Sun, 3 Oct 2021 21:14:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38634 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232105AbhJDBOF (ORCPT ); Sun, 3 Oct 2021 21:14:05 -0400 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8AAC9C061788 for ; Sun, 3 Oct 2021 18:12:11 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id r18so309392wrg.6 for ; Sun, 03 Oct 2021 18:12:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Va3OCSs1QcDZyg3510+KU2IW6XAx9EG+z6fMGugxZKc=; b=WwjEFRdAetTLhPg9JlNiZYqIW7feyk3SQZmwxkV6tdFfGtsIf681dfcYw6+9bBzpf1 GwcZ30qLxFCd47MATGE5jvtHTwyqqnDhDccHXfhjSk2D/xK15TmnnzIQ1V5/AkqFltld 57XyVBAFn8YmN70Kws9mLSHl9ZvvZ4RMjNarGlvMurjEo484wGT3UKeFldkFFSRUVwKJ zgEB4z+i8ssVIsrsybr4uHmURH96Gbi0AwipoI+n7GOTxh6uzVCmadEYP/oFDREF2IhK lkr5dpw7LjDCY6vaXq/hXA9mYSFDQNMSkrIzvtq4H2E3rw68sOw7aQV+IOxtWBB8Jww0 SscA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Va3OCSs1QcDZyg3510+KU2IW6XAx9EG+z6fMGugxZKc=; b=M8o+hJh1hN8fa7gth81g/m9sY/gcxa9Xh5q+puuXfuoYs6le8M09El+y+qUQjrO0wk ZZHGvvZHzQox7I59H4dlw+8Bv9ajDAHnHJs7SlzZnbhtBgbgnsfCAA8lmK/gUQZJo7Zt jYZtVKBkYyV9PX9zOg+zoCmKJ6BI2NZ3pzh0623qrPd6Ys3JVwUe+qjzlhk0vKutLtZm tgSVhg3LGHc/ofNBX+f+9m7JxRWYOLgkDdjkIKskT5ZpBHEm4xm7P+9wj0qPdqsrydIQ BHp5vSULRq+dmOZdIVJBZxTMvN3vsaFIZYh+aDf1EbT2SCs4AlMkGBbNezrGzJ9+2VpY 94Og== X-Gm-Message-State: AOAM5309vLOFYAcg0hguiOqo7sqWl0l7obJHaD+/mR/Ln4rYPZucaBVF 2oCPOjdNEA9M7O22+i0gKiIEgV4sDp9DyQ== X-Google-Smtp-Source: ABdhPJzMo97sU2UzPDQQP3TCKqHyMwTreJTMc13pVrdwyRm7kXtteqlI3jJjMnMNJ3f4caQEyVPnmw== X-Received: by 2002:a5d:648f:: with SMTP id o15mr11104694wri.338.1633309930156; Sun, 03 Oct 2021 18:12:10 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id q3sm12384317wmc.25.2021.10.03.18.12.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Oct 2021 18:12:09 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Elijah Newren , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= , =?utf-8?q?Martin_=C3=85gren?= , Andrzej Hunt , Jeff King , Fedor Biryukov , Philip Oakley , Phillip Wood , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= Subject: [RFC PATCH v4 09/10] Comment important codepaths regarding nuking untracked files/dirs Date: Mon, 4 Oct 2021 03:11:58 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.1404.g83021034c5d In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren In the last few commits we focused on code in unpack-trees.c that mistakenly removed untracked files or directories. There may be more of those, but in this commit we change our focus: callers of toplevel commands that are expected to remove untracked files or directories. As noted previously, we have toplevel commands that are expected to delete untracked files such as 'read-tree --reset', 'reset --hard', and 'checkout --force'. However, that does not mean that other highlevel commands that happen to call these other commands thought about or conveyed to users the possibility that untracked files could be removed. Audit the code for such callsites, and add comments near existing callsites to mention whether these are safe or not. My auditing is somewhat incomplete, though; it skipped several cases: * git-rebase--preserve-merges.sh: is in the process of being deprecated/removed, so I won't leave a note that there are likely more bugs in that script. * contrib/git-new-workdir: why is the -f flag being used in a new empty directory?? It shouldn't hurt, but it seems useless. * git-p4.py: Don't see why -f is needed for a new dir (maybe it's not and is just superfluous), but I'm not at all familiar with the p4 stuff * git-archimport.perl: Don't care; arch is long since dead * git-cvs*.perl: Don't care; cvs is long since dead Also, the reset --hard in builtin/worktree.c looks safe, due to only running in an empty directory. Signed-off-by: Elijah Newren Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/stash.c | 1 + builtin/submodule--helper.c | 4 ++++ contrib/rerere-train.sh | 2 +- submodule.c | 1 + 4 files changed, 7 insertions(+), 1 deletion(-) diff --git a/builtin/stash.c b/builtin/stash.c index 061237cf9a4..fabfb63632e 100644 --- a/builtin/stash.c +++ b/builtin/stash.c @@ -1525,6 +1525,7 @@ static int do_push_stash(const struct pathspec *ps, const char *stash_msg, int q } else { struct child_process cp = CHILD_PROCESS_INIT; cp.git_cmd = 1; + /* BUG: this nukes untracked files in the way */ strvec_pushl(&cp.args, "reset", "--hard", "-q", "--no-recurse-submodules", NULL); if (run_command(&cp)) { diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 57f09925157..e40e4b6aacc 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -3091,6 +3091,10 @@ static int add_submodule(const struct add_data *add_data) prepare_submodule_repo_env(&cp.env_array); cp.git_cmd = 1; cp.dir = add_data->sm_path; + /* + * NOTE: we only get here if add_data->force is true, so + * passing --force to checkout is reasonable. + */ strvec_pushl(&cp.args, "checkout", "-f", "-q", NULL); if (add_data->branch) { diff --git a/contrib/rerere-train.sh b/contrib/rerere-train.sh index eeee45dd341..75125d6ae00 100755 --- a/contrib/rerere-train.sh +++ b/contrib/rerere-train.sh @@ -91,7 +91,7 @@ do git checkout -q $commit -- . git rerere fi - git reset -q --hard + git reset -q --hard # Might nuke untracked files... done if test -z "$branch" diff --git a/submodule.c b/submodule.c index 03cf36707ae..9f3d9b7ee73 100644 --- a/submodule.c +++ b/submodule.c @@ -1910,6 +1910,7 @@ static void submodule_reset_index(const char *path) strvec_pushf(&cp.args, "--super-prefix=%s%s/", get_super_prefix_or_empty(), path); + /* TODO: determine if this might overwright untracked files */ strvec_pushl(&cp.args, "read-tree", "-u", "--reset", NULL); strvec_push(&cp.args, empty_tree_oid_hex()); From patchwork Mon Oct 4 01:11:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12533143 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EBAA6C433EF for ; Mon, 4 Oct 2021 01:12:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D5E676115B for ; Mon, 4 Oct 2021 01:12:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232201AbhJDBON (ORCPT ); Sun, 3 Oct 2021 21:14:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38638 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232008AbhJDBOF (ORCPT ); Sun, 3 Oct 2021 21:14:05 -0400 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D9A92C06178C for ; Sun, 3 Oct 2021 18:12:12 -0700 (PDT) Received: by mail-wm1-x336.google.com with SMTP id g193-20020a1c20ca000000b0030d55f1d984so6657575wmg.3 for ; Sun, 03 Oct 2021 18:12:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=AwuJjoOmSdzpgNKRDleD83+86zD1JgmaoRYpkwakrXI=; b=VJeAU+t31fUaYp3ReuP/pMOnLbXVIv2EYkYSptuHVLfrHECnt9t6x1aPSzohjUYtPr oshokNJAZbXHgC2XvsZDPjVgUFvVsuY5Yse6PGpvgBu11KpIwh7r6i0nuUoqWvZW2+dd PiYSA4tWKMVKiAqFSInPm9b23KOKgh7GcBrruzUfWicYIOvpqFKg9nOr1953YRpsLvW7 8wH5vTtHB/XJ994ACjuMR4gf+MK9HQlmB2ojQr4VTXTeJN2t05JsmsW7QmzI+kv5VTF2 9aquYOtGL5DjsG7f+mm717A73eWJvNSiHpIjAJtuikjDUfm7V/QOuqqe3rMX8Ew7OaS5 sJhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=AwuJjoOmSdzpgNKRDleD83+86zD1JgmaoRYpkwakrXI=; b=JY8FtKd65+COTFD3Giiip2JQ6sonq02NT4rh55FGvqaMG6XpqHLFhdnBzhFmIObefs 0PwzKxvsRB2AjMKO9H1cz2EGoFIOcL4JoboqYzPTYC8Lv4zGO1cODdhQnBXDyRHySBjz dejWZx8pLkWEJb0yp0VR9Oepl9b4aF1Sp6XdV8aqritGMHFzFSpq+RWrK/r5pLUcpPoV FOE8h5pNUxNLbbfI6d2tYDSV/HJG4zywBs8gjO2oQhXdbTVhrf6isjvvxGYd5EnembQR H2VrBWU/ynTWIxv6V3JgTG+TmldQFE41wMDRh4+LnvrUwPfUTl7IXkfDv5B5Yi/4JU3j U7sQ== X-Gm-Message-State: AOAM530K0h7stcIyfsJpE3Pqs9TuO8CnC6aef7Yhvzru1IY+O1LYlW5m h6mAw63r7PoKrupy95EIqyDRFOark4cuaQ== X-Google-Smtp-Source: ABdhPJzq9ynnsiAgYZsU9A96N+IIWLxEbw2i03fKYJ6Cz7Wt/bbQpQ9GcD6AHTT8Xd4kLiw6Um7t/w== X-Received: by 2002:a7b:c351:: with SMTP id l17mr15938824wmj.120.1633309931195; Sun, 03 Oct 2021 18:12:11 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id q3sm12384317wmc.25.2021.10.03.18.12.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Oct 2021 18:12:10 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Elijah Newren , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= , =?utf-8?q?Martin_=C3=85gren?= , Andrzej Hunt , Jeff King , Fedor Biryukov , Philip Oakley , Phillip Wood , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= Subject: [RFC PATCH v4 10/10] Documentation: call out commands that nuke untracked files/directories Date: Mon, 4 Oct 2021 03:11:59 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.1404.g83021034c5d In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren Some commands have traditionally also removed untracked files (or directories) that were in the way of a tracked file we needed. Document these cases. Signed-off-by: Elijah Newren Signed-off-by: Ævar Arnfjörð Bjarmason --- Documentation/git-checkout.txt | 5 +++-- Documentation/git-read-tree.txt | 5 +++-- Documentation/git-reset.txt | 3 ++- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/Documentation/git-checkout.txt b/Documentation/git-checkout.txt index b1a6fe44997..d473c9bf387 100644 --- a/Documentation/git-checkout.txt +++ b/Documentation/git-checkout.txt @@ -118,8 +118,9 @@ OPTIONS -f:: --force:: When switching branches, proceed even if the index or the - working tree differs from `HEAD`. This is used to throw away - local changes. + working tree differs from `HEAD`, and even if there are untracked + files in the way. This is used to throw away local changes and + any untracked files or directories that are in the way. + When checking out paths from the index, do not fail upon unmerged entries; instead, unmerged entries are ignored. diff --git a/Documentation/git-read-tree.txt b/Documentation/git-read-tree.txt index 0222a27c5af..8c3aceb8324 100644 --- a/Documentation/git-read-tree.txt +++ b/Documentation/git-read-tree.txt @@ -38,8 +38,9 @@ OPTIONS --reset:: Same as -m, except that unmerged entries are discarded instead - of failing. When used with `-u`, updates leading to loss of - working tree changes will not abort the operation. + of failing. When used with `-u`, updates leading to loss of + working tree changes or untracked files or directories will not + abort the operation. -u:: After a successful merge, update the files in the work diff --git a/Documentation/git-reset.txt b/Documentation/git-reset.txt index 252e2d4e47d..6f7685f53d5 100644 --- a/Documentation/git-reset.txt +++ b/Documentation/git-reset.txt @@ -69,7 +69,8 @@ linkgit:git-add[1]). --hard:: Resets the index and working tree. Any changes to tracked files in the - working tree since `` are discarded. + working tree since `` are discarded. Any untracked files or + directories in the way of writing any tracked files are simply deleted. --merge:: Resets the index and updates the files in the working tree that are