From patchwork Fri Aug 5 03:05:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shaoxuan Yuan X-Patchwork-Id: 12936829 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 49816C25B08 for ; Fri, 5 Aug 2022 03:05:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236877AbiHEDF5 (ORCPT ); Thu, 4 Aug 2022 23:05:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37404 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234738AbiHEDFx (ORCPT ); Thu, 4 Aug 2022 23:05:53 -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 CD73563A6 for ; Thu, 4 Aug 2022 20:05:51 -0700 (PDT) Received: by mail-pg1-x530.google.com with SMTP id 12so1589498pga.1 for ; Thu, 04 Aug 2022 20:05:51 -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=OP4gxRN95WA3vVC9PD6S/XeOgjAFyckDw637atYtixo=; b=eVgaFKjwHlPFAvCWnbrVzAo6yqvmqLhQEfTJMQVm8GElXj/efxDVbFO2hC0Hs7tGL8 fnTSX9LjemPEpTgSDJ8G0AZuu3LMKvEYZRTitkEdTxso5Q6OiY2ELZtkafTIGUrama3f TMMFA3YllCgt986a/1dGsYlO6HGzxyAsI0tk+KDXxdwQVoW2cZd1c7/FO6gpUGccNo36 aQ9NzuEGcBMIOXjSeOJq34Si3z28mqjLydvuCP3Vu1EeFuZZjJd4aEGDEQm+L6pri6/2 emV3NPOow+QpGXKaCR8VBSWcRCCZoi3gVzAYl05OpdAm62UaiZ3mtakknWPyHckOpEK2 fmbw== 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=OP4gxRN95WA3vVC9PD6S/XeOgjAFyckDw637atYtixo=; b=DeVikznngmQrO3bECMTJp3y/DOMkfEmvQxxSdnBaGU2nfEhjfM6m+vcMncBz4TY47l VP0TyOVQGNhXLX5Sw5QiUfgwxvTEqOg2feT606Og3NkWV3ustPr1z7NMW3vo81Gk7yG1 JQM+D60wKqgxRSqwpYcSzG/a+MIrdEQ20ypv3qzQpkk25hnSPJM70ygnBwX02QJQvK6G 3R/IjXVqssU8hflJfxL7k/xMx8lxKKrK3b2rSrNkLjxaazFd0qR4NNApPYEwXB4b4Op6 YGyYBT4SSCrwyt1fovi40FGksMdN0OrQj64d6zADKpd06ZdcnWhrbtJvU7Y5yW6Y4HSq OUqQ== X-Gm-Message-State: ACgBeo3WF/3JpfEa2qj+vPbfKG/fMft+DmrZ4qg+ULV32bot0cJ/eALc hHrLalIbreTxypE98IaKR2XSIBGNr5Y3VRxM X-Google-Smtp-Source: AA6agR4Eox1QErelP4RjE26UK6WjXv3WqCDhuwCHgyEbVxJNHgkdut3NRglb6jSbotxDo98Y310Y0w== X-Received: by 2002:a05:6a00:1ad3:b0:52b:37ac:4435 with SMTP id f19-20020a056a001ad300b0052b37ac4435mr4845787pfv.25.1659668751110; Thu, 04 Aug 2022 20:05:51 -0700 (PDT) Received: from ffyuanda.localdomain ([113.65.229.239]) by smtp.gmail.com with ESMTPSA id i6-20020a654d06000000b0040df0c9a1aasm570234pgt.14.2022.08.04.20.05.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Aug 2022 20:05:50 -0700 (PDT) From: Shaoxuan Yuan To: git@vger.kernel.org Cc: vdye@github.com, derrickstolee@github.com, Shaoxuan Yuan Subject: [PATCH v2 1/9] t7002: add tests for moving from in-cone to out-of-cone Date: Fri, 5 Aug 2022 11:05:20 +0800 Message-Id: <20220805030528.1535376-2-shaoxuan.yuan02@gmail.com> X-Mailer: git-send-email 2.37.0 In-Reply-To: <20220805030528.1535376-1-shaoxuan.yuan02@gmail.com> References: <20220719132809.409247-1-shaoxuan.yuan02@gmail.com> <20220805030528.1535376-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. 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. Helped-by: Derrick Stolee Helped-by: Victoria Dye Signed-off-by: Shaoxuan Yuan --- t/t7002-mv-sparse-checkout.sh | 122 ++++++++++++++++++++++++++++++++++ 1 file changed, 122 insertions(+) diff --git a/t/t7002-mv-sparse-checkout.sh b/t/t7002-mv-sparse-checkout.sh index 71fe29690f..9b3a9ab4c3 100755 --- a/t/t7002-mv-sparse-checkout.sh +++ b/t/t7002-mv-sparse-checkout.sh @@ -290,4 +290,126 @@ 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 "^H sub/d\$" actual && + grep "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 "H sub/file1" actual && + grep "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 && + + test_path_is_missing sub/d && + test_path_is_file folder1/d && + git ls-files -t >actual && + ! grep "^H sub/d\$" actual && + grep "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 folder1 && + git ls-files -t >actual && + ! grep "H sub/dir/e" actual && + grep "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 && + + 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 "H sub/dir/e" actual && + ! grep "H sub/dir/e2" actual && + ! grep "H sub/dir/e3" actual && + grep "S folder1/dir/e" actual && + grep "H folder1/dir/e2" actual && + grep "H folder1/dir/e3" actual +' + test_done From patchwork Fri Aug 5 03:05:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shaoxuan Yuan X-Patchwork-Id: 12936830 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 629CEC19F2A for ; Fri, 5 Aug 2022 03:06:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239651AbiHEDGA (ORCPT ); Thu, 4 Aug 2022 23:06:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37416 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235377AbiHEDFy (ORCPT ); Thu, 4 Aug 2022 23:05:54 -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 964F02DFA for ; Thu, 4 Aug 2022 20:05:53 -0700 (PDT) Received: by mail-pg1-x530.google.com with SMTP id f11so1562134pgj.7 for ; Thu, 04 Aug 2022 20:05:53 -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=X469WROovn5VaE3OAc+dJxHmhUoHwaMuvoqvRtRENb8=; b=erA8JynEGO9T8HH69HtekDdHVWstwNmpmlw1uHPEBXYwNO08QpIctl0/Zpfru4O0IX yF3c0Wbxfic/IW+nO0AKw9XECqXG8H3f+L3Oam57O9u8XOS5djcDRZwWXB36mki5yuLB 7Rc4GJ469qorgqEQpTIAl8g5kpvzJqNhprMpaR0UtzgdinXlQJB05JftXp1fr52XujL4 k2FTyISuQjVVqw5RAEmUefAg0rMFclPZ3Ry3AIi0A8FA/ZkSPsQAYj8JgULaRe3qyAL+ rU3ItIBkkFQ9+R0IcawuTv5PJlDXcznVvy4NY16rMaOboWn+ifJUTMKRY1TPLmZWZv3V 4vwQ== 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=X469WROovn5VaE3OAc+dJxHmhUoHwaMuvoqvRtRENb8=; b=rZL/T0fCltHzOXA5wHWQuI7CNjYZEsipMEe01ttdnjPELF/7b9yUXJcZBVwJr/zK4b o99LpU48Ujlpw0vWORNUsuHmZTa2/kMRRPr1HhQDUOK9eEEtYvft48wZN0Lw5fP4EE8Z upgq2tXcwZtNx9/Xyje+0SdOP/CexDFxXWTqjTq9HtZfp0dyBE63+m/l/rlGAAKt4wgp I4GfHE0A3FASF2j7RyAplBhAUBbS6dq7YFDQTduO1kE5Q4okdID12fLG5HXr+PhKfo3j eKg2M3pZGvV+6PFTHR1oVtBFnXqNRkefCl9B3VrLbFwWjhM9Q9/Ju4dTU7uo79l5PRKI aWcw== X-Gm-Message-State: ACgBeo1+nKyqLGchKEfoEOGBzvWabksqq2Xwo8xp8mcWn8tEmF9WEytg rMb2qBkNtS7fvlfymlYSE09WJP4q+HBIEhLV X-Google-Smtp-Source: AA6agR5uInSZpyBt1BkkyhQmW3EcUIfcVpaaFR8WWYNsm63K+KuD96LfhqS2Erhb492nblabyjH2XA== X-Received: by 2002:a63:f809:0:b0:41b:4a4c:4fbf with SMTP id n9-20020a63f809000000b0041b4a4c4fbfmr4246147pgh.616.1659668752622; Thu, 04 Aug 2022 20:05:52 -0700 (PDT) Received: from ffyuanda.localdomain ([113.65.229.239]) by smtp.gmail.com with ESMTPSA id i6-20020a654d06000000b0040df0c9a1aasm570234pgt.14.2022.08.04.20.05.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Aug 2022 20:05:52 -0700 (PDT) From: Shaoxuan Yuan To: git@vger.kernel.org Cc: vdye@github.com, derrickstolee@github.com, Shaoxuan Yuan Subject: [PATCH v2 2/9] mv: rename check_dir_in_index() to empty_dir_has_sparse_contents() Date: Fri, 5 Aug 2022 11:05:21 +0800 Message-Id: <20220805030528.1535376-3-shaoxuan.yuan02@gmail.com> X-Mailer: git-send-email 2.37.0 In-Reply-To: <20220805030528.1535376-1-shaoxuan.yuan02@gmail.com> References: <20220719132809.409247-1-shaoxuan.yuan02@gmail.com> <20220805030528.1535376-1-shaoxuan.yuan02@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Method check_dir_in_index() introduced in b91a2b6594 (mv: add check_dir_in_index() and solve general dir check issue, 2022-06-30) does not describe its intent and behavior well. Change its name to empty_dir_has_sparse_contents(), which more precisely describes its purpose. Reverse the return values, check_dir_in_index() return 0 for success and 1 for failure; reverse the values so empty_dir_has_sparse_contents() return 1 for success and 0 for failure. These values are more intuitive because 1 usually means "has" and 0 means "not found". Also modify the documentation to better align with the method's intent and behavior. Helped-by: Derrick Stolee Helped-by: Victoria Dye Signed-off-by: Shaoxuan Yuan --- builtin/mv.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/builtin/mv.c b/builtin/mv.c index 4729bb1a1a..7c11b8f995 100644 --- a/builtin/mv.c +++ b/builtin/mv.c @@ -125,15 +125,13 @@ static int index_range_of_same_dir(const char *src, int length, } /* - * Check if an out-of-cone directory should be in the index. Imagine this case - * that all the files under a directory are marked with 'CE_SKIP_WORKTREE' bit - * and thus the directory is sparsified. - * - * 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. + * Given the path of a directory that does not exist on-disk, check whether the + * directory contains any entries in the index with the SKIP_WORKTREE flag + * enabled. + * Return 1 if such index entries exist. + * Return 0 otherwise. */ -static int check_dir_in_index(const char *name) +static int empty_dir_has_sparse_contents(const char *name) { const char *with_slash = add_slash(name); int length = strlen(with_slash); @@ -144,14 +142,14 @@ static int check_dir_in_index(const char *name) if (pos < 0) { pos = -pos - 1; if (pos >= the_index.cache_nr) - return 1; + return 0; ce = active_cache[pos]; if (strncmp(with_slash, ce->name, length)) - return 1; - if (ce_skip_worktree(ce)) return 0; + if (ce_skip_worktree(ce)) + return 1; } - return 1; + return 0; } int cmd_mv(int argc, const char **argv, const char *prefix) @@ -232,7 +230,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix) if (pos < 0) { const char *src_w_slash = add_slash(src); if (!path_in_sparse_checkout(src_w_slash, &the_index) && - !check_dir_in_index(src)) { + empty_dir_has_sparse_contents(src)) { modes[i] |= SKIP_WORKTREE_DIR; goto dir_check; } From patchwork Fri Aug 5 03:05:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shaoxuan Yuan X-Patchwork-Id: 12936831 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 B9843C25B08 for ; Fri, 5 Aug 2022 03:06:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239984AbiHEDGD (ORCPT ); Thu, 4 Aug 2022 23:06:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37424 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229477AbiHEDFz (ORCPT ); Thu, 4 Aug 2022 23:05:55 -0400 Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C2F8B63A6 for ; Thu, 4 Aug 2022 20:05:54 -0700 (PDT) Received: by mail-pj1-x1032.google.com with SMTP id t2-20020a17090a4e4200b001f21572f3a4so1645572pjl.0 for ; Thu, 04 Aug 2022 20:05:54 -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=4ui84gGy//MR5nayXsLtLh2DEca++xowMq/b5JPqYEM=; b=n+bBNXlYPCu1h+tFVqUVHGhLX7YLHqdsAQEggT+qgzYuYNDDsZd9CK0Xb1SZkIspET 1V84KBQEg1SULFp+3Q0XDeePTLQmoE6qAI6NyEyk8A3qW0BCCKC1bE+cKXdaTeyHwB+c RQE29+RDE8wwmwU8qBZ/Gs+Uwaes4IOgoYzjCQx2A06GGyBHIo71owhJEvMCauzt5O2w Bj05I64c7fmSo3yKSA5mQr2CujGm3fUDrISUlnt9WZC6SiwmzY9UfEOWfxmtJhNLmvAp 3RZU73P2V/ivDNqkuuXJ8LxECVIZy/fz65CCfZOwLrv0lffMKdqrW/U8AoSqgji/grUa VW1g== 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=4ui84gGy//MR5nayXsLtLh2DEca++xowMq/b5JPqYEM=; b=tMsgwE1zmDWQiKQSjvKN0iVWuGs7noJvy0L1/mNh6bpddvc54fiKbnjGR0wurQjz9j LrvODmNJZmcB4zTbfY8wT8RayNE8e8TyjP8Lc6iAPn8oOUH5gxf1Rd/KetgHFPULOWrW FvCtLMrHJaF6BTq8GZeXNJvUs+gRtDR8/pyJHQnWPTBhrICMzylcIwf5iy9gY/4k9+Pb EqUE7eNDIdiG5QEIl/wou9bNT+MDnZM/Q9BGnELNFkYiW4jxNXOwGU4OtUnv438ADIIP 8378lY5CXei7sz3t5hjMxKaCsbtGHk53JIpcSPawP4ZuWkCR4MMJQ2hz8wX/jQrdP5rU zEFw== X-Gm-Message-State: ACgBeo2sXzCW3cdarN1fW8oGTpWMZKa36MnfvlCGQ5w0Lh8z4k8XZJYI ooiHpfLcHnb3+uOQ+J4qbyZ7hU3MBlT8zuyf X-Google-Smtp-Source: AA6agR61PjzisSNcJxOF+vP+tWTn2bDXg0dJhqYvH8x5xhk+vjy3eXCeaujUzyGi6pGgvfZ1+NdoKw== X-Received: by 2002:a17:902:a9c6:b0:16c:9d5a:fde1 with SMTP id b6-20020a170902a9c600b0016c9d5afde1mr4601867plr.3.1659668754193; Thu, 04 Aug 2022 20:05:54 -0700 (PDT) Received: from ffyuanda.localdomain ([113.65.229.239]) by smtp.gmail.com with ESMTPSA id i6-20020a654d06000000b0040df0c9a1aasm570234pgt.14.2022.08.04.20.05.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Aug 2022 20:05:53 -0700 (PDT) From: Shaoxuan Yuan To: git@vger.kernel.org Cc: vdye@github.com, derrickstolee@github.com, Shaoxuan Yuan Subject: [PATCH v2 3/9] mv: free the *with_slash in check_dir_in_index() Date: Fri, 5 Aug 2022 11:05:22 +0800 Message-Id: <20220805030528.1535376-4-shaoxuan.yuan02@gmail.com> X-Mailer: git-send-email 2.37.0 In-Reply-To: <20220805030528.1535376-1-shaoxuan.yuan02@gmail.com> References: <20220719132809.409247-1-shaoxuan.yuan02@gmail.com> <20220805030528.1535376-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. Helped-by: Derrick Stolee Helped-by: Victoria Dye 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 7c11b8f995..0a999640c9 100644 --- a/builtin/mv.c +++ b/builtin/mv.c @@ -133,6 +133,7 @@ static int index_range_of_same_dir(const char *src, int length, */ static int empty_dir_has_sparse_contents(const char *name) { + int ret = 0; const char *with_slash = add_slash(name); int length = strlen(with_slash); @@ -142,14 +143,18 @@ static int empty_dir_has_sparse_contents(const char *name) if (pos < 0) { pos = -pos - 1; if (pos >= the_index.cache_nr) - return 0; + goto free_return; ce = active_cache[pos]; if (strncmp(with_slash, ce->name, length)) - return 0; + goto free_return; if (ce_skip_worktree(ce)) - return 1; + ret = 1; } - return 0; + +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 Fri Aug 5 03:05:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shaoxuan Yuan X-Patchwork-Id: 12936832 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 A9ECBC19F2A for ; Fri, 5 Aug 2022 03:06:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240009AbiHEDGO (ORCPT ); Thu, 4 Aug 2022 23:06:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37486 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235616AbiHEDF6 (ORCPT ); Thu, 4 Aug 2022 23:05:58 -0400 Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A29E59FF7 for ; Thu, 4 Aug 2022 20:05:56 -0700 (PDT) Received: by mail-pf1-x430.google.com with SMTP id g12so1163008pfb.3 for ; Thu, 04 Aug 2022 20:05:56 -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=LKXhmBlxvN2IiplKFduGf7i9Fru3vQ/QSJaeUXYsMto=; b=A+WFIKbCUTBoWgXMftEyEY6z76Go64vsvfDw2LKWQQcHJtQVBbR6o4wXzNDb6C97Eg sy4ZOGdaMqRJQfIC1yAkcIU3KeYtGLiIq8C0DV13ui5PvkdUWsl+cEGeZSfp5cvBgVcp 1qtL/rB+Y+I7eAUD/Z9G1D5u+xAz2E9CVJ80izcXgWxzjcilOk/B5VQ+zHPNQ4wQMYYk nwPWmUXhp6TjjbEg78Kl5X/FLNRMDakb1Smr0sqORDnMreYgPuB7OyUoUlDBUcpX3yTi Oo4z2JRUNzR2sjw9YbVZb0XS9BC1KivzWleALIliXmZo6mwTYUYGH/HJ4ebaMyh2AB3x lCrw== 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=LKXhmBlxvN2IiplKFduGf7i9Fru3vQ/QSJaeUXYsMto=; b=aXT3B8OqDJ/z8UwPmNTn+lOrNiHXkU7i5pzl8bvTILd4FHw0zFnSeP2xQaEwhyBEt5 dh+1bPWjrkpckazP67BhAP3nhlg87sOLrFqOOzf+ZDViAbJEmV7F3wSqtdy1Z6Q+orww 8T0ugHlR/Kp0nrDt0hqCcG9ZDN985gWlw0ymLfO3DGg9kuehr1XwKz+Wb3fLWlE5Qys7 itbGXb3F7lL064ra9jCThp4Zre3wT8/sxMeZl2jqbS5KOU4t7qBUoub+mC9FME3CLs6q xQgfjDF84p+Y7+r84JVvUfllT7OjbOAna9Lu0lrLj+b14J/5nXfKnCch/UGVtNMzqAaF 4GSw== X-Gm-Message-State: ACgBeo33Q5FMaf0xafGj89br6o6l7qKPONFJUzowFb4fahAKdfOjyTGF YzkvkemhZdH4Ch2GzWcQTj2BhWhZHEOYkIF5 X-Google-Smtp-Source: AA6agR7Bd7IKIFmwNVQkEOEQ28+4Zwvq6HhunOLqAbaYD29vDqEfLVVnr4uL0DyC25a8YOMC54q4Pg== X-Received: by 2002:a05:6a00:cc1:b0:52d:a29d:fb1 with SMTP id b1-20020a056a000cc100b0052da29d0fb1mr4906117pfv.56.1659668755723; Thu, 04 Aug 2022 20:05:55 -0700 (PDT) Received: from ffyuanda.localdomain ([113.65.229.239]) by smtp.gmail.com with ESMTPSA id i6-20020a654d06000000b0040df0c9a1aasm570234pgt.14.2022.08.04.20.05.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Aug 2022 20:05:55 -0700 (PDT) From: Shaoxuan Yuan To: git@vger.kernel.org Cc: vdye@github.com, derrickstolee@github.com, Shaoxuan Yuan Subject: [PATCH v2 4/9] mv: check if is a SKIP_WORKTREE_DIR Date: Fri, 5 Aug 2022 11:05:23 +0800 Message-Id: <20220805030528.1535376-5-shaoxuan.yuan02@gmail.com> X-Mailer: git-send-email 2.37.0 In-Reply-To: <20220805030528.1535376-1-shaoxuan.yuan02@gmail.com> References: <20220719132809.409247-1-shaoxuan.yuan02@gmail.com> <20220805030528.1535376-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 is such a sparse directory, then we should modify the index the same way as we would if this were a non-sparse directory. We must be careful to ensure that the is marked with SKIP_WORKTREE_DIR. Also add a `dst_w_slash` to reuse the result from `add_slash()`, which was everywhere and can be simplified. Helped-by: Derrick Stolee Helped-by: Victoria Dye Signed-off-by: Shaoxuan Yuan --- builtin/mv.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/builtin/mv.c b/builtin/mv.c index 0a999640c9..f213a92bf6 100644 --- a/builtin/mv.c +++ b/builtin/mv.c @@ -171,6 +171,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix) OPT_END(), }; const char **source, **destination, **dest_path, **submodule_gitfile; + const char *dst_w_slash; enum update_mode *modes; struct stat st; struct string_list src_for_dst = STRING_LIST_INIT_NODUP; @@ -201,6 +202,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') @@ -208,12 +210,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) && + empty_dir_has_sparse_contents(dst_w_slash)) { + destination = internal_prefix_pathspec(dst_w_slash, argv, argc, DUP_BASENAME); + } 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); + dst_w_slash = NULL; } /* Checking */ From patchwork Fri Aug 5 03:05:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shaoxuan Yuan X-Patchwork-Id: 12936833 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 287FAC19F2A for ; Fri, 5 Aug 2022 03:06:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234724AbiHEDGd (ORCPT ); Thu, 4 Aug 2022 23:06:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239921AbiHEDGA (ORCPT ); Thu, 4 Aug 2022 23:06:00 -0400 Received: from mail-pg1-x531.google.com (mail-pg1-x531.google.com [IPv6:2607:f8b0:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 72848AE73 for ; Thu, 4 Aug 2022 20:05:58 -0700 (PDT) Received: by mail-pg1-x531.google.com with SMTP id s206so1582789pgs.3 for ; Thu, 04 Aug 2022 20:05:58 -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=i3DdkBLkm5Ldmt/BWfrdxFk0g0Ma19fIrmqwg6thbro=; b=GEx4TC7HaydjCRDl9w+bwM1IuqJ8eJE+cXkOD7fpGVO3kB/dk41WNN+Jh+sgZjZOV7 u6g+nRG2bFeCvabUIR5juj0lqri5rk8RDYrBh1Kw0B6iVJe5B9zSuL9iZ9Py624HYU+1 gL9pkgKDUeMJR2cAaTk+JknOMDBJLZ8NDJOLZN9vjS5FAWlFWltEifRfEsyVR/KDao/g 988cl0v7GhZIUcOJTvVsbsfCIKUIbDeZZiiwC6Jam2BqFxl1ptnA+QvfSsdo98VtqhNQ PKD8mhW80BiRb5QWp9nbn5axctoPLVLb5Pg3Ex7pHHpEa+X80CLO1f5Ex1Otx0+mxd6j vA4w== 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=i3DdkBLkm5Ldmt/BWfrdxFk0g0Ma19fIrmqwg6thbro=; b=hID7Vzv7YbAamcG+I6YDO2AFM43zz9los0I4z9u3cw8fFhr/KWSAa+k83ei5048fv0 xSN7cdNdyB84BTIHll/3w7OFwEJW5o5DR+XQV7xLsTPQ7TAqTXvRG37TcHehS8Q5MPkn 42raMp+IOT2XArIkKc0GM3FEAzSz0hJfzcmzFSqc09XxckObfcVzDAce/sfh7c6ULDFN jrx28DVFD4UtCubAEr6nWQbC5PnzCJ3t1GEv6UEHzMaW6Mj48RkwdGTevyp9B/zR9qxL XHnKcWyRZaapvEjm14fjl04om4LjLcCUc+cjhcau1119kEmg71MSRKThptLwtCUmMd9h ZPHw== X-Gm-Message-State: ACgBeo1Ki9RlOvByQuR81Pvx92MJ59dYhcVVJADczI/FmuxJ8khIUO/T OFxRhOEcZj+AWTwYsqZj4AHR+/UzTAmOGey6 X-Google-Smtp-Source: AA6agR4RhPKtpJ/WqxZrpMH5AvvI1+EMI1d6wmnwbA+Z0fBAxv73O8GANEr5rnzNfwzZDlOId0MFIg== X-Received: by 2002:a62:79c4:0:b0:52d:cd3d:2027 with SMTP id u187-20020a6279c4000000b0052dcd3d2027mr4933090pfc.71.1659668757623; Thu, 04 Aug 2022 20:05:57 -0700 (PDT) Received: from ffyuanda.localdomain ([113.65.229.239]) by smtp.gmail.com with ESMTPSA id i6-20020a654d06000000b0040df0c9a1aasm570234pgt.14.2022.08.04.20.05.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Aug 2022 20:05:56 -0700 (PDT) From: Shaoxuan Yuan To: git@vger.kernel.org Cc: vdye@github.com, derrickstolee@github.com, Shaoxuan Yuan Subject: [PATCH v2 5/9] mv: remove BOTH from enum update_mode Date: Fri, 5 Aug 2022 11:05:24 +0800 Message-Id: <20220805030528.1535376-6-shaoxuan.yuan02@gmail.com> X-Mailer: git-send-email 2.37.0 In-Reply-To: <20220805030528.1535376-1-shaoxuan.yuan02@gmail.com> References: <20220719132809.409247-1-shaoxuan.yuan02@gmail.com> <20220805030528.1535376-1-shaoxuan.yuan02@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Since BOTH is not used anywhere in the code and its meaning is unclear, remove it. Helped-by: Derrick Stolee Helped-by: Victoria Dye 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 f213a92bf6..1dc55153ed 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 Fri Aug 5 03:05:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shaoxuan Yuan X-Patchwork-Id: 12936834 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 7C8A9C19F2A for ; Fri, 5 Aug 2022 03:06:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240131AbiHEDGf (ORCPT ); Thu, 4 Aug 2022 23:06:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38058 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237584AbiHEDG1 (ORCPT ); Thu, 4 Aug 2022 23:06:27 -0400 Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3AAE1DEDB for ; Thu, 4 Aug 2022 20:06:00 -0700 (PDT) Received: by mail-pf1-x42f.google.com with SMTP id c139so1172506pfc.2 for ; Thu, 04 Aug 2022 20:06:00 -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=OFrpYOlgu3kMh4AxM1QhObGRwdasE+EoQmJpcSdwcnw=; b=bbb45L6R2M1uPczE47jlR19DzHcR9zp7MVgfTZxsJgjESyzyvfSdEq8aBK7afuQM1v 2lVTgqbTNtCrPCO58M8E41zq+R4IANfKpZP6o+oPy/SHipf4bLUb4e8QifqDrBn2k7JT FZ68vRMLEmchGtsy/O3ZF7MXy0OQ8+AJ3RXHb5r6VSXRNtjPQwbZ/LV5oRAwGJkyHLxV flCQWcXxtsGYBKM2sW83oVgu+OL+nVzAL/bneS6SZeQboibVfgtiKAHN/aajyzm++W+N fwtK3og6pHAkkBsqj3G5NnKL9SaGRw+PEq5y2qKB9faCm7/7fmFLgYLct3rqG2wpeXo6 nqrg== 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=OFrpYOlgu3kMh4AxM1QhObGRwdasE+EoQmJpcSdwcnw=; b=wKWLRyqjWXJKaQVwIy9Dx1erRQ2nFJOCuIBwXhfmfqB8WSfJTNdpwefOKoHkkcBVfJ HftbwaW2TZd5jp+Cg1vPwbnJdaWKcabfxYspuZwhSgr42SKhcrXC3AZj7/QGnld8SwNN pQ7e/WP9PwDC+nHbwVhe7pYuR/5jLxDmHW1sJLeSH1urQObFGicw5ATYF8i0GC5gn4qy l8AQ9A/iGO1bJMutgnGEHHUrZ064e2WDgRCsXFDUAU2Jl0ttX0OdPnfvDv0KQ0PQ1g8x /urBSIzm+MVWZ9MUWvlrUm3sXAkP925n+2t7o3HsYPF+gx+5fFQcXShjzj2p/arDpDL2 qgyA== X-Gm-Message-State: ACgBeo28MrrIJYtJUJyILLcjJW1UqU5lJd0b7D0OkjktW5p6R0K3GYrF eTgEIrsJLlnRQl3hudmtzdOr/hibg1zVo21z X-Google-Smtp-Source: AA6agR764fs7FpJwoIjC9r8lvSZK1gQ6GaY9YNS1XvL24HYg0r6U/LWWXezLNskR+CLoO4Ndi/EDcQ== X-Received: by 2002:a05:6a00:13a2:b0:52e:128a:23dd with SMTP id t34-20020a056a0013a200b0052e128a23ddmr4750711pfg.54.1659668759222; Thu, 04 Aug 2022 20:05:59 -0700 (PDT) Received: from ffyuanda.localdomain ([113.65.229.239]) by smtp.gmail.com with ESMTPSA id i6-20020a654d06000000b0040df0c9a1aasm570234pgt.14.2022.08.04.20.05.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Aug 2022 20:05:58 -0700 (PDT) From: Shaoxuan Yuan To: git@vger.kernel.org Cc: vdye@github.com, derrickstolee@github.com, Shaoxuan Yuan Subject: [PATCH v2 6/9] mv: from in-cone to out-of-cone Date: Fri, 5 Aug 2022 11:05:25 +0800 Message-Id: <20220805030528.1535376-7-shaoxuan.yuan02@gmail.com> X-Mailer: git-send-email 2.37.0 In-Reply-To: <20220805030528.1535376-1-shaoxuan.yuan02@gmail.com> References: <20220719132809.409247-1-shaoxuan.yuan02@gmail.com> <20220805030528.1535376-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. Helped-by: Derrick Stolee Helped-by: Victoria Dye Signed-off-by: Shaoxuan Yuan --- builtin/mv.c | 55 +++++++++++++++++++++++++++++------ t/t7002-mv-sparse-checkout.sh | 8 ++--- 2 files changed, 50 insertions(+), 13 deletions(-) diff --git a/builtin/mv.c b/builtin/mv.c index 1dc55153ed..e4a14aea2d 100644 --- a/builtin/mv.c +++ b/builtin/mv.c @@ -171,12 +171,13 @@ int cmd_mv(int argc, const char **argv, const char *prefix) }; const char **source, **destination, **dest_path, **submodule_gitfile; const char *dst_w_slash; - enum update_mode *modes; + 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; 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); @@ -214,6 +215,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix) if (!path_in_sparse_checkout(dst_w_slash, &the_index) && empty_dir_has_sparse_contents(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]); } else { @@ -408,6 +410,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 sparse_and_dirty = 0; struct checkout state = CHECKOUT_INIT; state.istate = &the_index; @@ -418,6 +421,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; @@ -437,17 +441,49 @@ 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)) + sparse_and_dirty = 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) { + if ((mode & SPARSE) && + path_in_sparse_checkout(dst, &the_index)) { + /* from out-of-cone to in-cone */ + int dst_pos = cache_name_pos(dst, strlen(dst)); + struct cache_entry *dst_ce = active_cache[dst_pos]; + + dst_ce->ce_flags &= ~CE_SKIP_WORKTREE; + + if (checkout_entry(dst_ce, &state, NULL, NULL)) + die(_("cannot checkout %s"), dst_ce->name); + } else if ((dst_mode & SKIP_WORKTREE_DIR) && + !(mode & SPARSE) && + !path_in_sparse_checkout(dst, &the_index)) { + /* from in-cone to out-of-cone */ + int dst_pos = cache_name_pos(dst, strlen(dst)); + struct cache_entry *dst_ce = active_cache[dst_pos]; - dst_pos = cache_name_pos(dst, strlen(dst)); - active_cache[dst_pos]->ce_flags &= ~CE_SKIP_WORKTREE; - - if (checkout_entry(active_cache[dst_pos], &state, NULL, NULL)) - die(_("cannot checkout %s"), active_cache[dst_pos]->name); + /* + * if src is clean, it will suffice to remove it + */ + if (!sparse_and_dirty) { + dst_ce->ce_flags |= CE_SKIP_WORKTREE; + unlink_or_warn(src); + } else { + /* + * if src is dirty, move it to the + * destination and create leading + * dirs if necessary + */ + char *dst_dup = xstrdup(dst); + string_list_append(&dirty_paths, dst); + safe_create_leading_directories(dst_dup); + FREE_AND_NULL(dst_dup); + rename(src, dst); + } + } } } @@ -459,6 +495,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 9b3a9ab4c3..fc9577b2a6 100755 --- a/t/t7002-mv-sparse-checkout.sh +++ b/t/t7002-mv-sparse-checkout.sh @@ -290,7 +290,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 && @@ -343,7 +343,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 && @@ -363,7 +363,7 @@ test_expect_failure 'move dirty path from in-cone to out-of-cone' ' grep "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 && @@ -382,7 +382,7 @@ test_expect_failure 'move dir from in-cone to out-of-cone' ' grep "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 Fri Aug 5 03:05:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shaoxuan Yuan X-Patchwork-Id: 12936835 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 D5282C19F2A for ; Fri, 5 Aug 2022 03:06:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240032AbiHEDGj (ORCPT ); Thu, 4 Aug 2022 23:06:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38074 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237079AbiHEDG3 (ORCPT ); Thu, 4 Aug 2022 23:06:29 -0400 Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5ADE89FFE for ; Thu, 4 Aug 2022 20:06:01 -0700 (PDT) Received: by mail-pj1-x1029.google.com with SMTP id gj1so1563301pjb.0 for ; Thu, 04 Aug 2022 20:06: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=tO+nvSO883HQ6yqwLe/5TG7lDlnEVb9iMR8nxhoUMdw=; b=Mr5NogyAwoGaatGqGDnTwc+/beGVWhpadmko0GUfOrmeFadfcdBmWuN6ArzxAdBUJH ulMowMjiBnScGM+x/rLjrVFVgvLBI01qSqP/eZq2FRx35eWIs9TKmCLr5jVYBv2MzZL9 aSJWzDhtg7iqJKd1zZH5hoa81ig5/1Yobn2BoNDRWdm1THCA/hxPh5flpicuGovWBO29 RqzuthlcNdItd1lmDY41MW75USJ5rfAAf2adQoYM3kdXxh8knHclVGZaqoeQ+75BMIiV /+4MDQHtmWkKx0BMKume/aGDbNdI+ZbtYQNW5kMcilUknhij34YWrP9KYnHzsNQB4V7V US9A== 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=tO+nvSO883HQ6yqwLe/5TG7lDlnEVb9iMR8nxhoUMdw=; b=ipeN341xNko6q069no8tDyTwrab43h5up5W2gUcB5m+sMfDgMJl7cCjl/PN2afWkFo AWCo212lL8T/8C+6GcmdoZeugUpeJtdChccPFUzYyESr69+s76Q1yblQzRe+ultRImcY bw13IwzVZTjqfICL1vSKRKmJNLm5ROPYYUqE9jSfUwlQkAx34pbj15jBSg30UGClbHZG ECQaabXGcnYw+kUZYWhj0fpwOrL2SYOYXDtEpazz24RPs4QYInIz8zT7OP9SPFFIWiid 89YsjgLibfNemp2ko+cj0sOQSsgp0Xso3qnb4YtPlLVqz4oYC+snyX3UMGxdcXULrR7m OeDg== X-Gm-Message-State: ACgBeo1RynD0qvhlzKvB+zRc4EyDmUYJhR5AQuVtniT9OQ5suuk0YzVv derdz4J65yeBCvNUXl8cf2llKP+uVAFa8a+m X-Google-Smtp-Source: AA6agR6USGxWbsqZi9oBQalQcfm3NPdy82O3pZ+81iqRsz4g5ISCbyUZFaGYX7JHyj0c0apQ4avqjw== X-Received: by 2002:a17:902:ec90:b0:16d:d156:2c01 with SMTP id x16-20020a170902ec9000b0016dd1562c01mr4925810plg.114.1659668760651; Thu, 04 Aug 2022 20:06:00 -0700 (PDT) Received: from ffyuanda.localdomain ([113.65.229.239]) by smtp.gmail.com with ESMTPSA id i6-20020a654d06000000b0040df0c9a1aasm570234pgt.14.2022.08.04.20.05.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Aug 2022 20:06:00 -0700 (PDT) From: Shaoxuan Yuan To: git@vger.kernel.org Cc: vdye@github.com, derrickstolee@github.com, Shaoxuan Yuan Subject: [PATCH v2 7/9] mv: cleanup empty WORKING_DIRECTORY Date: Fri, 5 Aug 2022 11:05:26 +0800 Message-Id: <20220805030528.1535376-8-shaoxuan.yuan02@gmail.com> X-Mailer: git-send-email 2.37.0 In-Reply-To: <20220805030528.1535376-1-shaoxuan.yuan02@gmail.com> References: <20220719132809.409247-1-shaoxuan.yuan02@gmail.com> <20220805030528.1535376-1-shaoxuan.yuan02@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Originally, moving from-in-to-out may leave an empty directory on-disk (this kind of directory is marked as WORKING_DIRECTORY). Cleanup such directories if they are empty (don't have any entries under them). Modify two tests that take as WORKING_DIRECTORY to test this behavior. Suggested-by: Derrick Stolee Signed-off-by: Shaoxuan Yuan --- builtin/mv.c | 27 +++++++++++++++++++++++++++ t/t7002-mv-sparse-checkout.sh | 4 ++++ 2 files changed, 31 insertions(+) diff --git a/builtin/mv.c b/builtin/mv.c index e4a14aea2d..a58387a986 100644 --- a/builtin/mv.c +++ b/builtin/mv.c @@ -171,6 +171,9 @@ int cmd_mv(int argc, const char **argv, const char *prefix) }; const char **source, **destination, **dest_path, **submodule_gitfile; const char *dst_w_slash; + const char **src_dir = NULL; + int src_dir_nr = 0, src_dir_alloc = 0; + struct strbuf a_src_dir = STRBUF_INIT; enum update_mode *modes, dst_mode = 0; struct stat st; struct string_list src_for_dst = STRING_LIST_INIT_NODUP; @@ -304,6 +307,10 @@ int cmd_mv(int argc, const char **argv, const char *prefix) /* last - first >= 1 */ modes[i] |= WORKING_DIRECTORY; + + ALLOC_GROW(src_dir, src_dir_nr + 1, src_dir_alloc); + src_dir[src_dir_nr++] = src; + n = argc + last - first; REALLOC_ARRAY(source, n); REALLOC_ARRAY(destination, n); @@ -487,6 +494,26 @@ int cmd_mv(int argc, const char **argv, const char *prefix) } } + /* + * cleanup the empty src_dirs + */ + for (i = 0; i < src_dir_nr; i++) { + int dummy; + strbuf_addstr(&a_src_dir, src_dir[i]); + /* + * if entries under a_src_dir are all moved away, + * recursively remove a_src_dir to cleanup + */ + if (index_range_of_same_dir(a_src_dir.buf, a_src_dir.len, + &dummy, &dummy) < 1) { + remove_dir_recursively(&a_src_dir, 0); + } + strbuf_reset(&a_src_dir); + } + + strbuf_release(&a_src_dir); + free(src_dir); + if (gitmodules_modified) stage_updated_gitmodules(&the_index); diff --git a/t/t7002-mv-sparse-checkout.sh b/t/t7002-mv-sparse-checkout.sh index fc9577b2a6..23d0c4cec6 100755 --- a/t/t7002-mv-sparse-checkout.sh +++ b/t/t7002-mv-sparse-checkout.sh @@ -366,6 +366,7 @@ test_expect_success 'move dirty path 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 && + mkdir sub/dir/deep && test_must_fail git mv sub/dir folder1 2>stderr && cat sparse_error_header >expect && @@ -376,6 +377,7 @@ test_expect_success 'move dir from in-cone to out-of-cone' ' 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 "H sub/dir/e" actual && @@ -385,6 +387,7 @@ test_expect_success 'move 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 && + mkdir sub/dir/deep && touch sub/dir/e2 sub/dir/e3 && git add sub/dir/e2 sub/dir/e3 && echo "modified" >>sub/dir/e2 && @@ -400,6 +403,7 @@ test_expect_success 'move partially-dirty dir from in-cone to out-of-cone' ' git mv --sparse sub/dir folder1 2>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 && From patchwork Fri Aug 5 03:05:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shaoxuan Yuan X-Patchwork-Id: 12936836 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 C2CF2C19F2A for ; Fri, 5 Aug 2022 03:06:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237139AbiHEDGr (ORCPT ); Thu, 4 Aug 2022 23:06:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38090 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240047AbiHEDGb (ORCPT ); Thu, 4 Aug 2022 23:06:31 -0400 Received: from mail-pg1-x52c.google.com (mail-pg1-x52c.google.com [IPv6:2607:f8b0:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 74C2AEE38 for ; Thu, 4 Aug 2022 20:06:03 -0700 (PDT) Received: by mail-pg1-x52c.google.com with SMTP id bh13so1577376pgb.4 for ; Thu, 04 Aug 2022 20:06: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=l+6w4KbvUR8fvO/OdiGiJz3W8kvsA10zemHwlZRgFrQ=; b=kOr8eHAHMbRpKX34oT58TwCcnOaKZCBxLKsbox7IOGsOJboIeCvhIWnk/ClsAg4AUs Bi1cbTcOTRTqB1FTnCp9nWzMtmQ4ig5Hb5E7qzwLigz5ogOQCrVecnn+hN6LaGpbab/I 6kDv8VSizZJUwu+B7naTvNnNiQe/GSccYsalUcv8tmPcpQVAmycuuEe88/2YXDBYTBpB GvJZyNp62PxS5ntyvk28jq98oQ20X/nVG0S71v0VO8hnC8imYgqXfLmoEYAiCaXAEvJg Jb9iF/P2r2Jh16KOyoI3wirlKOMgV8qA2xm+4mmhM5ahuUvZFjzjUZIwxcbS+BN2joGj HMwA== 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=l+6w4KbvUR8fvO/OdiGiJz3W8kvsA10zemHwlZRgFrQ=; b=AIY+adLw4dc3KEJqOjR+mL/aey2iU0pQVzJ17dppYAo9dcV6vcfZNd3/50MYXwoyvo 9jKhG1GbQq8e5XNNIbeiOaNjdPwWwI7yKDQI55SxinA+6HZ07AG9H+mJxP2I/GTExm9R eJuoXfOzsp4vGSqhz0MyGVSXw2+IFmpL4i/fMOnYv7s0gqec1osSoiak0DI1H1javXQO vSxrxg5xMsuzAg6vKodd6NLE0rKJ4JA4SSABwyJQZuWClglk7HBlQ2PWVYp0cOuZ6+s2 J1sMYPCMWSpMxiL1/T0PGOAZgcxJ7mvh0usdm7EC+zt+oORa7sdm07hzfhe9DgCU3BXH 457g== X-Gm-Message-State: ACgBeo3xL970iTa3gnAGBs4yxbfTToIA9cWNy8KCXG0W8k6+q+m9ZNf9 7JONta5OZ81QFdzU7fRaBzKdXocZZCIftocJ X-Google-Smtp-Source: AA6agR5Qh+TqALfkQBIurx5C0DO8ySIcCRovBqOpRQGPghx/D7BypernCJexx2ifnIsj1CtyOJqkYQ== X-Received: by 2002:a63:3243:0:b0:41c:ea5f:b29d with SMTP id y64-20020a633243000000b0041cea5fb29dmr3300477pgy.433.1659668762338; Thu, 04 Aug 2022 20:06:02 -0700 (PDT) Received: from ffyuanda.localdomain ([113.65.229.239]) by smtp.gmail.com with ESMTPSA id i6-20020a654d06000000b0040df0c9a1aasm570234pgt.14.2022.08.04.20.06.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Aug 2022 20:06:02 -0700 (PDT) From: Shaoxuan Yuan To: git@vger.kernel.org Cc: vdye@github.com, derrickstolee@github.com, Shaoxuan Yuan Subject: [PATCH v2 8/9] advice.h: add advise_on_moving_dirty_path() Date: Fri, 5 Aug 2022 11:05:27 +0800 Message-Id: <20220805030528.1535376-9-shaoxuan.yuan02@gmail.com> X-Mailer: git-send-email 2.37.0 In-Reply-To: <20220805030528.1535376-1-shaoxuan.yuan02@gmail.com> References: <20220719132809.409247-1-shaoxuan.yuan02@gmail.com> <20220805030528.1535376-1-shaoxuan.yuan02@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Add an advice. When the user use `git mv --sparse `, Git will warn the user to use `git add --sparse ` then use `git sparse-checkout reapply` to apply the sparsity rules. Add a few lines to previous "move dirty path" tests so we can test this new advice is working. Suggested-by: Derrick Stolee Signed-off-by: Shaoxuan Yuan --- advice.c | 19 +++++++++++++++++++ advice.h | 1 + builtin/mv.c | 3 +++ t/t7002-mv-sparse-checkout.sh | 24 +++++++++++++++++++++++- 4 files changed, 46 insertions(+), 1 deletion(-) 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 a58387a986..765a1e8eb5 100644 --- a/builtin/mv.c +++ b/builtin/mv.c @@ -514,6 +514,9 @@ int cmd_mv(int argc, const char **argv, const char *prefix) strbuf_release(&a_src_dir); free(src_dir); + if (dirty_paths.nr) + advise_on_moving_dirty_path(&dirty_paths); + if (gitmodules_modified) stage_updated_gitmodules(&the_index); diff --git a/t/t7002-mv-sparse-checkout.sh b/t/t7002-mv-sparse-checkout.sh index 23d0c4cec6..f0b32a2f70 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' ' @@ -355,6 +368,10 @@ test_expect_success 'move dirty path from in-cone to out-of-cone' ' 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 && @@ -402,6 +419,11 @@ test_expect_success 'move partially-dirty dir from in-cone to out-of-cone' ' 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 && From patchwork Fri Aug 5 03:05:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shaoxuan Yuan X-Patchwork-Id: 12936837 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 484DDC19F2A for ; Fri, 5 Aug 2022 03:06:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240157AbiHEDG5 (ORCPT ); Thu, 4 Aug 2022 23:06:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38056 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236133AbiHEDGc (ORCPT ); Thu, 4 Aug 2022 23:06:32 -0400 Received: from mail-pg1-x52f.google.com (mail-pg1-x52f.google.com [IPv6:2607:f8b0:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C812B101F7 for ; Thu, 4 Aug 2022 20:06:04 -0700 (PDT) Received: by mail-pg1-x52f.google.com with SMTP id bh13so1577421pgb.4 for ; Thu, 04 Aug 2022 20:06: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=MWf9s3Lm8yrbGwwBbzyZN+RdRUj7ojNrhg84WfEReR4=; b=dPitKpd8XBCHXvhV5yerWoR4PYFTnq8AAFJn9T/7rV7K3Yirbfeq5ePh4uITtRseC8 zXncaFDMGOpL+QwKXB4g098vet+y4vfZpXnPl2+f+VHpqEb2IN9lotCCCkHZKfKPd5sg zGtXJrbAeedWMya4GPRZU/9uzcXOZGmSPZ/MNgyWBVswUeVeRYeXb5q27qtdscigo/n2 By+iOPmgv8PYfMyjVwL130S/MHybmb9loKGQpWwSpM89J4Jf01ZK9E7urYwjACBkltFq oHFi7JrR7ykMhXuJMuIQAmEPgg94By0LTojm93cbQCdFGlAi4kojm/uw3OlKmbX71BLM RPRw== 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=MWf9s3Lm8yrbGwwBbzyZN+RdRUj7ojNrhg84WfEReR4=; b=GBf3vhcMfhNEljUbDPg2eXD/gA6M5w1+mrgNb3fhHix2yxJkAxVR1ZJDtblWnuVpsX YSWtjmQdUom74OgVVfjyRDhE8/3vkHC6/IvZ3SlUUreWl86kCUXRhja/yO9ll5CL5kkc iMTOi5nfynhapOf48Pdmq7EkV9yr9Suf4tU28G9OYsvKCv4+KypGr4Y78bJo73ydq0pb me76Rz6cfHAK51dvQEwMafT9UfQI6B9wKZ8EWsG6LFwAjtoTwELoDKrT55dpmTcz2Vxi yaa5p5HQ4y5FO43xKehqqpvKvNHIGdCR1G4YmMCaHclVFzY74/K3dDewqtDhgU6I7Ds7 VLoA== X-Gm-Message-State: ACgBeo1NPVOux7jPklhCxBVkEx3iQbONa/qGOLSGd+YhjUk+CmVfCloj 56AB1hCQg3fF4k4ved/xSrG15ybwRBnsYSOo X-Google-Smtp-Source: AA6agR4T2WA6LfZLEQLwzQcv1NUasHV7/UmFE4IiSZXi5zJumbhvyzN0MqJd8STJnU3lZFPqHjQCDg== X-Received: by 2002:a65:6d1b:0:b0:41d:431:eaff with SMTP id bf27-20020a656d1b000000b0041d0431eaffmr1021021pgb.592.1659668764142; Thu, 04 Aug 2022 20:06:04 -0700 (PDT) Received: from ffyuanda.localdomain ([113.65.229.239]) by smtp.gmail.com with ESMTPSA id i6-20020a654d06000000b0040df0c9a1aasm570234pgt.14.2022.08.04.20.06.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Aug 2022 20:06:03 -0700 (PDT) From: Shaoxuan Yuan To: git@vger.kernel.org Cc: vdye@github.com, derrickstolee@github.com, Shaoxuan Yuan Subject: [PATCH v2 9/9] mv: check overwrite for in-to-out move Date: Fri, 5 Aug 2022 11:05:28 +0800 Message-Id: <20220805030528.1535376-10-shaoxuan.yuan02@gmail.com> X-Mailer: git-send-email 2.37.0 In-Reply-To: <20220805030528.1535376-1-shaoxuan.yuan02@gmail.com> References: <20220719132809.409247-1-shaoxuan.yuan02@gmail.com> <20220805030528.1535376-1-shaoxuan.yuan02@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Add checking logic for overwriting when moving from in-cone to out-of-cone. It is the index version of the original overwrite logic. Helped-by: Derrick Stolee 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 765a1e8eb5..70996d582f 100644 --- a/builtin/mv.c +++ b/builtin/mv.c @@ -367,6 +367,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 f0b32a2f70..50bcca583c 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 "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 &&