From patchwork Sun Sep 8 07:05:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ren=C3=A9_Scharfe?= X-Patchwork-Id: 13795331 Received: from mout.web.de (mout.web.de [212.227.15.14]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 883C9A93D for ; Sun, 8 Sep 2024 07:05:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=212.227.15.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725779157; cv=none; b=raMkHripyvxC6d6WLxG6xTH9qZrk1O6L13NL+8bzdHyJl2GHB3uVP8xXB+lWh4SOmVjPjWKW/NySanNZpuRhatmesyU6vQ5vNdYg5T3DOph2e8cnNLiWzW7lVH0aL1qLx6/8RKnr8iK04cnLPH1yhPlgXJzQwHRpICWhUgpC/wQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725779157; c=relaxed/simple; bh=+qFJd2WWD2WsRy/i6lSt90bIFCQForn10wQ+AIoLMik=; h=Message-ID:Date:MIME-Version:To:From:Subject:Cc:Content-Type; b=Tk2/dBAhZlVKS8zp7Ne+/0235ZC4QlCw+5iz10o5tNpdM8NiAQOcPycX8bcvXXwCg2FMPlATEVSEKB9AHL0PAiUZzVlPFzt4+9hg2XrVL5Sszs0tHN3rtNXlSDLGx60YGhI8hQGFv/2DtLgD0rFkuOwJDU4bJF50oR7r915gNto= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=web.de; spf=pass smtp.mailfrom=web.de; dkim=pass (2048-bit key) header.d=web.de header.i=l.s.r@web.de header.b=cC/5kR5G; arc=none smtp.client-ip=212.227.15.14 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=web.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=web.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=web.de header.i=l.s.r@web.de header.b="cC/5kR5G" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=web.de; s=s29768273; t=1725779144; x=1726383944; i=l.s.r@web.de; bh=3WeJ9pGy+ZAYWeac1SK0VkmDN4Q1KOKaRg1yLNK1Gxk=; h=X-UI-Sender-Class:Message-ID:Date:MIME-Version:To:From:Subject: Cc:Content-Type:Content-Transfer-Encoding:cc: content-transfer-encoding:content-type:date:from:message-id: mime-version:reply-to:subject:to; b=cC/5kR5G0l5jOtuJludrEKAceh3fR4xErOdnfazukkj6CNVKcUZ3woh+wHDTmzPZ Pq39VqByFUNMBCcf+MdgOcvlz2FsWnB9JMg5ZxeqVVvTwdptIgbAvndy0pnhQ/w+R 3E6m48T5z2A1gWkmuqv8BuusDCKmSEW98CxieytHg96yJtk04tCyZHCKRrfLADTK2 3BF6DaAfqZ7fghea1PxBCqnLQ8ODkmJ25gYVrHbDSkxGTKBlQyOY9JPZfzk+ztYLW E9rYvcFIm2FSa+6IInwv8OzB200jX/0IflIvfNhpmxpnAF3Hji8COdpxsb7ZS2AC9 AFLpInhosLhWQzMHyw== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Received: from [192.168.178.29] ([91.47.152.211]) by smtp.web.de (mrweb006 [213.165.67.108]) with ESMTPSA (Nemesis) id 1Mft7t-1s7GbJ26u1-00igbg; Sun, 08 Sep 2024 09:05:44 +0200 Message-ID: <130d4803-2818-4611-9258-951a18dd5717@web.de> Date: Sun, 8 Sep 2024 09:05:44 +0200 Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US To: Git List From: =?utf-8?q?Ren=C3=A9_Scharfe?= Subject: [PATCH 1/2] diff: report copies and renames as changes in run_diff_cmd() Cc: Jorge Luis Martinez Gomez , David Hull X-Provags-ID: V03:K1:LR8jyB23f+BYvsB349G/I/sx/Hqtz3jZVpjHegWg37VKjiU478G 7k8NjtPfpwTIAeOrL38UDUIy3K58/bQi1l28KT3N0w7DxaikGPOoxFU4Va0T2YFMyfXMwWv w3kftLF64ZqFCtJ4OHFLGSp0K/KV3idf5AliGr+IdwGp7C90dYGeToLru951pjTrS5YR/7q MflZMPxIzP77lvoyU6TfA== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:4c/ihfTWUjE=;pvilP9U73SXS7Xxc4HKpB/lnF75 /q0zteY4Ht4ApIEU4eD/tcD8mvZvwDiMEdBmaqVnmtjEpoPO6zX0h6f3u3DutFnwD7/dR1PVP o9Di/QHsk+EvW1C5ys1NsvBJg/eS5HoPMp5A59PHxxpveTnJ8mCMH6ViFILPsH5cUQulbZE3o 4PKEHSrBM9w9CYLwGlYoJj+bIS6PuGg49GVoyosmVBcZN2XdXhs3n6ZQEUsgBoVbHHWhi4QT+ RefOGr/yKWYFQn7VDcNRJ+sT0hbbHDf0GuKhF2oBJwm3UO1kdAMsrA5c1zXxY4QZRTDa+8ehZ A9eDTO30V9daFgOwhZp1hjNdvfEdmqkHTlwBs4LdlHuh9w4UXAxNxUR1jr0/gEG21koAew4lE I4q5i9ejIjHHDyViDoDVX2xgl83wOP2hMpGrtmu0NSImaJmfBpUnkr2gFFfEnM5HVozeGQ8Fe OkS2iwM6DqAdPuM6DHj33WjnQglD6nBzPz0mY4j8nv/EFnPC57EzWRDgrlcpgJgW6CJ1LsU7M wfn2Q6T198lq43gVlyKL1/eU0wXIEs6cUn1nQSHE0B93VlLhxyU0AWIDwO/QQfIrDMxzd3gLH 67mvmx82vEl6MWCwfj+0QdDPX/6FDbjoTs1ZvLUrZ67+Ol1JeQXfV3cZNNEA/K3C0B5hwzjad EkecYzzuXT7V0NIKMlG4+7co8RvPpIucmZa85rSmtRzZ0xbH7dl3JeLzhIhEy93qC5Q5pO9lW +syrLPOPP1zkKtRA7EBtzwNnqzPCPSq5KtSUobRwhD4rpVXWb51HwyGF0TTtEZdXcJQvmr+UR m7h3v4dSofwsUxH4PFZkTHJA== The diff machinery has two ways to detect changes to set the exit code: Just comparing hashes and comparing blob contents. The latter is needed if certain changes have to be ignored, e.g. with --ignore-space-change or --ignore-matching-lines. It's enabled by the diff_options flag diff_from_contents. The slower mode has never considered copies and renames to be changes, which is inconsistent with the quicker one. Fix it. Even if we ignore the file contents (because it's empty or contains only ignored lines), there's still the meta data change of adding or changing a filename, so we need to report it in the exit code. d7b97b7185 (diff: let external diffs report that changes are uninteresting, 2024-06-09) set diff_from_contents if external diff programs are allowed. This is the default e.g. for git diff, and so that change exposed the inconsistency much more widely. Reported-by: Jorge Luis Martinez Gomez Signed-off-by: René Scharfe --- diff.c | 3 +++ t/t4017-diff-retval.sh | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) -- 2.46.0 diff --git a/diff.c b/diff.c index 4035a9374d..1d2057d4cb 100644 --- a/diff.c +++ b/diff.c @@ -4587,6 +4587,9 @@ static void run_diff_cmd(const struct external_diff *pgm, builtin_diff(name, other ? other : name, one, two, xfrm_msg, must_show_header, o, complete_rewrite); + if (p->status == DIFF_STATUS_COPIED || + p->status == DIFF_STATUS_RENAMED) + o->found_changes = 1; } else { fprintf(o->file, "* Unmerged path %s\n", name); o->found_changes = 1; diff --git a/t/t4017-diff-retval.sh b/t/t4017-diff-retval.sh index f439f469bd..9a4f578614 100755 --- a/t/t4017-diff-retval.sh +++ b/t/t4017-diff-retval.sh @@ -143,4 +143,20 @@ test_expect_success 'option errors are not confused by --exit-code' ' grep '^usage:' err ' +for option in --exit-code --quiet +do + test_expect_success "git diff $option returns 1 for copied file" " + git reset --hard && + cp a copy && + git add copy && + test_expect_code 1 git diff $option --cached --find-copies-harder + " + + test_expect_success "git diff $option returns 1 for renamed file" " + git reset --hard && + git mv a renamed && + test_expect_code 1 git diff $option --cached + " +done + test_done From patchwork Sun Sep 8 07:08:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ren=C3=A9_Scharfe?= X-Patchwork-Id: 13795332 Received: from mout.web.de (mout.web.de [212.227.15.14]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 63F9461FCE for ; Sun, 8 Sep 2024 07:08:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=212.227.15.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725779323; cv=none; b=M7UD7ouCFWvfzurSpXZtIbFyp8OjWB1ffNl4oSN0cTd/WS0J7WZGC5u7ZArhHyCfaI06M+tkhHpYIcUOWKXu53LkFIQ0zzF/1JLvTqjTb+0E9PvDjhnt7mhgtc5pikEnpbphxnz/F2rmXoqw05K8bAbnXStKi7rRRCFIov2eE1M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725779323; c=relaxed/simple; bh=bXYQzW8ADbW+VuIrbh5TX/3i3EGmmCA+Ce7HlqhbGmA=; h=Message-ID:Date:MIME-Version:Subject:From:To:Cc:References: In-Reply-To:Content-Type; b=DtSS4u7aM6BUcYZoGhl/0FFzdUWWqE1myB8rVxkskvADS2f7/1wgMPiHUHvZRreSTd7JLSzqMQCRwcbR3jj63o8skdfLvIPvy/eEMVT6s/y8Ok7Zc+cCQsvFRIQGJSo7lKRx8fC1Ulf1n3LbNTKOkMyTvRC8W0+Jj3GT9dw8gLU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=web.de; spf=pass smtp.mailfrom=web.de; dkim=pass (2048-bit key) header.d=web.de header.i=l.s.r@web.de header.b=BmwT7KRR; arc=none smtp.client-ip=212.227.15.14 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=web.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=web.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=web.de header.i=l.s.r@web.de header.b="BmwT7KRR" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=web.de; s=s29768273; t=1725779316; x=1726384116; i=l.s.r@web.de; bh=0lSCcjiwqr9yH+CSm8JA/z0n2gK11CgPLFoMQ627LWY=; h=X-UI-Sender-Class:Message-ID:Date:MIME-Version:Subject:From:To: Cc:References:In-Reply-To:Content-Type:Content-Transfer-Encoding: cc:content-transfer-encoding:content-type:date:from:message-id: mime-version:reply-to:subject:to; b=BmwT7KRR3CQD9ggk4QNEUmrmp30B8inlhkv9iIMDNfwVUcZjUDA/MtfwIonQqjdy Vl2HLKpKEmyiVwzNG5eh4CgmKgbpAAeWOMdBX6RbnjU8caSCl/9qD0SDd6DuYU1MW 8MYWaqD6oNaPEW9gtakxhBC0A1Oprd3Yay+iGBC8SvdWc6O22+TfN1D0+Xjrl5sZ4 GgdBYzJIod+92bmLN1cA0ciUsVeva4kLdcrhMBRWkeQhovBC6K3NcVcxlsgrErQYh TnUMvhGEcxJlnRtpUi58W8BqTSLfxSSE84Yck7WoPdEw31Wq0JTRCDRexIwVepiFB GFlOfpYZLoQ0gRghjw== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Received: from [192.168.178.29] ([91.47.152.211]) by smtp.web.de (mrweb005 [213.165.67.108]) with ESMTPSA (Nemesis) id 1MREzA-1sQ2Rb4AHk-00TDr5; Sun, 08 Sep 2024 09:08:36 +0200 Message-ID: <0864c86a-5562-4780-92c5-59d6c1a35aad@web.de> Date: Sun, 8 Sep 2024 09:08:35 +0200 Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH 2/2] diff: report dirty submodules as changes in builtin_diff() From: =?utf-8?q?Ren=C3=A9_Scharfe?= To: Git List Cc: Jorge Luis Martinez Gomez , David Hull References: <130d4803-2818-4611-9258-951a18dd5717@web.de> Content-Language: en-US In-Reply-To: <130d4803-2818-4611-9258-951a18dd5717@web.de> X-Provags-ID: V03:K1:7dB3cTp1Ts9wGR/iXVsz9QmvkwdXJefWiVT48ho/UUKi1/eGgDS woMdhWzV8ahdtfOzOkWmKSd0JOxrYfVVpnGHjilJEd0SxGsmAMGUtBraMyU8bCkIl8eFnkZ OXlmadpiR0BfJIanroK1klmlsMJIA9b21IFAr0z1P/dmqwtcnCqYIIyuqUPM/sxT63KkMaE 6Hmnd1j+YcIa1vRz5R9dQ== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:JFfPWE9FAwI=;tjqKD+HPlAyQDT6SJ8uk9oz5Bta xHbWQbyE+Lzs0tQhQBd07PSofkntkJjYV4W0mYN7oK1UeVBL59aUsWxP4PbwWDp7o0ewxaAhl q5gli52JuH3BFH2a5r2u1F78qhDNZxli0aCcKwWK8z4jSqIE0UIshXa2kcKBUOanvm8s25rGE rexpBVNS2POuTzvkuyJMH7UbjEZVDBsPx/rjo6kzLCfuhuW8DhsvyAePoFrOJtW1b/dohCBfH pdzmMeMAJZPK8J7UuSAPYWutY5wa1b607YLdBGUGl53+XTyYkkAYsNukokGH0IPLZ6naBvQs8 qo0RnD2BgLSQum4VDSQz1CCiZqY1Gx32QBxUsqkDtzMwvZPI3+nfEwekmKpfWwDrCmmmrzX9E AIFBIsEtKNloKtFJa2p2vz2IRhbGWGFKBZaGGFh7jaGayI/DXJKkyuU+HS8W+2wx1GJJlMUlu 7L+jDk+I/q54UtferyEqPNnUDJS55w8bXZqpMdxxPV7wanRvSUaDiWky7/cglCe7wYMZTnjdQ 24DWSlZJR4sRb1cQ/bOlXfAW78cJ6TQT1TUBLwK08xFNCJRL2oqyn2FQ0cax+UN8Z3Wr8n86N niWBLSRMU9eHiqXUOnmwc3DmmoKKD8VBrWB9chbHfYnuy5+hJxpjy6W3Y9DNd37jndpAKADmR bRp1sHWk+Rwxg3FjjuVGWr9KT8aqPfe6vYCr8eg+t+xM08872cyOo4E6qmtNkHt5iXNSOqslE EpmfLjNbvka8dpduN2srwrwCzKdHNQP4vnlu4t+xsagMnDRL4WVXvOtXCqxEO+H1FbljxxE5+ LDzi8HE8cp0w2FlITydfagkw== The diff machinery has two ways to detect changes to set the exit code: Just comparing hashes and comparing blob contents. The latter is needed if certain changes have to be ignored, e.g. with --ignore-space-change or --ignore-matching-lines. It's enabled by the diff_options flag diff_from_contents. The slower mode as never considered submodules (and subrepos) as changes with --submodule=diff or --submodule=log, which is inconsistent with --submodule=short (the default). Fix it. d7b97b7185 (diff: let external diffs report that changes are uninteresting, 2024-06-09) set diff_from_contents if external diff programs are allowed. This is the default e.g. for git diff, and so that change exposed the inconsistency much more widely. Reported-by: David Hull Signed-off-by: René Scharfe --- diff.c | 2 ++ t/t4017-diff-retval.sh | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+) -- 2.46.0 diff --git a/diff.c b/diff.c index 1d2057d4cb..472479eb10 100644 --- a/diff.c +++ b/diff.c @@ -3565,6 +3565,7 @@ static void builtin_diff(const char *name_a, show_submodule_diff_summary(o, one->path ? one->path : two->path, &one->oid, &two->oid, two->dirty_submodule); + o->found_changes = 1; return; } else if (o->submodule_format == DIFF_SUBMODULE_INLINE_DIFF && (!one->mode || S_ISGITLINK(one->mode)) && @@ -3573,6 +3574,7 @@ static void builtin_diff(const char *name_a, show_submodule_inline_diff(o, one->path ? one->path : two->path, &one->oid, &two->oid, two->dirty_submodule); + o->found_changes = 1; return; } diff --git a/t/t4017-diff-retval.sh b/t/t4017-diff-retval.sh index 9a4f578614..d644310e22 100755 --- a/t/t4017-diff-retval.sh +++ b/t/t4017-diff-retval.sh @@ -159,4 +159,25 @@ do " done +test_expect_success 'setup dirty subrepo' ' + git reset --hard && + test_create_repo subrepo && + test_commit -C subrepo subrepo-file && + test_tick && + git add subrepo && + git commit -m subrepo && + test_commit -C subrepo another-subrepo-file +' + +for option in --exit-code --quiet +do + for submodule_format in diff log short + do + opts="$option --submodule=$submodule_format" && + test_expect_success "git diff $opts returns 1 for dirty subrepo" " + test_expect_code 1 git diff $opts + " + done +done + test_done