From patchwork Tue Jul 19 13:28:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shaoxuan Yuan X-Patchwork-Id: 12922588 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E404DC433EF for ; Tue, 19 Jul 2022 14:10:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238843AbiGSOK1 (ORCPT ); Tue, 19 Jul 2022 10:10:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41722 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238832AbiGSOKL (ORCPT ); Tue, 19 Jul 2022 10:10:11 -0400 Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7663558C5 for ; Tue, 19 Jul 2022 06:28:55 -0700 (PDT) Received: by mail-pj1-x102d.google.com with SMTP id s21so14707448pjq.4 for ; Tue, 19 Jul 2022 06:28:55 -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=ZYBSi74GfGuu3qxJxRKdH6JFmWGBv1dEXqpD4MhYV+c=; b=eeByAxzFkqsyfHkIBj0bfpYE8HEKmGZ2MBG6To+lUVoqQ+1eHxofnQbPEhD/i6ZSl7 IBwUmZF/UYZ0yheCuDAOMWIHSYJ3SUkXY9/GcnJHY/GFsYvIbkKUkcLCdsW+sHvIcOPE x2PVYTqjh3hkdUPB0PrVRAGA9L2t0LCOy4mZCAFiS8L/YKFNYr3KnzCP/+p8/+UcnCYw EqjevzbbyVqxc+aBZBb8YWImV7Tu3q0YcIFXi/2k1eWSzaUbNAv9HJ6sTO/fHhEifOi0 2faZcmWRisID2jW3UF4U8STpDKgWGJapBHumBprDNcySyd13SZZAH6E9rBKxpIRNXFsn 6cHg== 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=ZYBSi74GfGuu3qxJxRKdH6JFmWGBv1dEXqpD4MhYV+c=; b=CpsPY8snHH9TRJRt7BPWs/ZApuXnqSRLHN3KWsC99YdhrCEjBFD4h4At2eYOFMRQEB ucUs6AsfO31z5dpzyIF7rAbl17Acqu64u7nIByEMwy91OLKoPuN0GgyeevPqQv3JfWeQ HrObfIMgb336eSOZ7arjUzx+2LWm+M7FPuT8Y2HAvzGqHPF90ODSMDQKSRfC0xGJVoRn oMtfFrhm7WVG944teL+lsjkLMapAzpgOg3TqEKBHsZhj87HEfTjj03GisUuFoaOwZUlT OgBVdIKauvu+C46QuLtYlagBqWyJoVXsv1b5mEP52cOtnjObjphGqZk9ZiXFKR/9Mjup hlww== X-Gm-Message-State: AJIora+Zh1k4Kvc7GZ3dzGHMsssI0/RR3qh2tqz2pdbEgz85MJ/wG8EE DesphSc53tp5KvkJMPiI/Y4rx6xKEbze5uc9 X-Google-Smtp-Source: AGRyM1sp7GMiR+iYoE//FxIaWJ2f3tX6IOVVQXttYGcRoNaN/0h7iVF40L3X8VdLKmnkYF45mptaVg== X-Received: by 2002:a17:902:e84e:b0:16c:773:9daf with SMTP id t14-20020a170902e84e00b0016c07739dafmr33521958plg.43.1658237335114; Tue, 19 Jul 2022 06:28:55 -0700 (PDT) Received: from ffyuanda.localdomain ([101.206.227.243]) by smtp.gmail.com with ESMTPSA id r9-20020a170902be0900b0016be834d544sm624424pls.237.2022.07.19.06.28.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Jul 2022 06:28:54 -0700 (PDT) From: Shaoxuan Yuan To: git@vger.kernel.org Cc: vdye@github.com, derrickstolee@github.com, gitster@pobox.com, Shaoxuan Yuan Subject: [PATCH v1 1/7] t7002: add tests for moving from in-cone to out-of-cone Date: Tue, 19 Jul 2022 21:28:03 +0800 Message-Id: <20220719132809.409247-2-shaoxuan.yuan02@gmail.com> X-Mailer: git-send-email 2.37.0 In-Reply-To: <20220719132809.409247-1-shaoxuan.yuan02@gmail.com> References: <20220719132809.409247-1-shaoxuan.yuan02@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Add corresponding tests to test that user can move an in-cone to out-of-cone when --sparse is supplied. Such can be either clean or dirty, and moving it results in different behaviors: A clean move should move the to the , both in the working tree and the index, then remove the resulted path from the working tree, and turn on its CE_SKIP_WORKTREE bit. A dirty move should move the to the , both in the working tree and the index, but should *not* remove the resulted path from the working tree and should *not* turn on its CE_SKIP_WORKTREE bit. Instead advise user to "git add" this path and run "git sparse-checkout reapply" to re-sparsify that path. Also make sure that if exists in the index (existing check for if is in the worktree is not enough in in-to-out moves), warn user against the overwrite. And Git should force the overwrite when supplied with -f or --force. Signed-off-by: Shaoxuan Yuan --- t/t7002-mv-sparse-checkout.sh | 148 +++++++++++++++++++++++++++++++++- 1 file changed, 147 insertions(+), 1 deletion(-) diff --git a/t/t7002-mv-sparse-checkout.sh b/t/t7002-mv-sparse-checkout.sh index 71fe29690f..c27fcdbfd0 100755 --- a/t/t7002-mv-sparse-checkout.sh +++ b/t/t7002-mv-sparse-checkout.sh @@ -28,12 +28,25 @@ test_expect_success 'setup' " updated in the index: EOF - cat >sparse_hint <<-EOF + cat >sparse_hint <<-EOF && hint: If you intend to update such entries, try one of the following: hint: * Use the --sparse option. hint: * Disable or modify the sparsity rules. hint: Disable this message with \"git config advice.updateSparsePath false\" EOF + + cat >dirty_error_header <<-EOF && + The following paths have been moved outside the + sparse-checkout definition but are not sparse due to local + modifications. + EOF + + cat >dirty_hint <<-EOF + hint: To correct the sparsity of these paths, do the following: + hint: * Use \"git add --sparse \" to update the index + hint: * Use \"git sparse-checkout reapply\" to apply the sparsity rules + hint: Disable this message with \"git config advice.updateSparsePath false\" + EOF " test_expect_success 'mv refuses to move sparse-to-sparse' ' @@ -290,4 +303,137 @@ test_expect_success 'move sparse file to existing destination with --force and - test_cmp expect sub/file1 ' +test_expect_failure 'move clean path from in-cone to out-of-cone' ' + test_when_finished "cleanup_sparse_checkout" && + setup_sparse_checkout && + + test_must_fail git mv sub/d folder1 2>stderr && + cat sparse_error_header >expect && + echo "folder1/d" >>expect && + cat sparse_hint >>expect && + test_cmp expect stderr && + + git mv --sparse sub/d folder1 2>stderr && + test_must_be_empty stderr && + + test_path_is_missing sub/d && + test_path_is_missing folder1/d && + git ls-files -t >actual && + ! grep -x "H sub/d" actual && + grep -x "S folder1/d" actual +' + +test_expect_failure 'move clean path from in-cone to out-of-cone overwrite' ' + test_when_finished "cleanup_sparse_checkout" && + setup_sparse_checkout && + echo "sub/file1 overwrite" >sub/file1 && + git add sub/file1 && + + test_must_fail git mv sub/file1 folder1 2>stderr && + cat sparse_error_header >expect && + echo "folder1/file1" >>expect && + cat sparse_hint >>expect && + test_cmp expect stderr && + + test_must_fail git mv --sparse sub/file1 folder1 2>stderr && + echo "fatal: destination exists in the index, source=sub/file1, destination=folder1/file1" \ + >expect && + test_cmp expect stderr && + + git mv --sparse -f sub/file1 folder1 2>stderr && + test_must_be_empty stderr && + + test_path_is_missing sub/file1 && + test_path_is_missing folder1/file1 && + git ls-files -t >actual && + ! grep -x "H sub/file1" actual && + grep -x "S folder1/file1" actual && + + # compare file content before move and after move + echo "sub/file1 overwrite" >expect && + git ls-files -s -- folder1/file1 | awk "{print \$2}" >oid && + git cat-file blob $(cat oid) >actual && + test_cmp expect actual +' + +test_expect_failure 'move dirty path from in-cone to out-of-cone' ' + test_when_finished "cleanup_sparse_checkout" && + setup_sparse_checkout && + echo "modified" >>sub/d && + + test_must_fail git mv sub/d folder1 2>stderr && + cat sparse_error_header >expect && + echo "folder1/d" >>expect && + cat sparse_hint >>expect && + test_cmp expect stderr && + + git mv --sparse sub/d folder1 2>stderr && + cat dirty_error_header >expect && + echo "folder1/d" >>expect && + cat dirty_hint >>expect && + test_cmp expect stderr && + + test_path_is_missing sub/d && + test_path_is_file folder1/d && + git ls-files -t >actual && + ! grep -x "H sub/d" actual && + grep -x "H folder1/d" actual +' + +test_expect_failure 'move dir from in-cone to out-of-cone' ' + test_when_finished "cleanup_sparse_checkout" && + setup_sparse_checkout && + + test_must_fail git mv sub/dir folder1 2>stderr && + cat sparse_error_header >expect && + echo "folder1/dir/e" >>expect && + cat sparse_hint >>expect && + test_cmp expect stderr && + + git mv --sparse sub/dir folder1 2>stderr && + test_must_be_empty stderr && + + test_path_is_missing sub/dir && + test_path_is_missing folder1 && + git ls-files -t >actual && + ! grep -x "H sub/dir/e" actual && + grep -x "S folder1/dir/e" actual +' + +test_expect_failure 'move partially-dirty dir from in-cone to out-of-cone' ' + test_when_finished "cleanup_sparse_checkout" && + setup_sparse_checkout && + touch sub/dir/e2 sub/dir/e3 && + git add sub/dir/e2 sub/dir/e3 && + echo "modified" >>sub/dir/e2 && + echo "modified" >>sub/dir/e3 && + + test_must_fail git mv sub/dir folder1 2>stderr && + cat sparse_error_header >expect && + echo "folder1/dir/e" >>expect && + echo "folder1/dir/e2" >>expect && + echo "folder1/dir/e3" >>expect && + cat sparse_hint >>expect && + test_cmp expect stderr && + + git mv --sparse sub/dir folder1 2>stderr && + cat dirty_error_header >expect && + echo "folder1/dir/e2" >>expect && + echo "folder1/dir/e3" >>expect && + cat dirty_hint >>expect && + test_cmp expect stderr && + + test_path_is_missing sub/dir && + test_path_is_missing folder1/dir/e && + test_path_is_file folder1/dir/e2 && + test_path_is_file folder1/dir/e3 && + git ls-files -t >actual && + ! grep -x "H sub/dir/e" actual && + ! grep -x "H sub/dir/e2" actual && + ! grep -x "H sub/dir/e3" actual && + grep -x "S folder1/dir/e" actual && + grep -x "H folder1/dir/e2" actual && + grep -x "H folder1/dir/e3" actual +' + test_done From patchwork Tue Jul 19 13:28:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shaoxuan Yuan X-Patchwork-Id: 12922589 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6858FC433EF for ; Tue, 19 Jul 2022 14:10:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238972AbiGSOK3 (ORCPT ); Tue, 19 Jul 2022 10:10:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42444 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238834AbiGSOKM (ORCPT ); Tue, 19 Jul 2022 10:10:12 -0400 Received: from mail-pf1-x42b.google.com (mail-pf1-x42b.google.com [IPv6:2607:f8b0:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A174D550BE for ; Tue, 19 Jul 2022 06:28:57 -0700 (PDT) Received: by mail-pf1-x42b.google.com with SMTP id d10so13518281pfd.9 for ; Tue, 19 Jul 2022 06:28:57 -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=b9QsySwOcVZTcFRawWKLXMNfFKp3pFjxtFgTd/+q8Uo=; b=BiDuytAFGaHCeal319AkUwPcXy8GpHo4gXlvuoXfAIbLLE0+U4MbeAr1wnuBvwbGDp jKiAWDERO3OyiZG/Y1D+UyO5QBB37GshF0BSGVCaX/etitFnsQWyiSnN4luGMPgagijM znV13e4mWkp+WoOSwOtunx0hp2bl1v4y3KfEh+fP9OpawOhP/35TxhqJQw+Th0K1zMyy QKQCVY0D/SuQPYTxYqIbQHzfbaE6C4isyciliTfonjfCyRzi9vMnvni+y+P9z51b6YJr 9i8FenmODPZDHHr0LeZeFHITL1lkinW8smw8fhY0kPtYR9pale4aqOyjV7xMmwnW1r3X Rj0w== 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=b9QsySwOcVZTcFRawWKLXMNfFKp3pFjxtFgTd/+q8Uo=; b=cu0k1SGzgIOjGbbqH9gm44BcsHu/ur/FtGNAF61dLjI/wKQFQgwBiBbX0aqnTX7qeY 11m6dzo+cDGueUwqOsZjFCs2RVB52ZeHxF819ldHiLjtWiWhlC2uND7IKW4fpZO2+V6y GT6nt2skq7krD8ux96MgN2VDUH9BfwuYecnQeVArKA4gb1ZWyNweJ11jI+Hz3IXou/JJ QQM8wHnYgVStnS6chWuEcTXcezzFWLq3Bt5dPvEdrP3omFZgN1Lkudd/eB/9U+evByxb ZtV/ZeWiaXFqk0+EKQT5N6WrfsWRnw9eZN3TDduF6RGSSrL5jFqKy1TNHLmKqloH+L+5 oxJg== X-Gm-Message-State: AJIora9T5gAR/sVtmx23dQ100CeAxs6mpe0lckhnvfCrGFrb/c5LdFJY +e3are1UISlmb+w3N8oNATR7hAb2jgQSoqZc X-Google-Smtp-Source: AGRyM1uRaT1MsCM92WM4DrQdSIT49laFkNySFJGC0QXGyi+UeonFD2iKp4ms27orS5UbTOLAFnjbpg== X-Received: by 2002:a63:8841:0:b0:412:b40b:cfb5 with SMTP id l62-20020a638841000000b00412b40bcfb5mr30125735pgd.197.1658237336994; Tue, 19 Jul 2022 06:28:56 -0700 (PDT) Received: from ffyuanda.localdomain ([101.206.227.243]) by smtp.gmail.com with ESMTPSA id r9-20020a170902be0900b0016be834d544sm624424pls.237.2022.07.19.06.28.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Jul 2022 06:28:56 -0700 (PDT) From: Shaoxuan Yuan To: git@vger.kernel.org Cc: vdye@github.com, derrickstolee@github.com, gitster@pobox.com, Shaoxuan Yuan Subject: [PATCH v1 2/7] mv: add documentation for check_dir_in_index() Date: Tue, 19 Jul 2022 21:28:04 +0800 Message-Id: <20220719132809.409247-3-shaoxuan.yuan02@gmail.com> X-Mailer: git-send-email 2.37.0 In-Reply-To: <20220719132809.409247-1-shaoxuan.yuan02@gmail.com> References: <20220719132809.409247-1-shaoxuan.yuan02@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Using check_dir_in_index without checking if the directory is on-disk could get a false positive for partially sparsified directory. Add a note in the documentation to warn potential user. Signed-off-by: Shaoxuan Yuan --- builtin/mv.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/builtin/mv.c b/builtin/mv.c index 4729bb1a1a..c8b9069db8 100644 --- a/builtin/mv.c +++ b/builtin/mv.c @@ -132,6 +132,11 @@ static int index_range_of_same_dir(const char *src, int length, * Return 0 if such directory exist (i.e. with any of its contained files not * marked with CE_SKIP_WORKTREE, the directory would be present in working tree). * Return 1 otherwise. + * + * Note: *always* check the directory is not on-disk before this function + * (i.e. using lstat()); + * otherwise it may return a false positive for a partially sparsified + * directory. */ static int check_dir_in_index(const char *name) { From patchwork Tue Jul 19 13:28:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shaoxuan Yuan X-Patchwork-Id: 12922591 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CF30EC43334 for ; Tue, 19 Jul 2022 14:10:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239009AbiGSOKe (ORCPT ); Tue, 19 Jul 2022 10:10:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45174 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238854AbiGSOKM (ORCPT ); Tue, 19 Jul 2022 10:10:12 -0400 Received: from mail-pg1-x530.google.com (mail-pg1-x530.google.com [IPv6:2607:f8b0:4864:20::530]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A336A4D4DA for ; Tue, 19 Jul 2022 06:28:59 -0700 (PDT) Received: by mail-pg1-x530.google.com with SMTP id o18so13463741pgu.9 for ; Tue, 19 Jul 2022 06:28:59 -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=dlNEvhIJLmX7y4XPjfnzdGR+FaGJHlapW3spqnQxAMk=; b=Lz5NDrrGXQlmuH+pRKzQcjHMM9lsHaOhw2gwVNysl8vel055vWHPhX1HUOgNzNDPsT 0Y/QIdzOmCvENK9CYQvaJZkXkVMAsFKEqDXz/Q0ZzkfUgZD+MrqD6Kb0jPWLZicDuzk+ ZEFiV0asKcel2rS4UIfaUN9r4qRnc2ktwGiGbrwZ3PkFwyLiI84y/PWaicB5ucymV+ZR NOWC160UDpC1E2dY2Unuadr/vYuZqmP47MtGp3nx/vvxk8eS6ardbN42OXh4C5+NQpdY GBznuaSLgVEwwV5+sdcZqpx1FBoUIcYgaa9laW4qVUggyUzZ9Fd72FlCFe1X/YHz0OyV LjJQ== 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=dlNEvhIJLmX7y4XPjfnzdGR+FaGJHlapW3spqnQxAMk=; b=4YyHsa8fqmWIBkkgagLHZQAPCAv9GTIOdjVytevQ0+OIBR4ILiCBaquJPA733i7zP+ 3/ieslLJ0196dgmjEXoQtl8h36L2+l8HrI3utpdAgmkYuH6Rhsj3wh0LYqZPWjcqpIWT YON1SWoojie98TilEWn7JCcyc20zNgd51J0Ng24UI6KU8AC+gzVFkOQcLskvxaHh+ZE6 RMR8zpq/O1EJKYRRzKJ6o+Zwl+PjosMHjSAa4FxSyp5ki+YL91zVWw6Ud7GQXoiHWoOY uPeI7D+NT4t8m5naToVbJel7ICGWRfNUVspaazKzFT4cpVmfRnujsg/4VmY2wW9NSVNS b1nQ== X-Gm-Message-State: AJIora94ZU5ze/uT9e88bMC1jayda4S/qHqpUtd6b50MNgY+h6f8A/2m SwzC/EKjaSK7OKMCDSAlG0qViOez2iObAafy X-Google-Smtp-Source: AGRyM1u5YmOY2viCgnhxO8Al+g5lDSDLQXdqO9xHcR7MCj9Iv0PUUPy1iUhLSzh2sbx+7KtAfANaMQ== X-Received: by 2002:a63:e252:0:b0:41a:4df2:13ed with SMTP id y18-20020a63e252000000b0041a4df213edmr2088196pgj.113.1658237338990; Tue, 19 Jul 2022 06:28:58 -0700 (PDT) Received: from ffyuanda.localdomain ([101.206.227.243]) by smtp.gmail.com with ESMTPSA id r9-20020a170902be0900b0016be834d544sm624424pls.237.2022.07.19.06.28.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Jul 2022 06:28:58 -0700 (PDT) From: Shaoxuan Yuan To: git@vger.kernel.org Cc: vdye@github.com, derrickstolee@github.com, gitster@pobox.com, Shaoxuan Yuan Subject: [PATCH v1 3/7] mv: free the *with_slash in check_dir_in_index() Date: Tue, 19 Jul 2022 21:28:05 +0800 Message-Id: <20220719132809.409247-4-shaoxuan.yuan02@gmail.com> X-Mailer: git-send-email 2.37.0 In-Reply-To: <20220719132809.409247-1-shaoxuan.yuan02@gmail.com> References: <20220719132809.409247-1-shaoxuan.yuan02@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org *with_slash may be a malloc'd pointer, and when it is, free it. Signed-off-by: Shaoxuan Yuan --- builtin/mv.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/builtin/mv.c b/builtin/mv.c index c8b9069db8..23a297d6b8 100644 --- a/builtin/mv.c +++ b/builtin/mv.c @@ -140,6 +140,7 @@ static int index_range_of_same_dir(const char *src, int length, */ static int check_dir_in_index(const char *name) { + int ret = 1; const char *with_slash = add_slash(name); int length = strlen(with_slash); @@ -149,14 +150,18 @@ static int check_dir_in_index(const char *name) if (pos < 0) { pos = -pos - 1; if (pos >= the_index.cache_nr) - return 1; + goto free_return; ce = active_cache[pos]; if (strncmp(with_slash, ce->name, length)) - return 1; + goto free_return; if (ce_skip_worktree(ce)) - return 0; + ret = 0; } - return 1; + +free_return: + if (with_slash != name) + free((char *)with_slash); + return ret; } int cmd_mv(int argc, const char **argv, const char *prefix) From patchwork Tue Jul 19 13:28:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shaoxuan Yuan X-Patchwork-Id: 12922593 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8697BC43334 for ; Tue, 19 Jul 2022 14:10:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238479AbiGSOKh (ORCPT ); Tue, 19 Jul 2022 10:10:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44136 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238875AbiGSOKN (ORCPT ); Tue, 19 Jul 2022 10:10:13 -0400 Received: from mail-pf1-x42b.google.com (mail-pf1-x42b.google.com [IPv6:2607:f8b0:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C2E28558CF for ; Tue, 19 Jul 2022 06:29:01 -0700 (PDT) Received: by mail-pf1-x42b.google.com with SMTP id l124so13511359pfl.8 for ; Tue, 19 Jul 2022 06:29:01 -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=rYXym/+opy3nmKeEok8SGg0UamikXOVHzY0az9xgUMc=; b=as+KuAAhSkxy6HhrH06ElOpJx55nBjey8peL1jCveDaVukFve5Ga45L9Mx2cmHFIbh ilxqWmEVPEG53V/2Y0pskUlMXpeThBVEYlNcEyL4E286HYv6pTa4+l6jVEzBfHzT4mVB Bx1p9T76UPDuw8iJJRV5UwaK7488D+LbtN8jlLTFohiX57GrqAxTUMo39GaW+b5PNCB6 vCLa2gneKMtVZXRRxUi25ZSDz41Co8DwweJqG5JzlqHsUaB+vNfCCYfa2EjMkXs1Mfc8 i6+4lHpTIrpnnz6XvBKDI8JfZ986OHeXzcNDDFqx6D7aADDtXX9+IiHQ5QthL5wJkfIr kLOQ== 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=rYXym/+opy3nmKeEok8SGg0UamikXOVHzY0az9xgUMc=; b=dnpPvKLvfx0mqsJQscvfVfX9imNCOn74HpBPOA2wqBickRUh3uG1Sq9JPU7Z0bfx55 p9FKSTfpYa0ucDMZSW+aOOZowEVUCGIoNCUp/W+DONhvk8KAv2WF/DxEJX4KxSM4n0it TGOeo0xtkFTInr4+/XY3QttD6402FxVvpJ8XMkD1EhS2MuUjOAbhHffnkNdQG5LLqPi5 Xb61BG6BYjkDedPIVxh4CF2F6xBDipuUZqy9WEAJGCoWSAvkUl7oxrmCKsVjJ3WrOHBc zOgIcWdbzLGddutBk2AyViu6/5CurzN6xfxN8JwvHUcgSnrQFJBRyZwC7eWWOacvgpug TfLw== X-Gm-Message-State: AJIora+91vPCqdppUVu61xGL8iOA05vkVLkpPFMMZn5Ea2QVTdyjsXpw ht9goN/0uqcaZcVXehDqZBLSp2LpsNegWsdD X-Google-Smtp-Source: AGRyM1tqHhy9mBRq50/dxfTLKZxqPapgHWYWc1XVfqHWxgoT9mmueNgOyC3CpoBx32AckHoXJnENCA== X-Received: by 2002:a63:5f4e:0:b0:417:ba9d:c513 with SMTP id t75-20020a635f4e000000b00417ba9dc513mr29580467pgb.434.1658237341120; Tue, 19 Jul 2022 06:29:01 -0700 (PDT) Received: from ffyuanda.localdomain ([101.206.227.243]) by smtp.gmail.com with ESMTPSA id r9-20020a170902be0900b0016be834d544sm624424pls.237.2022.07.19.06.28.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Jul 2022 06:29:00 -0700 (PDT) From: Shaoxuan Yuan To: git@vger.kernel.org Cc: vdye@github.com, derrickstolee@github.com, gitster@pobox.com, Shaoxuan Yuan Subject: [PATCH v1 4/7] mv: check if is a SKIP_WORKTREE_DIR Date: Tue, 19 Jul 2022 21:28:06 +0800 Message-Id: <20220719132809.409247-5-shaoxuan.yuan02@gmail.com> X-Mailer: git-send-email 2.37.0 In-Reply-To: <20220719132809.409247-1-shaoxuan.yuan02@gmail.com> References: <20220719132809.409247-1-shaoxuan.yuan02@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Originally, is assumed to be in the working tree. If it is not found as a directory, then it is determined to be either a regular file path, or error out if used under the second form (move into a directory) of 'git-mv'. Such behavior is not ideal, mainly because Git does not look into the index for , which could potentially be a SKIP_WORKTREE_DIR, which we need to determine for the later "moving from in-cone to out-of-cone" patch. Change the logic so that Git first check if is a directory with all its contents sparsified (a SKIP_WORKTREE_DIR). If yes, then treat as a directory exists in the working tree, and thus using the second form of 'git-mv', i.e. move into this , and mark as a SKIP_WORKTREE_DIR. If no, continue the original checking logic. Also add a `dst_w_slash` to reuse the result from `add_slash()`, which was everywhere and can be simplified. Signed-off-by: Shaoxuan Yuan --- builtin/mv.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/builtin/mv.c b/builtin/mv.c index 23a297d6b8..2e9d577227 100644 --- a/builtin/mv.c +++ b/builtin/mv.c @@ -178,7 +178,8 @@ int cmd_mv(int argc, const char **argv, const char *prefix) OPT_END(), }; const char **source, **destination, **dest_path, **submodule_gitfile; - enum update_mode *modes; + const char *dst_w_slash; + enum update_mode *modes, dst_mode = 0; struct stat st; struct string_list src_for_dst = STRING_LIST_INIT_NODUP; struct lock_file lock_file = LOCK_INIT; @@ -208,6 +209,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix) if (argc == 1 && is_directory(argv[0]) && !is_directory(argv[1])) flags = 0; dest_path = internal_prefix_pathspec(prefix, argv + argc, 1, flags); + dst_w_slash = add_slash(dest_path[0]); submodule_gitfile = xcalloc(argc, sizeof(char *)); if (dest_path[0][0] == '\0') @@ -215,13 +217,20 @@ int cmd_mv(int argc, const char **argv, const char *prefix) destination = internal_prefix_pathspec(dest_path[0], argv, argc, DUP_BASENAME); else if (!lstat(dest_path[0], &st) && S_ISDIR(st.st_mode)) { - dest_path[0] = add_slash(dest_path[0]); - destination = internal_prefix_pathspec(dest_path[0], argv, argc, DUP_BASENAME); + destination = internal_prefix_pathspec(dst_w_slash, argv, argc, DUP_BASENAME); } else { - if (argc != 1) + if (!path_in_sparse_checkout(dst_w_slash, &the_index) && + !check_dir_in_index(dst_w_slash)) { + destination = internal_prefix_pathspec(dst_w_slash, argv, argc, DUP_BASENAME); + dst_mode |= SKIP_WORKTREE_DIR; + } else if (argc != 1) { die(_("destination '%s' is not a directory"), dest_path[0]); - destination = dest_path; + } else { + destination = dest_path; + } } + if (dst_w_slash != dest_path[0]) + free((char *)dst_w_slash); /* Checking */ for (i = 0; i < argc; i++) { From patchwork Tue Jul 19 13:28:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shaoxuan Yuan X-Patchwork-Id: 12922592 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2BD07CCA47F for ; Tue, 19 Jul 2022 14:10:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238896AbiGSOKg (ORCPT ); Tue, 19 Jul 2022 10:10:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44314 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238864AbiGSOKN (ORCPT ); Tue, 19 Jul 2022 10:10:13 -0400 Received: from mail-pl1-x62b.google.com (mail-pl1-x62b.google.com [IPv6:2607:f8b0:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DE84A664C2 for ; Tue, 19 Jul 2022 06:29:03 -0700 (PDT) Received: by mail-pl1-x62b.google.com with SMTP id z1so11959386plb.1 for ; Tue, 19 Jul 2022 06:29:03 -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=zgaoGiB2Kf3OuCcRTLdGJUx9rzt8YmZKI0IFLSLl510=; b=PpYRATyWU3ygx3tqw2p/5bxNSf5ono71pPEaYP8CGADbqubsOLOb5eNdFIUxYyN1iv mRahjjNfk7XnJlu3jnvZSNZu/Wd1ZqK0ew3ps2Mhvp4bXCWLo3jt2zTZQatUZbbQu9f8 A+4i9jxhe4C4/eS+CkJz3eg/iEFy0rZbniRBTj4JXEV0PZCUyc1CnAxbxQTgwftWouaJ otqvmnH2GDW80pcfBCWH9ecYHw7dtMwhnvCO53kyFrJtqa9Qq3OdWR7rwZEij/O/nCqz ww497Z9c2w+1VNa8+uVykLWWFYksSSo7SyLEETiE2Tk26NHAchyf4FMzHyQSBpuEwZfc RcUQ== 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=zgaoGiB2Kf3OuCcRTLdGJUx9rzt8YmZKI0IFLSLl510=; b=dugT53IM2o8yIy1CtC7wgaIAQMBjz0w6Q99Wo0CQ8dItva7mGUxpcl9wzgFkfDsTPu 6pptSpTctxnKykivJiDQO1U3XK09j+3/6IwV2g7ay6lzQqtIjTcOn4LMfNrzteatSCxJ 9bhR0Qkbe9lKfEDf/AE7vi/dqPpo9bCZdJhvMBSEJyiIt/QMAyHQyB2Wkx3V+SJNK1RT ovBdaPpSjaX4h9y0QA6CwJj9DR6hpLxpiNJVWnu6WmtaP71Wxg+MKtLiSi1FCl2iQXES hYgFhXxjyO02KxkqUakidZjMD6o0TuBOINgQsShlUAp9VYEJuhbF0EPD5NmggpPBWDDA UmuA== X-Gm-Message-State: AJIora/4giVAVbek0KFq1PRnR5hDJ4s7JTh6UA0vg+viFkP8W9/Agvm1 vtOT+wsMpA7pyoEwnvndyiqmgKJ9JWFCUxmk X-Google-Smtp-Source: AGRyM1s07OhguYQs5tV3ucz3EYGgGo9ecZsOXEcsrgyzVS6TckfWI0FgPIzcYBcWg8dWbJ3s2K9Q3g== X-Received: by 2002:a17:90a:2c0d:b0:1ef:c839:c34b with SMTP id m13-20020a17090a2c0d00b001efc839c34bmr45520873pjd.39.1658237343236; Tue, 19 Jul 2022 06:29:03 -0700 (PDT) Received: from ffyuanda.localdomain ([101.206.227.243]) by smtp.gmail.com with ESMTPSA id r9-20020a170902be0900b0016be834d544sm624424pls.237.2022.07.19.06.29.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Jul 2022 06:29:02 -0700 (PDT) From: Shaoxuan Yuan To: git@vger.kernel.org Cc: vdye@github.com, derrickstolee@github.com, gitster@pobox.com, Shaoxuan Yuan Subject: [PATCH v1 5/7] mv: remove BOTH from enum update_mode Date: Tue, 19 Jul 2022 21:28:07 +0800 Message-Id: <20220719132809.409247-6-shaoxuan.yuan02@gmail.com> X-Mailer: git-send-email 2.37.0 In-Reply-To: <20220719132809.409247-1-shaoxuan.yuan02@gmail.com> References: <20220719132809.409247-1-shaoxuan.yuan02@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Since BOTH is not practically used anywhere in the code and its meaning is unclear, remove it. Signed-off-by: Shaoxuan Yuan --- builtin/mv.c | 1 - 1 file changed, 1 deletion(-) diff --git a/builtin/mv.c b/builtin/mv.c index 2e9d577227..d05914a233 100644 --- a/builtin/mv.c +++ b/builtin/mv.c @@ -21,7 +21,6 @@ static const char * const builtin_mv_usage[] = { }; enum update_mode { - BOTH = 0, WORKING_DIRECTORY = (1 << 1), INDEX = (1 << 2), SPARSE = (1 << 3), From patchwork Tue Jul 19 13:28:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shaoxuan Yuan X-Patchwork-Id: 12922594 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EF545CCA47F for ; Tue, 19 Jul 2022 14:10:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238875AbiGSOKj (ORCPT ); Tue, 19 Jul 2022 10:10:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50730 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238887AbiGSOKO (ORCPT ); Tue, 19 Jul 2022 10:10:14 -0400 Received: from mail-pj1-x102f.google.com (mail-pj1-x102f.google.com [IPv6:2607:f8b0:4864:20::102f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CCD68664C3 for ; Tue, 19 Jul 2022 06:29:05 -0700 (PDT) Received: by mail-pj1-x102f.google.com with SMTP id q13-20020a17090a304d00b001f1af9a18a2so7241579pjl.5 for ; Tue, 19 Jul 2022 06:29: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=qVA8khSqd33XdWY34IuU/S0gTQ1wMFeJ33gIBC4cFig=; b=RgdpHvktMRzWpWP7zPZYyT9qXq+wbWsKeNdNNKv8qdkWV4lKx3uTEmtdKHRaBG5sAr xRdi6QoBST3eRui+VGyhpNuQDT/qs6s7H2dYuxIBmG950fJixCRIP829TZ4aXdcQh4o3 zg6ofkVN+29CP8FlbhZDWksqXdiJxfX4CR23Lc7MTiDaWJJwDExrc4osWNGhrRkc/KLd Q9vkMM1gf4a3m0R+XM7Dn1KzPV7BEdMp0vlWn3XVgGhwL7UVZSMTMriv/PwnfI4XcjeZ I27fUATolvgYeJEss3VUuqsbvUWZmJbRBBA9jSMJDzaDiu1ondDF4gZOcEPC4dTGrgYp qIjg== 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=qVA8khSqd33XdWY34IuU/S0gTQ1wMFeJ33gIBC4cFig=; b=wS4/Nqts7jOYS4/W8RM8W79Zfv1eRwsdt91wXQwMk0eP9lYBepvVvh5j4a2VDNAB6R dTdlB7/QwZM6Ovg8WVhHyRQA+UY57VWJEEaeottikWOmxk9Yi4iLxnLYHRXaTbAVAJ0I VXDNw9+ko6Guf3tP/ZJ09+F6ds79m341POMFBGrRKlwS7t4sRFboNTTIy33pJEFAWrqK IgaMJuhU3D+bWDeCPzkK8p+p9Ldp9I4exQJKerdSvGWz930gG7q7efR+WjLnZhz9vk/q twJUFnB/3kmwNTsOuu0ybdMKB4clL+144t1A7U263E1dFDsH3/5RzVtvP9SSMbDuqw4f /tMg== X-Gm-Message-State: AJIora91ITSrJHk2cRFVC4jwKPXPlO20oSgBvohyJVWIu+uef80NgeDU ZJNzRe1me9rv40KK6YOcMOKsLRA6TqHXiR75 X-Google-Smtp-Source: AGRyM1tbQ0TYh96VVoeGI8Z5gkeXxfqbb6a4e5uA33D1dpr52XjZPfAVfRh7xhu4vJsVeX03x4RQ4w== X-Received: by 2002:a17:902:f60c:b0:16d:1af0:6656 with SMTP id n12-20020a170902f60c00b0016d1af06656mr237287plg.153.1658237345129; Tue, 19 Jul 2022 06:29:05 -0700 (PDT) Received: from ffyuanda.localdomain ([101.206.227.243]) by smtp.gmail.com with ESMTPSA id r9-20020a170902be0900b0016be834d544sm624424pls.237.2022.07.19.06.29.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Jul 2022 06:29:04 -0700 (PDT) From: Shaoxuan Yuan To: git@vger.kernel.org Cc: vdye@github.com, derrickstolee@github.com, gitster@pobox.com, Shaoxuan Yuan Subject: [PATCH v1 6/7] mv: from in-cone to out-of-cone Date: Tue, 19 Jul 2022 21:28:08 +0800 Message-Id: <20220719132809.409247-7-shaoxuan.yuan02@gmail.com> X-Mailer: git-send-email 2.37.0 In-Reply-To: <20220719132809.409247-1-shaoxuan.yuan02@gmail.com> References: <20220719132809.409247-1-shaoxuan.yuan02@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Originally, moving an in-cone to an out-of-cone was not possible, mainly because such is a directory that is not present in the working tree. Change the behavior so that we can move an in-cone to out-of-cone when --sparse is supplied. Such can be either clean or dirty, and moving it results in different behaviors: A clean move should move the to the , both in the working tree and the index, then remove the resulted path from the working tree, and turn on its CE_SKIP_WORKTREE bit. A dirty move should move the to the , both in the working tree and the index, but should *not* remove the resulted path from the working tree and should *not* turn on its CE_SKIP_WORKTREE bit. Instead advise user to "git add" this path and run "git sparse-checkout reapply" to re-sparsify that path. Helped-by: Victoria Dye Signed-off-by: Shaoxuan Yuan --- advice.c | 19 +++++++++++++ advice.h | 1 + builtin/mv.c | 50 ++++++++++++++++++++++++++++++----- t/t7002-mv-sparse-checkout.sh | 8 +++--- 4 files changed, 67 insertions(+), 11 deletions(-) diff --git a/advice.c b/advice.c index 6fda9edbc2..fd18968943 100644 --- a/advice.c +++ b/advice.c @@ -261,3 +261,22 @@ void detach_advice(const char *new_name) fprintf(stderr, fmt, new_name); } + +void advise_on_moving_dirty_path(struct string_list *pathspec_list) +{ + struct string_list_item *item; + + if (!pathspec_list->nr) + return; + + fprintf(stderr, _("The following paths have been moved outside the\n" + "sparse-checkout definition but are not sparse due to local\n" + "modifications.\n")); + for_each_string_list_item(item, pathspec_list) + fprintf(stderr, "%s\n", item->string); + + advise_if_enabled(ADVICE_UPDATE_SPARSE_PATH, + _("To correct the sparsity of these paths, do the following:\n" + "* Use \"git add --sparse \" to update the index\n" + "* Use \"git sparse-checkout reapply\" to apply the sparsity rules")); +} diff --git a/advice.h b/advice.h index 7ddc6cbc1a..07e0f76833 100644 --- a/advice.h +++ b/advice.h @@ -74,5 +74,6 @@ void NORETURN die_conclude_merge(void); void NORETURN die_ff_impossible(void); void advise_on_updating_sparse_paths(struct string_list *pathspec_list); void detach_advice(const char *new_name); +void advise_on_moving_dirty_path(struct string_list *pathspec_list); #endif /* ADVICE_H */ diff --git a/builtin/mv.c b/builtin/mv.c index d05914a233..d35994c443 100644 --- a/builtin/mv.c +++ b/builtin/mv.c @@ -184,6 +184,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix) struct lock_file lock_file = LOCK_INIT; struct cache_entry *ce; struct string_list only_match_skip_worktree = STRING_LIST_INIT_NODUP; + struct string_list dirty_paths = STRING_LIST_INIT_NODUP; git_config(git_default_config, NULL); @@ -414,6 +415,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix) const char *src = source[i], *dst = destination[i]; enum update_mode mode = modes[i]; int pos; + int up_to_date = 0; struct checkout state = CHECKOUT_INIT; state.istate = &the_index; @@ -424,6 +426,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix) if (show_only) continue; if (!(mode & (INDEX | SPARSE | SKIP_WORKTREE_DIR)) && + !(dst_mode & SKIP_WORKTREE_DIR) && rename(src, dst) < 0) { if (ignore_errors) continue; @@ -443,20 +446,52 @@ int cmd_mv(int argc, const char **argv, const char *prefix) pos = cache_name_pos(src, strlen(src)); assert(pos >= 0); + if (!(mode & SPARSE) && !lstat(src, &st)) + up_to_date = !ce_modified(active_cache[pos], &st, 0); rename_cache_entry_at(pos, dst); - if ((mode & SPARSE) && - (path_in_sparse_checkout(dst, &the_index))) { - int dst_pos; + if (ignore_sparse && + core_apply_sparse_checkout && + core_sparse_checkout_cone) { - dst_pos = cache_name_pos(dst, strlen(dst)); - active_cache[dst_pos]->ce_flags &= ~CE_SKIP_WORKTREE; + /* from out-of-cone to in-cone */ + if ((mode & SPARSE) && + path_in_sparse_checkout(dst, &the_index)) { + int dst_pos = cache_name_pos(dst, strlen(dst)); + struct cache_entry *dst_ce = active_cache[dst_pos]; - if (checkout_entry(active_cache[dst_pos], &state, NULL, NULL)) - die(_("cannot checkout %s"), active_cache[dst_pos]->name); + dst_ce->ce_flags &= ~CE_SKIP_WORKTREE; + + if (checkout_entry(dst_ce, &state, NULL, NULL)) + die(_("cannot checkout %s"), dst_ce->name); + continue; + } + + /* from in-cone to out-of-cone */ + if ((dst_mode & SKIP_WORKTREE_DIR) && + !(mode & SPARSE) && + !path_in_sparse_checkout(dst, &the_index)) { + int dst_pos = cache_name_pos(dst, strlen(dst)); + struct cache_entry *dst_ce = active_cache[dst_pos]; + char *src_dir = dirname(xstrdup(src)); + + if (up_to_date) { + dst_ce->ce_flags |= CE_SKIP_WORKTREE; + unlink_or_warn(src); + } else { + string_list_append(&dirty_paths, dst); + safe_create_leading_directories(xstrdup(dst)); + rename(src, dst); + } + if ((mode & INDEX) && is_empty_dir(src_dir)) + rmdir_or_warn(src_dir); + } } } + if (dirty_paths.nr) + advise_on_moving_dirty_path(&dirty_paths); + if (gitmodules_modified) stage_updated_gitmodules(&the_index); @@ -465,6 +500,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix) die(_("Unable to write new index file")); string_list_clear(&src_for_dst, 0); + string_list_clear(&dirty_paths, 0); UNLEAK(source); UNLEAK(dest_path); free(submodule_gitfile); diff --git a/t/t7002-mv-sparse-checkout.sh b/t/t7002-mv-sparse-checkout.sh index c27fcdbfd0..dafe15b9cf 100755 --- a/t/t7002-mv-sparse-checkout.sh +++ b/t/t7002-mv-sparse-checkout.sh @@ -303,7 +303,7 @@ test_expect_success 'move sparse file to existing destination with --force and - test_cmp expect sub/file1 ' -test_expect_failure 'move clean path from in-cone to out-of-cone' ' +test_expect_success 'move clean path from in-cone to out-of-cone' ' test_when_finished "cleanup_sparse_checkout" && setup_sparse_checkout && @@ -356,7 +356,7 @@ test_expect_failure 'move clean path from in-cone to out-of-cone overwrite' ' test_cmp expect actual ' -test_expect_failure 'move dirty path from in-cone to out-of-cone' ' +test_expect_success 'move dirty path from in-cone to out-of-cone' ' test_when_finished "cleanup_sparse_checkout" && setup_sparse_checkout && echo "modified" >>sub/d && @@ -380,7 +380,7 @@ test_expect_failure 'move dirty path from in-cone to out-of-cone' ' grep -x "H folder1/d" actual ' -test_expect_failure 'move dir from in-cone to out-of-cone' ' +test_expect_success 'move dir from in-cone to out-of-cone' ' test_when_finished "cleanup_sparse_checkout" && setup_sparse_checkout && @@ -400,7 +400,7 @@ test_expect_failure 'move dir from in-cone to out-of-cone' ' grep -x "S folder1/dir/e" actual ' -test_expect_failure 'move partially-dirty dir from in-cone to out-of-cone' ' +test_expect_success 'move partially-dirty dir from in-cone to out-of-cone' ' test_when_finished "cleanup_sparse_checkout" && setup_sparse_checkout && touch sub/dir/e2 sub/dir/e3 && From patchwork Tue Jul 19 13:28:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shaoxuan Yuan X-Patchwork-Id: 12922595 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C4513C43334 for ; Tue, 19 Jul 2022 14:10:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239010AbiGSOKk (ORCPT ); Tue, 19 Jul 2022 10:10:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42548 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238889AbiGSOKO (ORCPT ); Tue, 19 Jul 2022 10:10:14 -0400 Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B14A558DF for ; Tue, 19 Jul 2022 06:29:07 -0700 (PDT) Received: by mail-pf1-x429.google.com with SMTP id g126so13542460pfb.3 for ; Tue, 19 Jul 2022 06:29: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=UScBClZnkEceahuoH1MI9Ww5n76d07CQMztc0SOra9Y=; b=SltP4f+J3qXjxiTppId9J59+kMWeiirQBM50AB8H0597bJO5sb+OI/bKbV8YT5Tcai T7l32srLb15QdTT5TWPjyiIX6+BOPvJwVMUu7YBR04yiLvFcZ+HQbo0WGNjmIuVVaEUV PxOm1GBEAKZaePjR+aLV3E550kKwknbVeoy8nEAUkyYj71MU7evJwiz9pVjJzERKG64y fa1XaJk7LAcx7xc9Be7DQYEg5jpFeMgnwhD9mBNcULfuTqgzmWegBefbKD1MvfVr/qSd DvpIvJ6A77HolnXqA7NFytpXJ/7pRV1PT4vZoC9kSFwjOOeLYHR9aNy9gNTtqvSGyDjZ YnKw== 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=UScBClZnkEceahuoH1MI9Ww5n76d07CQMztc0SOra9Y=; b=UDL1k68RFgymGphGaJadUslAuVX0G9ysRz3G2CTT37G+IsBZjZ2oHhy0/yBD0gc4N4 ZQGzwKWB29UjzbYJO3QytrFuf6atmfS2HvOJNTv6Pd3NPXbKhCiS3N8os3BGSxuqI/sL JkFUHPzD0/X1lDzIqtQ3Np+gS534P+LNEBTmHI5H+HjqLuAiBfkwmGM5TIiVreKIuGfp 29URIej6r8ODOFUM2NJxsReXi2VB/sznKgITE68GwRYddFuEGpijocQz+VL5by29bpwU I0k+IgD4wzCq76em+QZreds6P8Iy/bfU2uJLchrHNRaTRXE9D+HM++EbD6YxrnTXDXJ7 iOyw== X-Gm-Message-State: AJIora/9MMZC5aEkI2AcUG/1O7PgGs6gr6RP5SaHE/tCAf4+idMElh2y QNUxnq8g206Y4GbUOWRmOfz2HYI8skUZdpBd X-Google-Smtp-Source: AGRyM1sj6TtSZKqyiLGli6UjSTX83NnqOLGVYyTZqS7NUaaVYeIWBuJS7oN2h77WjyIiaHIOHLP4bw== X-Received: by 2002:a05:6a00:815:b0:52a:dea8:269b with SMTP id m21-20020a056a00081500b0052adea8269bmr33716797pfk.66.1658237346979; Tue, 19 Jul 2022 06:29:06 -0700 (PDT) Received: from ffyuanda.localdomain ([101.206.227.243]) by smtp.gmail.com with ESMTPSA id r9-20020a170902be0900b0016be834d544sm624424pls.237.2022.07.19.06.29.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Jul 2022 06:29:06 -0700 (PDT) From: Shaoxuan Yuan To: git@vger.kernel.org Cc: vdye@github.com, derrickstolee@github.com, gitster@pobox.com, Shaoxuan Yuan Subject: [PATCH v1 7/7] mv: check overwrite for in-to-out move Date: Tue, 19 Jul 2022 21:28:09 +0800 Message-Id: <20220719132809.409247-8-shaoxuan.yuan02@gmail.com> X-Mailer: git-send-email 2.37.0 In-Reply-To: <20220719132809.409247-1-shaoxuan.yuan02@gmail.com> References: <20220719132809.409247-1-shaoxuan.yuan02@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Add checking logic for overwritng when moving from in-cone to out-of-cone. It is the index version of the original overwrite logic. Signed-off-by: Shaoxuan Yuan --- builtin/mv.c | 12 ++++++++++++ t/t7002-mv-sparse-checkout.sh | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/builtin/mv.c b/builtin/mv.c index d35994c443..5ed3bd3431 100644 --- a/builtin/mv.c +++ b/builtin/mv.c @@ -365,6 +365,18 @@ int cmd_mv(int argc, const char **argv, const char *prefix) goto act_on_entry; } + if (ignore_sparse && + (dst_mode & SKIP_WORKTREE_DIR) && + index_entry_exists(&the_index, dst, strlen(dst))) { + bad = _("destination exists in the index"); + if (force) { + if (verbose) + warning(_("overwriting '%s'"), dst); + bad = NULL; + } else { + goto act_on_entry; + } + } /* * We check if the paths are in the sparse-checkout * definition as a very final check, since that diff --git a/t/t7002-mv-sparse-checkout.sh b/t/t7002-mv-sparse-checkout.sh index dafe15b9cf..5d810f3af0 100755 --- a/t/t7002-mv-sparse-checkout.sh +++ b/t/t7002-mv-sparse-checkout.sh @@ -323,7 +323,7 @@ test_expect_success 'move clean path from in-cone to out-of-cone' ' grep -x "S folder1/d" actual ' -test_expect_failure 'move clean path from in-cone to out-of-cone overwrite' ' +test_expect_success 'move clean path from in-cone to out-of-cone overwrite' ' test_when_finished "cleanup_sparse_checkout" && setup_sparse_checkout && echo "sub/file1 overwrite" >sub/file1 &&