From patchwork Mon Apr 29 18:37:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Rub=C3=A9n_Justo?= X-Patchwork-Id: 13647509 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8A0F312A163 for ; Mon, 29 Apr 2024 18:37:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714415828; cv=none; b=nwkpole2PCOKlBvfClqVkzkw/IajSjoR9dUL7j9ix6PZLmoTrY7tpwct0n9U3dFcEB63xaz61dAzolEyEDcaNq/iJs5oOXEa345hxSPGWdcFMhNGY4sEy89cCDb6ag9CjSZRT4PcqttkIRHU/nTOdOj6gmA8+a4xQKAyk77sORk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714415828; c=relaxed/simple; bh=yFM5oI63A9uNsDc6KN2pfgod3ZImNPjtAA08IR99yjA=; h=Message-ID:Date:MIME-Version:Subject:From:To:Cc:References: In-Reply-To:Content-Type; b=vExWiqjddiEzp0YwKQbePB2KqqjR0WSt7xMt2q/Rgf7uhBxQcupLBL9qMafG8RB+r5btXHZi5J2d/cWnq0BuWMEhgVHMnrKu11EgsaeuqCZEZdw48Vh1HVaTix+8coQWBIUspyAI3JaF1BCrro/GOcahG5Es4j29mkNe+NpZOvw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=NH6QHWfk; arc=none smtp.client-ip=209.85.128.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="NH6QHWfk" Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-41c1b75ca31so11605405e9.2 for ; Mon, 29 Apr 2024 11:37:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714415825; x=1715020625; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=HSwtg4YXCraQfJxePaAe0vpas53CBWi4HkuctTIDVkk=; b=NH6QHWfkFTNTH6Q9BWRp3PUhUOAFI4JC0GC64BQJmcHkprq4UBbuAKQ1B/GRzvHrZG rt0Vg2Jku9T8i4FO9BerNRo55oNSNlBHMvdOxHHqaLfxQyHVjPJy9l9HJQhMgjToM2b5 4SQb8DeIiuz92bnzcFWBxbMF640zRLXTwbaeRq5YOCFzLAlSML1coM7Kf4F/dwMqwFzg nDSIG2YIUM8PS3QahqpkHaAFCcMDia4rJl4xQ7rfvXnnh09JdAGvA+bf4K9BBziR30dw UURcSDyl+WgpMqmuiw6kMlHSiMAQ99Wx220EC43DSaCLEMt8oZYIGJ48UupBI+95KN3r UPBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714415825; x=1715020625; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=HSwtg4YXCraQfJxePaAe0vpas53CBWi4HkuctTIDVkk=; b=HApcZaHJVz/lItBBkYBmJp1zlObJf0qxbdys2xekgI1y2FH99vDGpMvOXkV/wPk3eO W1dZgRaOIxF9kMRCFJPU8+qea5lZSDmnlik0eP3IkLAJVLOiQHubm85o/hrcAYX8PslL oNnbQQm5p0E8CsQj/V4rc+tYAEUXTfqILjnCsTMgQAu8B3wFp27T0J0gME2QdWJRNxQw 2ge/Yev9bLFYuizB2CMKR3ah0T7CdKrb/wokpHAwjWBH3hyKw3bK840ZtVF/2W+DVaRl 5HgSij5ZcB0ALDtKJBx5Urp1ffJw6fn++K+mDXyW+FTBt+OOeRMpPkqp019mexJLmLx6 QDiA== X-Gm-Message-State: AOJu0YzMSapA2NdFZcS8VbgHy982raXxhPkCfty1qEWYvhyGn5orbMvT +uYX6vfzs4HKXdPA42XBbeHVt5uQGl3nr/NXfunjKN7JSuXAPFjQaZdLTw== X-Google-Smtp-Source: AGHT+IE7UcoMaz7rUJ3m5py29qua7ulkpIn/B2NN+wV5gZnhgCtEFltpOxycAeQ3kXZ0TMUpnQRtgw== X-Received: by 2002:a05:600c:3542:b0:415:6afd:9ba6 with SMTP id i2-20020a05600c354200b004156afd9ba6mr8281405wmq.1.1714415824647; Mon, 29 Apr 2024 11:37:04 -0700 (PDT) Received: from gmail.com (111.red-88-14-45.dynamicip.rima-tde.net. [88.14.45.111]) by smtp.gmail.com with ESMTPSA id n40-20020a05600c502800b0041b4c293f75sm17354556wmr.13.2024.04.29.11.37.04 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 29 Apr 2024 11:37:04 -0700 (PDT) Message-ID: <10905ab3-bb3c-4669-9177-84c8e6759616@gmail.com> Date: Mon, 29 Apr 2024 20:37:03 +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 v5 1/2] add-patch: do not show UI messages on stderr Content-Language: en-US From: =?utf-8?q?Rub=C3=A9n_Justo?= To: Git List Cc: Phillip Wood , Patrick Steinhardt , Junio C Hamano , Jeff King References: <4e2bc660-ee33-4641-aca5-783d0cefcd23@gmail.com> <6d421c67-9e10-4a7b-9782-38ba8e9da915@gmail.com> <952a9514-3cf1-4601-8f0d-db57adc750c3@gmail.com> In-Reply-To: <952a9514-3cf1-4601-8f0d-db57adc750c3@gmail.com> There is no need to show some UI messages on stderr, and yet doing so may produce some undesirable results, such as messages appearing in an unexpected order. Let's use stdout for all UI messages, and adjusts the tests accordingly. Signed-off-by: Rubén Justo --- add-patch.c | 13 ++++++------- t/t3701-add-interactive.sh | 12 ++++++------ 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/add-patch.c b/add-patch.c index 0997d4af73..fc0eed4fd4 100644 --- a/add-patch.c +++ b/add-patch.c @@ -293,10 +293,9 @@ static void err(struct add_p_state *s, const char *fmt, ...) va_list args; va_start(args, fmt); - fputs(s->s.error_color, stderr); - vfprintf(stderr, fmt, args); - fputs(s->s.reset_color, stderr); - fputc('\n', stderr); + fputs(s->s.error_color, stdout); + vprintf(fmt, args); + puts(s->s.reset_color); va_end(args); } @@ -1326,7 +1325,7 @@ static int apply_for_checkout(struct add_p_state *s, struct strbuf *diff, err(s, _("Nothing was applied.\n")); } else /* As a last resort, show the diff to the user */ - fwrite(diff->buf, diff->len, 1, stderr); + fwrite(diff->buf, diff->len, 1, stdout); return 0; } @@ -1778,9 +1777,9 @@ int run_add_p(struct repository *r, enum add_p_mode mode, break; if (s.file_diff_nr == 0) - fprintf(stderr, _("No changes.\n")); + err(&s, _("No changes.")); else if (binary_count == s.file_diff_nr) - fprintf(stderr, _("Only binary files changed.\n")); + err(&s, _("Only binary files changed.")); add_p_state_clear(&s); return 0; diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh index 04d8333373..c5531520cb 100755 --- a/t/t3701-add-interactive.sh +++ b/t/t3701-add-interactive.sh @@ -45,13 +45,13 @@ test_expect_success 'warn about add.interactive.useBuiltin' ' cat >expect <<-\EOF && warning: the add.interactive.useBuiltin setting has been removed! See its entry in '\''git help config'\'' for details. - No changes. EOF + echo "No changes." >expect.out && for v in = =true =false do git -c "add.interactive.useBuiltin$v" add -p >out 2>actual && - test_must_be_empty out && + test_cmp expect.out out && test_cmp expect actual || return 1 done ' @@ -335,13 +335,13 @@ test_expect_success 'different prompts for mode change/deleted' ' test_expect_success 'correct message when there is nothing to do' ' git reset --hard && - git add -p 2>err && - test_grep "No changes" err && + git add -p >out && + test_grep "No changes" out && printf "\\0123" >binary && git add binary && printf "\\0abc" >binary && - git add -p 2>err && - test_grep "Only binary files changed" err + git add -p >out && + test_grep "Only binary files changed" out ' test_expect_success 'setup again' ' From patchwork Mon Apr 29 18:37:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Rub=C3=A9n_Justo?= X-Patchwork-Id: 13647510 Received: from mail-wr1-f51.google.com (mail-wr1-f51.google.com [209.85.221.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3F01012A14B for ; Mon, 29 Apr 2024 18:37:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714415836; cv=none; b=iEs5g2xRbrRo6KOXJU5MyEA7LPjnEwWNPuBCH9brVtsC8JECEXArKtikSpfxjW/N/ZpX5TVXC8mcO+5NYigSFK0YArzD4WX88yYfOxX4iv+MyaV9vVAY55SCY0vB6JcHo3+UqKuVzlhnCwOPTvg3pvBGZUbdgNSmXN7gDw1Q4a8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714415836; c=relaxed/simple; bh=UKKPpYPTIB8l6rR71ijJperwJQGhIrQ6LtOA+ai1gV4=; h=Message-ID:Date:MIME-Version:Subject:From:To:Cc:References: In-Reply-To:Content-Type; b=kNEzI+sSDJfIkRnD9yn0BeFGuEVsbOIoYZLfFxMaKFuKTjtnvAeWHl3vib81M9oCBf3cYNXmjIh+dWX+yZHoUdS9l5YTURVXc5s9xdkRcbfL+C2HKu4YcUDZf5MpZ0UcR3JxB/72Rq4aaYwXsSGqa705rCtAcuETyzPLibL+lWM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=gZRWDflp; arc=none smtp.client-ip=209.85.221.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="gZRWDflp" Received: by mail-wr1-f51.google.com with SMTP id ffacd0b85a97d-346406a5fb9so4134363f8f.1 for ; Mon, 29 Apr 2024 11:37:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714415833; x=1715020633; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:from:subject:user-agent:mime-version:date:message-id:from:to :cc:subject:date:message-id:reply-to; bh=TB1BoVLiOux/HPrW8MyruJIMsPdwJkw5+l58oyD5a3c=; b=gZRWDflpgFUed+jErj0I1C9QR6dG+Gv+hfVDbZqrWjixJ9UymByFn2LGUsSZjwQRVw vk1HOsm61hhiD4MjlUCeBFjknO7mRsoNAi924uFqXGv+gK2X6a/CudmoD9luQn7ORzJl ziptgQ96s373tu2nzBgoA0hNhRRBDKcy+DIMEYvaE+SQkWpTWOCFeSGcILcDK27M3BvQ Ad3Ycqy/t8SRoVJ4Rf6DLKia8PbGlHjB6HbMHbVp+M4HukFufWRQu2jm4FKPE0Y1rUWE bkyNVPOEv9hzZCbPj2sfpxt83A6UVTtle6ifdQ8h7YVj+rdEKCrcijqLgfKspwd042KU UL5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714415833; x=1715020633; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:from:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=TB1BoVLiOux/HPrW8MyruJIMsPdwJkw5+l58oyD5a3c=; b=qWD7o/hFoFoXbb48g3go/45UyBWOprNddrUfmzu5qRArwnTqiBxqvz2hN9TeuTWOmZ +pVstV6UKBlLYkqFPyemtSziplL4hhDwAba2unrnol6A5yiQLC2ObIKL8cYg/X491L9O LGupat1ZXnYihexLpV99WNd0bAzsnWChJD3SUL1UbqN+lvUUzzC6P7GN4zMDQM4IBTJw 9F6DImYwugNOdC1YMaRZ8Zqc/U9RzFL504nYe9Xr90L1q/q2M496I7VADth/FUt5ANcl a13P5O2HSAVtmCGZlkB0OoExYeBd1yu3lX0em6Kv7mNmJPQbPD54El9P5U49oDln/AT3 MV+w== X-Gm-Message-State: AOJu0Yy2nCyrKlQb+FY0klYs6+j75PViDXQNupTeY1Myr8tdZ5lf4sju UuwmmP7LIj0+bhqUEVOhppA65dwoB3qmWfo6j+Sr/vwArqG7WL//L0WgBQ== X-Google-Smtp-Source: AGHT+IGu/rXE/3QjHO3sx2HUj7VIABt4K3Ebp6u3f5c2R1WFftbi5sZmH6fYbC3/BTBX9weEzqUjWw== X-Received: by 2002:adf:9791:0:b0:34a:e884:977b with SMTP id s17-20020adf9791000000b0034ae884977bmr6492035wrb.32.1714415833242; Mon, 29 Apr 2024 11:37:13 -0700 (PDT) Received: from gmail.com (111.red-88-14-45.dynamicip.rima-tde.net. [88.14.45.111]) by smtp.gmail.com with ESMTPSA id cs18-20020a056000089200b003437799a373sm30347591wrb.83.2024.04.29.11.37.12 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 29 Apr 2024 11:37:12 -0700 (PDT) Message-ID: <95c0dfff-3b11-4156-a502-c741fc0b76f7@gmail.com> Date: Mon, 29 Apr 2024 20:37:12 +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 v5 2/2] add-patch: response to unknown command From: =?utf-8?q?Rub=C3=A9n_Justo?= To: Git List Cc: Phillip Wood , Patrick Steinhardt , Junio C Hamano , Jeff King References: <4e2bc660-ee33-4641-aca5-783d0cefcd23@gmail.com> <6d421c67-9e10-4a7b-9782-38ba8e9da915@gmail.com> <952a9514-3cf1-4601-8f0d-db57adc750c3@gmail.com> Content-Language: en-US In-Reply-To: <952a9514-3cf1-4601-8f0d-db57adc750c3@gmail.com> When the user gives an unknown command to the "add -p" prompt, the list of accepted commands with their explanation is given. This is the same output they get when they say '?'. However, the unknown command may be due to a user input error rather than the user not knowing the valid command. To reduce the likelihood of user confusion and error repetition, instead of displaying the list of accepted commands, display a short error message with the unknown command received, as feedback to the user. Include a reminder about the current command '?' in the new message, to guide the user if they want help. Signed-off-by: Rubén Justo --- add-patch.c | 5 ++++- t/t3701-add-interactive.sh | 16 +++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/add-patch.c b/add-patch.c index fc0eed4fd4..2252895c28 100644 --- a/add-patch.c +++ b/add-patch.c @@ -1667,7 +1667,7 @@ static int patch_update_file(struct add_p_state *s, } } else if (s->answer.buf[0] == 'p') { rendered_hunk_index = -1; - } else { + } else if (s->answer.buf[0] == '?') { const char *p = _(help_patch_remainder), *eol = p; color_fprintf(stdout, s->s.help_color, "%s", @@ -1691,6 +1691,9 @@ static int patch_update_file(struct add_p_state *s, color_fprintf_ln(stdout, s->s.help_color, "%.*s", (int)(eol - p), p); } + } else { + err(s, _("Unknown command '%s' (use '?' for help)"), + s->answer.buf); } } diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh index c5531520cb..28a95a775d 100755 --- a/t/t3701-add-interactive.sh +++ b/t/t3701-add-interactive.sh @@ -8,6 +8,8 @@ TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY"/lib-terminal.sh +SP=" " + diff_cmp () { for x do @@ -56,6 +58,19 @@ test_expect_success 'warn about add.interactive.useBuiltin' ' done ' +test_expect_success 'unknown command' ' + test_when_finished "git reset --hard; rm -f command" && + echo W >command && + git add -N command && + git diff command >expect && + cat >>expect <<-EOF && + (1/1) Stage addition [y,n,q,a,d,e,p,?]? Unknown command ${SQ}W${SQ} (use ${SQ}?${SQ} for help) + (1/1) Stage addition [y,n,q,a,d,e,p,?]?$SP + EOF + git add -p -- command actual 2>&1 && + test_cmp expect actual +' + test_expect_success 'setup (initial)' ' echo content >file && git add file && @@ -232,7 +247,6 @@ test_expect_success 'setup file' ' ' test_expect_success 'setup patch' ' - SP=" " && NULL="" && cat >patch <<-EOF @@ -1,4 +1,4 @@