From patchwork Fri May 24 07:32:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Wienand X-Patchwork-Id: 13672772 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 DEE5412E5E for ; Fri, 24 May 2024 07:34:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716536071; cv=none; b=dXMlzLxOqF/Idz6tVlBI8bKaVUPcDIVJnORjHhkRqeD5bqFcQIvCpq/L472hpG/kyDWGbO0TL4ayJbZQf3qsNSo16ljlLSMoEn1hCmu8JkL49EsidhkuT76/S4RQJS4Mvd7X/N4dPaZzrAe0EDTMroEOsi6/182f1G85L2FFzKA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716536071; c=relaxed/simple; bh=pDXRgrua6JJbUBTIL6Wugzrh2VWQLKVAmv7dGOEQyno=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CUTxnZjkDjNkMUlNhkefMmVXdbFo+34lZqhLgaK5vyFROB2S/+OgQqSC1RGG1MMu/z3DV+R6BkOrjNoyq86VBXhEfiFKunwgGW0e6l1uoTEMpQs0mBALGMy3h+Kub3EJcS6XIEHbyS65jQcVA2tfaiNX6J4I+/0ELbRYAB5T4cw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=JCS0gMBG; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="JCS0gMBG" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716536068; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Amod9xU8lgw8FTf/FjDgMFSU+p0WZkQYZn85tjYS7Nw=; b=JCS0gMBGlkZLDopVOupHVRyt++BNyqj7/WXv9HmAjmqke38/lbHjbFED/4wU1rYgrL7mMM xslN5HDthA+A1GSnIg6cfv7c+7nYtmTPQaVyWKx+GW4fVtoJVcUDqALvQp607v1ta9qlfq CBVJH1JyPPfJwxpv02DW0dt6+cabyq8= Received: from mail-yw1-f197.google.com (mail-yw1-f197.google.com [209.85.128.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-543-CbRcIfunOQC6FNT-TvIzWw-1; Fri, 24 May 2024 03:34:26 -0400 X-MC-Unique: CbRcIfunOQC6FNT-TvIzWw-1 Received: by mail-yw1-f197.google.com with SMTP id 00721157ae682-62a084a0780so10807637b3.3 for ; Fri, 24 May 2024 00:34:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716536065; x=1717140865; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Amod9xU8lgw8FTf/FjDgMFSU+p0WZkQYZn85tjYS7Nw=; b=dZ5HjklfuFUfAoX7Q4byCLs9HLLuepmfWZhZFDzQrN2m13ycugc4wu6UMZ37qeujGX naz8JbUe8bEhihsdh4DXbdxpQN6hhMPr41zLnlhpiBOcCsQpyXZN+WlctpQQIbHqQqQ+ k6nnE8osxjQUJUr0mhHR8N6YjO2XJaMhJ3D7xueHE06CZP/iz0rS3AY9VsiHd555THYs rAJ6wBir8uK1jl3K13nLc8+J+B60UQFxP6sTQus1nuUow0Rsfinq5RGJe61PneLYrvBW Qh0Wv3JlyBo35mNLsLk5dek+Rq5be2/HlezLGFL8ADRJPt8muPrGil8+jXt9U4g7MRXr QZbg== X-Gm-Message-State: AOJu0YzuD0bvnX6bmHBv9PMf9QreF6g0K2s7Vvr+OnbyEkwuEShFUcd9 LzXIh+IA9JShxLXRbsNVaA45RysR2ZS4/GjuZqjo/u32LoRvbnVnq8+UeKY0Wv4EhA/2vITjtIj K2yG0YZOOGxF0eHeNxP2gmiJrgTX2ITQXTuOefMVhKkxk2Q/TCTxArdUTLNiqzi43NIu7PQTlQ4 o+2RWurOHHoL731h5IAwEHyFhBjn4UL6GoMw== X-Received: by 2002:a0d:d8ca:0:b0:618:7a0d:d5ef with SMTP id 00721157ae682-62a08dc608emr14382077b3.28.1716536065489; Fri, 24 May 2024 00:34:25 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHO4JbcNHEguqq4qtCH6sTQetlmuU7qoQrntQU2LF5X0pb2EUU2K6ybyfxbaGNmRp+Atxy1TA== X-Received: by 2002:a0d:d8ca:0:b0:618:7a0d:d5ef with SMTP id 00721157ae682-62a08dc608emr14381887b3.28.1716536064938; Fri, 24 May 2024 00:34:24 -0700 (PDT) Received: from fedora19.redhat.com (203-12-11-234.dyn.launtel.net.au. [203.12.11.234]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6ac0710865fsm4893356d6.71.2024.05.24.00.34.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 May 2024 00:34:24 -0700 (PDT) From: Ian Wienand To: git@vger.kernel.org Cc: Ian Wienand Subject: [PATCH v4 1/3] Documentation: alias: rework notes into points Date: Fri, 24 May 2024 17:32:42 +1000 Message-ID: <20240524073411.1355958-1-iwienand@redhat.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240523043806.1223032-1-iwienand@redhat.com> References: <20240523043806.1223032-1-iwienand@redhat.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 There are a number of caveats when using aliases. Rather than stuffing them all together in a paragraph, let's separate them out into individual points to make it clearer what's going on. Signed-off-by: Ian Wienand --- Documentation/config/alias.txt | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Documentation/config/alias.txt b/Documentation/config/alias.txt index 01df96fab3..40851ef429 100644 --- a/Documentation/config/alias.txt +++ b/Documentation/config/alias.txt @@ -21,8 +21,9 @@ If the alias expansion is prefixed with an exclamation point, it will be treated as a shell command. For example, defining `alias.new = !gitk --all --not ORIG_HEAD`, the invocation `git new` is equivalent to running the shell command -`gitk --all --not ORIG_HEAD`. Note that shell commands will be -executed from the top-level directory of a repository, which may -not necessarily be the current directory. -`GIT_PREFIX` is set as returned by running `git rev-parse --show-prefix` -from the original current directory. See linkgit:git-rev-parse[1]. +`gitk --all --not ORIG_HEAD`. Note: ++ +* Shell commands will be executed from the top-level directory of a + repository, which may not necessarily be the current directory. +* `GIT_PREFIX` is set as returned by running `git rev-parse --show-prefix` + from the original current directory. See linkgit:git-rev-parse[1]. From patchwork Fri May 24 07:32:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Wienand X-Patchwork-Id: 13672773 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 0FB9C12E5E for ; Fri, 24 May 2024 07:34:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716536074; cv=none; b=KvpQD9O+JDKaRDDroDEPDws6XOTAfmJUpp6ohYl+tjviSC6aOb6kUO9hIm4sYF5GUZUCliTbbIKKN+bicsrSUls0gr2msehwPhal/wA9gClDOVGoybKPar5tDMUT0wBs5wjxdN70KrgXyZYdRb0aMJ/F8O79OkGNmZkfXtQxUmY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716536074; c=relaxed/simple; bh=PJvtKfLMFKRXxMYXIsU4d1eLp+QyOSaS6BdieMAUKLo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lNisnWjSqaykTYQDqZtW6Rw0bm9md01Xuunq8/KGstDtKbAgL1mBCkMvfliJvinB//sTt+JMaQQTZ3SXntE734335VhVbWudLgWjf+W/o1sBCwrERd83qPq19yaZHVeEPo60t7YOaoiHWXb8zX9USGFQuu5oHIMjZXVzxlJgSRg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=hTLKBqJm; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="hTLKBqJm" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716536071; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AotnOA3dFJRsRAdtubd8p/AXYapmtCEf7HP+7OF2O4s=; b=hTLKBqJm0o62ITN9tiCHYHGwfxdIN/vg83MKIrrIcsdhi6mAAA+Y8S5MmTjUTEUD0iqHq8 PC/1oJ5Ll2nGgu1LsbJ2Lv4l83aiJLdQxo7DrGddtOzQlpbycOAqKLbjLL0a5WZhgZSEzz 5RkdSg9VOhANcW4gnh82huBVnazCoiU= Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-125-3C6k5hzFPQWpYwOV4kW1iw-1; Fri, 24 May 2024 03:34:29 -0400 X-MC-Unique: 3C6k5hzFPQWpYwOV4kW1iw-1 Received: by mail-qv1-f69.google.com with SMTP id 6a1803df08f44-6ab9e01225eso9915406d6.0 for ; Fri, 24 May 2024 00:34:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716536069; x=1717140869; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=AotnOA3dFJRsRAdtubd8p/AXYapmtCEf7HP+7OF2O4s=; b=X2xBrygqPDT5cUBqN+OH6DzV+3UZrrPck8wI9qveMZwMXLa8w06A2hwSw9WZYlvjxh NR6OG7TtRk61J6dWIEILI/IHWbawvhTre9rBL+VtSZ9ZxcrRQ/TtIsCGN8Kz3dTojcVA NcDWIjPfsYSnjXPIUTkl+BQbw4nFbATwyXDIH3AId27C2wg+7/CBZb1GMGeHq4Stl1DJ EN1iklPJvQtm46ac0SNv5hOhd3sxqi+J4fW82RD1Rlt1NNMIcOCiFvBxe5lLTstXHWRY aVxw8aSaU1yj/kg7+MJeF5kA/Og2Gev9RDN7uVNAzaWlL0Qs7ouzJPoCIsSPPptX42oS WzDg== X-Gm-Message-State: AOJu0YzyCVBVzLQjAF+3xlNzdA3+bgfCKqpd2XLMSgDUItPny7YJirRa 8jIuLvfFf7QckO8jzyUh436xmWs2iEHUbQbCdHoTMawScv1c/eAgKPkLBi+LW3KgnmzzySCxD2S Zp/Yj5h4k1iLpO/4KNKn774cO76ItxosxSL6W1PnTHL4+TIH0coEGetDfoy57hbzxNSrNRvjaqj e/8LKCHBrdQbmGcFHtWIuysPK/WR+1cvgANA== X-Received: by 2002:a05:6214:625:b0:6a1:6081:6879 with SMTP id 6a1803df08f44-6ab8f5578f4mr76068896d6.17.1716536068922; Fri, 24 May 2024 00:34:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFoYVv32s/F0JPZ6CeDJD81G9R/PY03r7hnrCHi3XHnX8P6Ba/t3Wy9IhNPKYdfnkRaZCWTxg== X-Received: by 2002:a05:6214:625:b0:6a1:6081:6879 with SMTP id 6a1803df08f44-6ab8f5578f4mr76068616d6.17.1716536068413; Fri, 24 May 2024 00:34:28 -0700 (PDT) Received: from fedora19.redhat.com (203-12-11-234.dyn.launtel.net.au. [203.12.11.234]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6ac0710865fsm4893356d6.71.2024.05.24.00.34.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 May 2024 00:34:27 -0700 (PDT) From: Ian Wienand To: git@vger.kernel.org Cc: Ian Wienand Subject: [PATCH v4 2/3] Documentation: alias: add notes on shell expansion Date: Fri, 24 May 2024 17:32:43 +1000 Message-ID: <20240524073411.1355958-2-iwienand@redhat.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240524073411.1355958-1-iwienand@redhat.com> References: <20240523043806.1223032-1-iwienand@redhat.com> <20240524073411.1355958-1-iwienand@redhat.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 When writing inline shell for shell-expansion aliases (i.e. prefixed with "!"), there are some caveats around argument parsing to be aware of. This series of notes attempts to explain what is happening more clearly. Signed-off-by: Ian Wienand --- Documentation/config/alias.txt | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Documentation/config/alias.txt b/Documentation/config/alias.txt index 40851ef429..51fa876c91 100644 --- a/Documentation/config/alias.txt +++ b/Documentation/config/alias.txt @@ -27,3 +27,24 @@ it will be treated as a shell command. For example, defining repository, which may not necessarily be the current directory. * `GIT_PREFIX` is set as returned by running `git rev-parse --show-prefix` from the original current directory. See linkgit:git-rev-parse[1]. +* If the shell alias is the full path to a binary, it will be executed + directly with any arguments. +* If the alias contains any whitespace or reserved characters, it will + be considered an inline script and run as an argument to `sh -c`. +* When running as a script, Git appends "$@" to the alias shell + command when arguments are present. If there are no arguments, + `"$@"` will not be appended. +** This may initially be confusing if your alias script references + argument variables, or is otherwise not expecting the presence of + `"$@"`. For example: `alias.echo = "!echo $1"` when run as `git + echo arg` will actually execute `sh -c "echo $1 $@" "echo $1" + "arg"` resulting in output `arg arg`. An alias `alias.for = "!for + i in 1 2 3; do echo $i; done"` will fail if any arguments are + specified to `git for` as the appended `"$@"` will create invalid + shell syntax. +** A convenient way to deal with this is to write your script + operations in an inline function that is then called with any + arguments from the command-line. For example `alias.echo = "!e() { + echo $* ; }; e" will work as expected, with the function `e` + receiving any arugments from the command-line. +** Setting `GIT_TRACE=1` can help debug the command being run. From patchwork Fri May 24 07:32:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Wienand X-Patchwork-Id: 13672774 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 7BF4B3307B for ; Fri, 24 May 2024 07:34:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716536077; cv=none; b=X8cGNSDBtw0m7cYu/Txa8ZN3qTxp4z8rPLzPlY27qQU50cZrH2EgEQbrDbhqkwJrucuI90S2v1n2/qwqfNG8z4LMHlCWFQ94ZEcZlAObZ50cxQ61Mh71LvRKR+nf/KaT06olBK3p8xCkeTdGYIQRnMXG0wy/COOTofu5ygAQt9c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716536077; c=relaxed/simple; bh=3C9xNd5+0llTR6pS8OEf8G55WpH1tCpvQcGg5SgpmK8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PbQxJqqTlQBJ4aTZ+5jgvn4DUxSWfbizXZj5GVnxB3J/QilY/+WdV6sL6y7l70PvCrKRJ11GcF8umLuiBQrv+aZVnN+sIwSpYyCDM1S2mAT3/i71r2y9rehiQdAqLjNw8yu5HYNvQqZB9nNG9N33oCrrGJ53QtCaBeTJNqesKZE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=btndI4Qs; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="btndI4Qs" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716536074; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=t6EbyvMAGZNSN0LdW8Vx3hyL/VkHnKPDXbGOTFtSgws=; b=btndI4Qs5Ch8sMNIE9cMrqGi/Z4JNPlz3KfT1Rr4mQJx8IB/iKwx5RYN3LLdQTyrmEUFG0 qLUzJkn9nUBlG86bFFIgL8MJZ7gMsMOW0BxzriJTLQOnuKOPMYDs0oye+eg+f32BrI+C5r wWI1V6NDqLe2pKnCdUlpve/tIJvrqGI= Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-349-1Q-Li0gxNouOKnCq0T0rmQ-1; Fri, 24 May 2024 03:34:33 -0400 X-MC-Unique: 1Q-Li0gxNouOKnCq0T0rmQ-1 Received: by mail-qv1-f71.google.com with SMTP id 6a1803df08f44-6ab9d01cbc3so7590326d6.1 for ; Fri, 24 May 2024 00:34:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716536072; x=1717140872; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=t6EbyvMAGZNSN0LdW8Vx3hyL/VkHnKPDXbGOTFtSgws=; b=PoqewGtagbAo/cJcR3vpVztFrrkA7huYTcc+4xmP4AUPJduBhjRY2b74Hg2+/1PLMb ulYSOB/qBWPebWPft8rt1ShBF3pr+faGdF9YeuKHU66V0FvALi/+Dvy3D+jlV6DqQem5 uuHaCseAX6avKLk740Se4N1j+2qYzsTdo/NWSuozDLX6y3TOGY71lshsub70Imeml8Ek rXpcIhazKAPDvdlE5JaV3YaGBVWssHw19uuDtbi5Bn0nylgV/CMTg8XVGztEx6mR3/tH 38FB5lpzIfhs3xltP47AvItDGPByNZArWZtPWWTc+g+LVk2T/YSb9pjUyKYtfFeoG052 8tRQ== X-Gm-Message-State: AOJu0YwA6UQJgNuZDe1y7f2zAKh6mNAXsdz1xyZbwTS/j90fmdNavXAf a++Wmgtz8ilz85KOAgBDJ30MzqSKd9dF3/7or0Qh2DkV8tWc7pnAmRGFv7VOwAM+QYaCb3wexmU kZWIOap86lPAY276rWhv+TnPY/Px1MMRFzZiDCOwFhz19dDFJoMKfSJCCvx4OMrR1g+sJaGX1fS UTJBT7il2s1GrtUgm+ZkE+vz5DnMzwi9bGJw== X-Received: by 2002:a05:6214:4604:b0:6a0:c339:1ede with SMTP id 6a1803df08f44-6abcd0b54efmr17624386d6.40.1716536072249; Fri, 24 May 2024 00:34:32 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEqoZP6bGdZtFKyNSi/LThSrSRtLiYTNynnl2xwdsj5uhGkjavtOr3aNt7o8KlUf1hU4INxwQ== X-Received: by 2002:a05:6214:4604:b0:6a0:c339:1ede with SMTP id 6a1803df08f44-6abcd0b54efmr17624236d6.40.1716536071835; Fri, 24 May 2024 00:34:31 -0700 (PDT) Received: from fedora19.redhat.com (203-12-11-234.dyn.launtel.net.au. [203.12.11.234]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6ac0710865fsm4893356d6.71.2024.05.24.00.34.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 May 2024 00:34:31 -0700 (PDT) From: Ian Wienand To: git@vger.kernel.org Cc: Ian Wienand Subject: [PATCH v4 3/3] run-command: show prepared command Date: Fri, 24 May 2024 17:32:44 +1000 Message-ID: <20240524073411.1355958-3-iwienand@redhat.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240524073411.1355958-1-iwienand@redhat.com> References: <20240523043806.1223032-1-iwienand@redhat.com> <20240524073411.1355958-1-iwienand@redhat.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This adds a trace point in prepare_cmd (for windows, prepare_shell_cmd), so we can see the actual command being run without having to resort to strace/code inspection. e.g. "test = !echo" when run under GIT_TRACE will show: $ GIT_TRACE=1 git test hello 10:58:56.877234 git.c:755 trace: exec: git-test hello 10:58:56.877382 run-command.c:657 trace: run_command: git-test hello 10:58:56.878655 run-command.c:657 trace: run_command: echo hello 10:58:56.878747 run-command.c:437 trace: prepare_cmd: /usr/bin/echo hello hello A "split" alias, e.g. test = "!echo $*" will show the shell wrapping and appending of "$@". $ GIT_TRACE=1 git test hello 11:00:45.959420 git.c:755 trace: exec: git-test hello 11:00:45.959737 run-command.c:657 trace: run_command: git-test hello 11:00:45.961424 run-command.c:657 trace: run_command: 'echo $*' hello 11:00:45.961528 run-command.c:437 trace: prepare_cmd: /bin/sh -c 'echo $* "$@"' 'echo $*' hello hello hello Prior changes have made the documentation around the internals of the alias command execution clearer, but I have still found this detailed view of the aliased command being run helpful for debugging purposes. A test case is added. This simply looks for the trace point output; the details change depending on platform -- the important thing is that we have a verbose log point, not so much the details of what happens on each platform. Signed-off-by: Ian Wienand --- run-command.c | 2 ++ t/t0014-alias.sh | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/run-command.c b/run-command.c index 1b821042b4..13e35fb76e 100644 --- a/run-command.c +++ b/run-command.c @@ -296,6 +296,7 @@ static const char **prepare_shell_cmd(struct strvec *out, const char **argv) } strvec_pushv(out, argv); + trace_argv_printf(&out->v[1], "trace: prepare_cmd:"); return out->v; } @@ -435,6 +436,7 @@ static int prepare_cmd(struct strvec *out, const struct child_process *cmd) } } + trace_argv_printf(&out->v[1], "trace: prepare_cmd:"); return 0; } diff --git a/t/t0014-alias.sh b/t/t0014-alias.sh index 95568342be..b7affbe93a 100755 --- a/t/t0014-alias.sh +++ b/t/t0014-alias.sh @@ -44,4 +44,10 @@ test_expect_success 'run-command formats empty args properly' ' test_cmp expect actual ' +test_expect_success 'tracing a shell alias with arguments shows trace of prepared command' ' + git config alias.echo "!echo \$*" && + env GIT_TRACE=1 git echo argument 2>output && + test_grep "^trace: prepare_cmd:.*" output +' + test_done