From patchwork Wed Mar 25 14:36:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiang Xin X-Patchwork-Id: 11457995 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7BF261392 for ; Wed, 25 Mar 2020 14:36:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5B2F72077D for ; Wed, 25 Mar 2020 14:36:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="AuAjzoZX" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727661AbgCYOgW (ORCPT ); Wed, 25 Mar 2020 10:36:22 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:36780 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727593AbgCYOgW (ORCPT ); Wed, 25 Mar 2020 10:36:22 -0400 Received: by mail-pf1-f193.google.com with SMTP id i13so1130774pfe.3 for ; Wed, 25 Mar 2020 07:36:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=YDpMoAAF8jxVQVIRb8n3Cm6LNcFDvAtJrGuHV2tBSDA=; b=AuAjzoZXsio65IvCyQQCkWel4a0fS4+3y4l38CDbfYtKI9dWJGy4qUCJH7p7S3XFWa N978igmeQZ8xOSzAZ2E044ovW0xWm22IQryfN7k9BgUhc86rtS2kA2Upvqkb/6Hyjj+U LnM51UhZJJnl5KXIaOaD8PqKCfOP9wEdKLUPhwl6ilmJ753F++bmlAGdNWC18+ecfH5n rfwQYAyKmXGCo1yGvVCUK2T4LHog2GaQgTuohuX61VutGwKx0OSh2/XVZgLMeuMCJdqv JjG8JJH+ivizfkgoOE7XyOJPPFbpvp0h1+t4f0jSAWczsDstSjohBJ5J/Xet352QdQmi 4NPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=YDpMoAAF8jxVQVIRb8n3Cm6LNcFDvAtJrGuHV2tBSDA=; b=eKWrsDANH5OToKM7eSCMs+/lUg6sGQMwcGMC1cT7963IRiG+X7sZhh5W+RO08jOr0k ubeyP9opmWKlS83wtwbqs/JSVRpEkduHVjN+NoXWhAe1wI66h7pstDP2+vLkzH78D+AY E/UZreJZdnllJF0YCRLZZU5EChhlB9xFiw3/hcJX6ZA7qAUQyKXrZ6f9XjTGhNZrBJeH QZMRE+aqZu32ZIhobKGV7jlsPTkJOK/Bk9qadoOIxG0I6doC79haqKXwlLk1vlePk/AM z6g+hfO1aeWnUSq2KT5DA0dbwrLlbkOc+GuIywvWSd4s6wpqwgkTKZ1zNCv26+of9lmZ GQ2Q== X-Gm-Message-State: ANhLgQ2/th3kFV0DFsztJmallvq2ZTq2XjEV0u+vOYEbB/63kXMOhpRL 87JjGvmIWqtOtmOMJPqOGzo= X-Google-Smtp-Source: ADFU+vv41q6SHPoHgpDCDP+vSOAVFAhAj4W/a0QWtNlmn84D3QjKuEqlIrjflKuVrjAgKtXT4TehJw== X-Received: by 2002:a65:5846:: with SMTP id s6mr3405642pgr.179.1585146981224; Wed, 25 Mar 2020 07:36:21 -0700 (PDT) Received: from localhost.localdomain ([47.89.83.3]) by smtp.gmail.com with ESMTPSA id f127sm18180423pfa.112.2020.03.25.07.36.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 25 Mar 2020 07:36:20 -0700 (PDT) From: Jiang Xin X-Google-Original-From: Jiang Xin To: Junio C Hamano , Git List , Emily Shaffer Cc: Jiang Xin Subject: [PATCH 1/3] t5543: never report what we do not push Date: Wed, 25 Mar 2020 22:36:06 +0800 Message-Id: <20200325143608.45141-2-zhiyou.jx@alibaba-inc.com> X-Mailer: git-send-email 2.26.0.3.ga7a9d752d4 In-Reply-To: <20200322131815.11872-3-worldhello.net@gmail.com> References: <20200322131815.11872-3-worldhello.net@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org When we push some references to the git server, we expect git to report the status of the references we are pushing; no more, no less. But when pusing with atomic mode, if some references cannot be pushed, Git reports the reject message on all references in the remote repository. Add new test cases in t5543, and fix them in latter commit. Signed-off-by: Jiang Xin --- t/t5543-atomic-push.sh | 92 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) diff --git a/t/t5543-atomic-push.sh b/t/t5543-atomic-push.sh index 7079bcf9a0..4b4c0a262b 100755 --- a/t/t5543-atomic-push.sh +++ b/t/t5543-atomic-push.sh @@ -27,6 +27,13 @@ test_refs () { test_cmp expect actual } +format_git_output () { + awk '/^(To| !) / {print}' | \ + sed \ + -e "s/ *\$//g" \ + -e "s/'/\"/g" +} + test_expect_success 'atomic push works for a single branch' ' mk_repo_pair && ( @@ -191,4 +198,89 @@ test_expect_success 'atomic push is not advertised if configured' ' test_refs master HEAD@{1} ' +# References in upstream : master(1) one(1) foo(1) +# References in workbench: master(2) foo(1) two(2) bar(2) +# Atomic push : master(2) two(2) bar(2) +test_expect_failure 'atomic push reports (reject by update hook)' ' + mk_repo_pair && + ( + cd workbench && + # Keep constant output. + git config core.abbrev 7 && + test_commit one && + git branch foo && + git push up master one foo && + git tag -d one + ) && + ( + mkdir -p upstream/.git/hooks && + cat >upstream/.git/hooks/update <<-EOF && + #!/bin/sh + + if test "\$1" = "refs/heads/bar" + then + echo >2 "Pusing to branch bar is prohibited" + exit 1 + fi + EOF + chmod a+x upstream/.git/hooks/update + ) && + ( + cd workbench && + test_commit two && + git branch bar + ) && + test_must_fail git -C workbench \ + push --atomic up master two bar >out 2>&1 && + format_git_output actual && + cat >expect <<-EOF && + To ../upstream + ! [remote rejected] master -> master (atomic push failure) + ! [remote rejected] two -> two (atomic push failure) + ! [remote rejected] bar -> bar (hook declined) + EOF + test_cmp expect actual +' + +# References in upstream : master(1) one(1) foo(1) +# References in workbench: master(2) foo(1) two(2) bar(2) +test_expect_failure 'atomic push reports (mirror, but reject by update hook)' ' + ( + cd workbench && + git remote remove up && + git remote add up ../upstream + ) && + test_must_fail git -C workbench \ + push --atomic --mirror up >out 2>&1 && + format_git_output actual && + cat >expect <<-EOF && + To ../upstream + ! [remote rejected] master -> master (atomic push failure) + ! [remote rejected] one (atomic push failure) + ! [remote rejected] bar -> bar (hook declined) + ! [remote rejected] two -> two (atomic push failure) + EOF + test_cmp expect actual +' + +# References in upstream : master(2) one(1) foo(1) +# References in workbench: master(1) foo(1) two(2) bar(2) +test_expect_failure 'atomic push reports (reject by non-ff)' ' + rm upstream/.git/hooks/update && + ( + cd workbench && + git push up master && + git reset --hard HEAD^ + ) && + test_must_fail git -C workbench \ + push --atomic up master foo bar >out 2>&1 && + format_git_output actual && + cat >expect <<-EOF && + To ../upstream + ! [rejected] master -> master (non-fast-forward) + ! [rejected] bar -> bar (atomic push failed) + EOF + test_cmp expect actual +' + test_done From patchwork Wed Mar 25 14:36:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiang Xin X-Patchwork-Id: 11457997 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0D6D31392 for ; Wed, 25 Mar 2020 14:36:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E28E020789 for ; Wed, 25 Mar 2020 14:36:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="tWm7+ti8" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727721AbgCYOgZ (ORCPT ); Wed, 25 Mar 2020 10:36:25 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:39846 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727593AbgCYOgZ (ORCPT ); Wed, 25 Mar 2020 10:36:25 -0400 Received: by mail-pl1-f194.google.com with SMTP id m1so866776pll.6 for ; Wed, 25 Mar 2020 07:36:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=dHa6uqTK/ZIi/VV7jI6KqiVSLQ3QUAQUv38qUzYy6l0=; b=tWm7+ti8uyTkOZvJiAuwSx32lGEPCDWPLbdev3FOth9piWo52hJ5Ij9vl2N+ruWd0M g6sI/AKqr8mwVxlwB04ZgJ40wQLPxs/87/LiqtQaA+0iYKN1GaES7bVxd2PSs40Nze0C BbEjLgVVnggj9r2A8DCd+9bjvstfqBKxiqCCt+YwFj6mgEJnJ8tvf9oejEkGI8bMZFo0 PGHU27snyUo9kkvVwqrMeGiIit0F0PJ5Bl0YLfuaEOorZrAd+nHqdM1Nxm+PzAeBCZuQ tZkzNN4N0XOcbOWD9tUBGxF3XASeMgziSqF+NhGAwtlxf0x4Y0bcB7FBpxExvuRdFfig 6vIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=dHa6uqTK/ZIi/VV7jI6KqiVSLQ3QUAQUv38qUzYy6l0=; b=Mdss4mmE9FHLKDTR3frhwkhqLLhHa1Nz1xkOeYx1A3fN80alrTJmkW60SHBqdGs+Kx 8Y2BqbELvbhUfvCLNAZNU1src/DzdHhyyTtYXfGpDUAsY1iy7g4RBGJySZB7eRzVKW7G AgpfBcho9xpPDSS6BYpkOxkG3iwUZdzUtgsqg/rzV3UiIZzMq43YDC24NMOWmirMHLdz RNcI3OuNpfG3l7WDsreJcAN2Y+YsA4KK0fiPz8a71weGK1fovExPwQ6kGXBqF3HYLJsW 7ezI6NMacVQZDMKN7nMH8mF8+buXWc7b9U1rUEARoN+9Y1cF6tmmnEF9WaKabX1vdVPb vcpg== X-Gm-Message-State: ANhLgQ1Yep4sjjvV6e4SLHu62np/nD3HaYqLpJVJKgRcOD58Qb65ZgLl sg9auU9et4UXFydfYruqjuU= X-Google-Smtp-Source: ADFU+vtaR0GQ48qkOnnb3efsdciWPprpoyy0pJLXr6q68qKRie9Boo6kUcdGpNoOUGy0D74y8Po/8g== X-Received: by 2002:a17:90a:178e:: with SMTP id q14mr4332799pja.132.1585146983187; Wed, 25 Mar 2020 07:36:23 -0700 (PDT) Received: from localhost.localdomain ([47.89.83.3]) by smtp.gmail.com with ESMTPSA id f127sm18180423pfa.112.2020.03.25.07.36.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 25 Mar 2020 07:36:22 -0700 (PDT) From: Jiang Xin X-Google-Original-From: Jiang Xin To: Junio C Hamano , Git List , Emily Shaffer Cc: Jiang Xin Subject: [PATCH 2/3] send-pack: mark failure of atomic push properly Date: Wed, 25 Mar 2020 22:36:07 +0800 Message-Id: <20200325143608.45141-3-zhiyou.jx@alibaba-inc.com> X-Mailer: git-send-email 2.26.0.3.ga7a9d752d4 In-Reply-To: <20200322131815.11872-3-worldhello.net@gmail.com> References: <20200322131815.11872-3-worldhello.net@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org When pusing with SSH or other smart protocol, references are validated by function `check_to_send_update()` beforce they are sent in commands to `send_pack()` of "receve-pack". For atomic push, if a reference is rejected after the validation, only references pushed by user should be marked as failure, instead of report failure on all remote references. Commit v2.22.0-1-g3bca1e7f9f (transport-helper: enforce atomic in push_refs_with_push, 2019-07-11) wanted to fix report issue of HTTP protocol, but marked all remote references failure for atomic push. Revert part of that commit and add additional status for function `atomic_push_failure()`. The additional status for it except the "REF_STATUS_EXPECTING_REPORT" status are: - REF_STATUS_NONE : Not marked as "REF_STATUS_EXPECTING_REPORT" yet. - REF_STATUS_OK : Assume OK for dryrun or status_report is disabled. This commit break test case in t5541, and will fix in other commit. Signed-off-by: Jiang Xin --- send-pack.c | 2 ++ t/t5541-http-push-smart.sh | 2 +- t/t5543-atomic-push.sh | 6 +++--- transport.c | 14 -------------- 4 files changed, 6 insertions(+), 18 deletions(-) diff --git a/send-pack.c b/send-pack.c index 0407841ae8..ff016c468c 100644 --- a/send-pack.c +++ b/send-pack.c @@ -334,6 +334,8 @@ static int atomic_push_failure(struct send_pack_args *args, continue; switch (ref->status) { + case REF_STATUS_NONE: + case REF_STATUS_OK: case REF_STATUS_EXPECTING_REPORT: ref->status = REF_STATUS_ATOMIC_PUSH_FAILED; continue; diff --git a/t/t5541-http-push-smart.sh b/t/t5541-http-push-smart.sh index 23be8ce92d..2c2c3fb0f5 100755 --- a/t/t5541-http-push-smart.sh +++ b/t/t5541-http-push-smart.sh @@ -177,7 +177,7 @@ test_expect_success 'push (chunked)' ' test $HEAD = $(git rev-parse --verify HEAD)) ' -test_expect_success 'push --atomic also prevents branch creation, reports collateral' ' +test_expect_failure 'push --atomic also prevents branch creation, reports collateral' ' # Setup upstream repo - empty for now d=$HTTPD_DOCUMENT_ROOT_PATH/atomic-branches.git && git init --bare "$d" && diff --git a/t/t5543-atomic-push.sh b/t/t5543-atomic-push.sh index 4b4c0a262b..d7be1c098b 100755 --- a/t/t5543-atomic-push.sh +++ b/t/t5543-atomic-push.sh @@ -201,7 +201,7 @@ test_expect_success 'atomic push is not advertised if configured' ' # References in upstream : master(1) one(1) foo(1) # References in workbench: master(2) foo(1) two(2) bar(2) # Atomic push : master(2) two(2) bar(2) -test_expect_failure 'atomic push reports (reject by update hook)' ' +test_expect_success 'atomic push reports (reject by update hook)' ' mk_repo_pair && ( cd workbench && @@ -244,7 +244,7 @@ test_expect_failure 'atomic push reports (reject by update hook)' ' # References in upstream : master(1) one(1) foo(1) # References in workbench: master(2) foo(1) two(2) bar(2) -test_expect_failure 'atomic push reports (mirror, but reject by update hook)' ' +test_expect_success 'atomic push reports (mirror, but reject by update hook)' ' ( cd workbench && git remote remove up && @@ -265,7 +265,7 @@ test_expect_failure 'atomic push reports (mirror, but reject by update hook)' ' # References in upstream : master(2) one(1) foo(1) # References in workbench: master(1) foo(1) two(2) bar(2) -test_expect_failure 'atomic push reports (reject by non-ff)' ' +test_expect_success 'atomic push reports (reject by non-ff)' ' rm upstream/.git/hooks/update && ( cd workbench && diff --git a/transport.c b/transport.c index 1fdc7dac1a..75c5c9fe98 100644 --- a/transport.c +++ b/transport.c @@ -1240,20 +1240,6 @@ int transport_push(struct repository *r, err = push_had_errors(remote_refs); ret = push_ret | err; - if ((flags & TRANSPORT_PUSH_ATOMIC) && err) { - struct ref *it; - for (it = remote_refs; it; it = it->next) - switch (it->status) { - case REF_STATUS_NONE: - case REF_STATUS_UPTODATE: - case REF_STATUS_OK: - it->status = REF_STATUS_ATOMIC_PUSH_FAILED; - break; - default: - break; - } - } - if (!quiet || err) transport_print_push_status(transport->url, remote_refs, verbose | porcelain, porcelain, From patchwork Wed Mar 25 14:36:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiang Xin X-Patchwork-Id: 11458001 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4586D139A for ; Wed, 25 Mar 2020 14:36:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 25537208CA for ; Wed, 25 Mar 2020 14:36:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="hr68l2oV" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727848AbgCYOga (ORCPT ); Wed, 25 Mar 2020 10:36:30 -0400 Received: from mail-pl1-f182.google.com ([209.85.214.182]:46036 "EHLO mail-pl1-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727809AbgCYOg1 (ORCPT ); Wed, 25 Mar 2020 10:36:27 -0400 Received: by mail-pl1-f182.google.com with SMTP id b9so854799pls.12 for ; Wed, 25 Mar 2020 07:36:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=YldpHljorqSItlmtAJicqf9shB217Y3+gvmG7lnmgik=; b=hr68l2oVxFk0G0P0L/CX8UteLGw4J8JOVU/Bqhr/jdcVhGtTg8XTrr523CNrIWQl+3 UKHUqT+h++ilWqZf2GGFEtOTMa6MAtQIwoMLVIWcF4Ioakpxd9lUhooc2JxWkfeerq5V ckD1pTHot7asAxzx8OLsJGSaI0k37Xum1hu9nBgm2qIvrsGnklWZ6yTLOHfWsjp46FGF gZw/S8fQO8Z9YR5gwCgSnED16U0/MElbQjtZu3YX34u+dTw1od2jqIxu2s4T4i+I6VdL G6BIBzlvdYk5d3JdV5a613+rxyF4m/xrp21HbO01B60an/rE3xWZZ/JqZ1Otpw3ObY3q KCOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=YldpHljorqSItlmtAJicqf9shB217Y3+gvmG7lnmgik=; b=eXf+7ay3JNkfpCAMs6/sQBbHSbvcGAOB8lhIgFWL4LJ0Kmck1p7PQrg9jho2sPARPd QiuAksNphqGmR45JeiMVlZ9s+S5b9Y5qHMJXarIVGQtBcsq2vOxaIsAn79vPDkqHDx9e zv102apTjBQtz/8yjoHnwYcMFU9ZPFTwULkkrQwHT/RIblgPMvLCFZWZd5xCcJ7wmvyY 63x7+PkNk9vuKPhLeglQOJQlka97nMMKAW1MJQEI8eZ0tLvedNKHCEhjcWqCAEhF/+tZ nnxK6Rv5rMsrwVRpz0R+BvVUcYkHcmjjG6MGQGsOmDa/xkwoDDOEWOefQTSBPIHorpZk cNBA== X-Gm-Message-State: ANhLgQ0KIODYPRfFiVIFn/IODXYuJ5lDdfNFvkaS/3eSyEht+FoivBiV ULwLXJFD+c5QMHOsnxzO9Fw= X-Google-Smtp-Source: ADFU+vtVlf63xqaJbqXOU/XYZ4SF2CtDqdgwsurKX14m/RRgXi7WjIJdpTdbbQ43djCV9evBIHGm0A== X-Received: by 2002:a17:90a:198e:: with SMTP id 14mr3990069pji.164.1585146985449; Wed, 25 Mar 2020 07:36:25 -0700 (PDT) Received: from localhost.localdomain ([47.89.83.3]) by smtp.gmail.com with ESMTPSA id f127sm18180423pfa.112.2020.03.25.07.36.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 25 Mar 2020 07:36:24 -0700 (PDT) From: Jiang Xin X-Google-Original-From: Jiang Xin To: Junio C Hamano , Git List , Emily Shaffer Cc: Jiang Xin Subject: [PATCH 3/3] transport-helper: enforce atomic in push_refs_with_push Date: Wed, 25 Mar 2020 22:36:08 +0800 Message-Id: <20200325143608.45141-4-zhiyou.jx@alibaba-inc.com> X-Mailer: git-send-email 2.26.0.3.ga7a9d752d4 In-Reply-To: <20200322131815.11872-3-worldhello.net@gmail.com> References: <20200322131815.11872-3-worldhello.net@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Commit v2.22.0-1-g3bca1e7f9f (transport-helper: enforce atomic in push_refs_with_push, 2019-07-11) noticed the incomplete report of failure of an atomic push for HTTP protocol. But the implementation has a flaw that mark all remote references as failure. Only mark necessary references as failure in `push_refs_with_push()` of transport-helper. Signed-off-by: Jiang Xin --- t/t5541-http-push-smart.sh | 14 +++++++++++--- transport-helper.c | 15 +++++++++++++++ 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/t/t5541-http-push-smart.sh b/t/t5541-http-push-smart.sh index 2c2c3fb0f5..afc680d5e3 100755 --- a/t/t5541-http-push-smart.sh +++ b/t/t5541-http-push-smart.sh @@ -177,7 +177,10 @@ test_expect_success 'push (chunked)' ' test $HEAD = $(git rev-parse --verify HEAD)) ' -test_expect_failure 'push --atomic also prevents branch creation, reports collateral' ' +## References of remote: atomic1(1) master(2) collateral(2) other(2) +## References of local : atomic2(2) master(1) collateral(3) other(2) collateral1(3) atomic(1) +## Atomic push : master(1) collateral(3) atomic(1) +test_expect_success 'push --atomic also prevents branch creation, reports collateral' ' # Setup upstream repo - empty for now d=$HTTPD_DOCUMENT_ROOT_PATH/atomic-branches.git && git init --bare "$d" && @@ -189,7 +192,8 @@ test_expect_failure 'push --atomic also prevents branch creation, reports collat test_commit atomic2 && git branch collateral && git branch other && - git push "$up" master collateral other && + git push "$up" atomic1 master collateral other && + git tag -d atomic1 && # collateral is a valid push, but should be failed by atomic push git checkout collateral && @@ -224,7 +228,11 @@ test_expect_failure 'push --atomic also prevents branch creation, reports collat # the collateral failure refs should be indicated to the user grep "^ ! .*rejected.* atomic -> atomic .*atomic push failed" output && - grep "^ ! .*rejected.* collateral -> collateral .*atomic push failed" output + grep "^ ! .*rejected.* collateral -> collateral .*atomic push failed" output && + + # never report what we do not push + ! grep "^ ! .*rejected.* atomic1 " output && + ! grep "^ ! .*rejected.* other " output ' test_expect_success 'push --atomic fails on server-side errors' ' diff --git a/transport-helper.c b/transport-helper.c index 20a7185ec4..ab3b52eb14 100644 --- a/transport-helper.c +++ b/transport-helper.c @@ -894,6 +894,21 @@ static int push_refs_with_push(struct transport *transport, case REF_STATUS_REJECT_STALE: case REF_STATUS_REJECT_ALREADY_EXISTS: if (atomic) { + /* Mark other refs as failed */ + for (ref = remote_refs; ref; ref = ref->next) { + if (!ref->peer_ref && !mirror) + continue; + + switch (ref->status) { + case REF_STATUS_NONE: + case REF_STATUS_OK: + case REF_STATUS_EXPECTING_REPORT: + ref->status = REF_STATUS_ATOMIC_PUSH_FAILED; + continue; + default: + break; /* do nothing */ + } + } string_list_clear(&cas_options, 0); return 0; } else