From patchwork Thu May 23 04:37:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Wienand X-Patchwork-Id: 13671253 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 7A657224D2 for ; Thu, 23 May 2024 04:38:27 +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=1716439109; cv=none; b=ZSOrcSXcv3sUuo6R+gtzmcIdQMCWl6GYIcHtd/LQNzWk4Tn8/cM/8MykSdKfDoYbN1jRBa/6MKDjBodk1RQBr7iZaNutBRqGWDdSBMxRDPi45PYzXmXYajMsQsw18fiwxyaXD+DeDDbg+6UADD2JlYsUOOJY51yR7bv3zDzjssc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716439109; c=relaxed/simple; bh=pDXRgrua6JJbUBTIL6Wugzrh2VWQLKVAmv7dGOEQyno=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QWBQ4kBNZ//DAgidrD25VHWDfy3UjDKtof8ePXCAyx+gOAsc+ZCZC7Eerlk+D13R4lppLz6CvqwvOrhPEm+Z26Yn/qde/htQLwcXLWhkJrBis9ONN459zolbM+F/eshZUm/9YmToWRc5NfBGpS+gzpcMGPpSOKbtEKgu2YF5r6g= 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=OlmUzIqM; 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="OlmUzIqM" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716439106; 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=OlmUzIqM+HBkESmn4K77MWKVre1tj0uZ93FYhFWXa7ctfqFE7QSVmlaxl9+P6IUoDlYeuz BkhSIrILQzkNJsxxpH73n7jtHXQ29yG0xT4WvTMo56X1IN2KlSc4nDLcLC8Y3thZCfs5oQ kjGijIjcvBea/zWEfU9yR/BeWIRqnUM= 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-619-iOpYBEpGMxKTtmRA_dMi2Q-1; Thu, 23 May 2024 00:38:24 -0400 X-MC-Unique: iOpYBEpGMxKTtmRA_dMi2Q-1 Received: by mail-qv1-f69.google.com with SMTP id 6a1803df08f44-6ab895670easo12479086d6.3 for ; Wed, 22 May 2024 21:38:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716439103; x=1717043903; 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=MVhB/1D2p/tNTZ3i4LvpC12X5wNc6pIthgScpBLRXXOVSidsZSNo8x4g2CNLDu6Sk+ eSCkf6/RlBtemVlPbOrT180FXbYjfll5io+NiIik7w23a0xoAApR55r983TzPDu+z6+Z TAECJIVmv1JstkElc4iHFt7zL23lHcQmVJZ6WBvPHnLa8xz4Juwps4qHfmTYhmvZ2KI0 TI4yYY4fGeW5v3fY33yhkEUZ8eTZAL43QbENPr423LgZrSj+a0igr90PDa95RfhlTb40 UBbwWwMsW5z2OiWDafM3K+ELx+YH20ivvkzZXOAp5zJLspmqX1CNywuQIIuyeE9OojT9 6ESg== X-Gm-Message-State: AOJu0Yz/5xjsXRwl8ZBs3+fKMjXbHhPB00NSFgiTwTUIkipq02ty8Am0 5dQcZCP+ZCHc59VZWuAie+6VBCdpyXjNJaEBofKpctbAH2hnJFRqklsmdS1KTpHQ/VRw2t8e4Ud H7HaPHd0hdDHyAIDeMz/j7SuAZq1GrLfSGaXSaGuACiB3DnrW0eWeqOuA0187Pv2Rz/h+v6mUFE GoYCMtTkGeTMsRu1QxjLyz4To3h/++PJ6xVg== X-Received: by 2002:a05:6214:2b9d:b0:6a9:944b:8fdb with SMTP id 6a1803df08f44-6ab7f332cd8mr41945616d6.9.1716439103501; Wed, 22 May 2024 21:38:23 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHnyDJzfncR0vX/Z7akPB5lCWFE4if2Ta4owJ1X24hkBaX47JMjGiI4QwWTiWlQUvMSST2IDA== X-Received: by 2002:a05:6214:2b9d:b0:6a9:944b:8fdb with SMTP id 6a1803df08f44-6ab7f332cd8mr41945466d6.9.1716439102901; Wed, 22 May 2024 21:38:22 -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-6a35969bcd5sm80952706d6.53.2024.05.22.21.38.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 May 2024 21:38:22 -0700 (PDT) From: Ian Wienand To: git@vger.kernel.org Cc: Ian Wienand Subject: [PATCH v3 1/3] Documentation: alias: rework notes into points Date: Thu, 23 May 2024 14:37:54 +1000 Message-ID: <20240523043806.1223032-1-iwienand@redhat.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240523042143.1220862-1-iwienand@redhat.com> References: <20240523042143.1220862-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 Thu May 23 04:37:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Wienand X-Patchwork-Id: 13671254 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 0769947F58 for ; Thu, 23 May 2024 04:38: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=1716439111; cv=none; b=gpMX+ZRSFHXUDmgDHt2g/oNxSYIGB9C5/Yf0hbMV4JEV6mm5mZ0bNiL93J/B1/mCPL2o9biieYN5qF4m7JBrLpX0fCxpWzkR3LDplrbYJwJwAZ+frx1Mr1lT4wxqLQU5z2lYTucAC+uxG5a04mR+OJBGT+CK5xbV/uFK3fSZ18w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716439111; c=relaxed/simple; bh=PJvtKfLMFKRXxMYXIsU4d1eLp+QyOSaS6BdieMAUKLo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=m3qd8LRsiJ+Ew7Q3Uf33AaRQ8Y97AOWFcoQxShuzg5jvNftSDvmFiX6bdtLieUZLQCnvcqasUqC1udOJZDX9g+BfnaVjHMucPKY8mj7CvsYIYWDHD2l90eb1yqFmxLbtSEgBjmlvqIWlTO2xbhQ/zeay7jidc5cbNAsVRLz2QNY= 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=Rebp4tVj; 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="Rebp4tVj" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716439108; 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=Rebp4tVjWA+vWwhUum+zcjRFNFNN/d1Xp0dohJ3duHSRd2VpOfVDyq0hahDTkxVdkOh6yE /dGqbVp9f+58wgGWZW/5Zl5ojLBKWp4/7m6ffjvYfUKMiSsb9LVODheuexJBKUAdZ+FxW8 joTUqlEusRvp505/18+kI5FbQocCCcA= Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-637-S56PQx3kPPGd0PMFRs8keA-1; Thu, 23 May 2024 00:38:27 -0400 X-MC-Unique: S56PQx3kPPGd0PMFRs8keA-1 Received: by mail-qv1-f70.google.com with SMTP id 6a1803df08f44-6ab895670easo12479366d6.3 for ; Wed, 22 May 2024 21:38:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716439106; x=1717043906; 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=j1641nJh5kk1+pjOl06RIhvkVWYhjZLSWvIzm/Lf4oVLAuku97e3Q0RXsMCNQdlYuf 5GMM92/dyxKDZwveERaVwGxxLatKHaaUSZTyTMgs4zjReiN2DE/ZyIvUgcbreVH61atq 77YvGe+58YqFnEVZtX3+zers8WwlT1mDNZkwVusBIIDSx3OEuEuj0u97RCjSh3tFL4Ji i0xUOphv4nkMkyKWRBpKsFPVUq3P4SntncU59JjZExyQPrmPwI48bRCV/ru48iGzK8/v M4fChANUBkNFX7onzU4tNLXeUu3VczC2WXl/s++Q8fk89QC6ewMMtEB6WOdTs8/UrE3c RVDQ== X-Gm-Message-State: AOJu0YytMMm8yjLt6tKhIRWsrs+CGutW066ncfdXC1YEJof/k2xhmjeA +UVi7gXWIUuc1EHaemeft0XlJKaIL339YCZ5o5hBQV20Porg7tdBcHVnrF7MdZXUKm0G9JsBDss Ziiw+CWX2rdHZUplrcy2GBFzOdmFhNg7oecwVi0sm2Y+4ffnmbJhd4aSaPd7h0HcvbmrpDbQ+D3 G8Bf/wgaGdwd5EOJTp0jBHjNSJgSb+OUNeqA== X-Received: by 2002:a05:6214:5a05:b0:6a9:ed54:be81 with SMTP id 6a1803df08f44-6ab808c96fdmr45510746d6.34.1716439106322; Wed, 22 May 2024 21:38:26 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEKLMoGvoyAn/+1wQJCpKzVdwWtN+LeZnXccRPId25Ke28d+wEKdr9qp3TYyWWRsTem6ljAXQ== X-Received: by 2002:a05:6214:5a05:b0:6a9:ed54:be81 with SMTP id 6a1803df08f44-6ab808c96fdmr45510526d6.34.1716439105786; Wed, 22 May 2024 21:38:25 -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-6a35969bcd5sm80952706d6.53.2024.05.22.21.38.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 May 2024 21:38:25 -0700 (PDT) From: Ian Wienand To: git@vger.kernel.org Cc: Ian Wienand Subject: [PATCH v3 2/3] Documentation: alias: add notes on shell expansion Date: Thu, 23 May 2024 14:37:55 +1000 Message-ID: <20240523043806.1223032-2-iwienand@redhat.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240523043806.1223032-1-iwienand@redhat.com> References: <20240523042143.1220862-1-iwienand@redhat.com> <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 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 Thu May 23 04:37:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Wienand X-Patchwork-Id: 13671255 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.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 A2D1C2AF06 for ; Thu, 23 May 2024 04:38:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716439114; cv=none; b=p5YoF2qHpzMC4EqUEuUkIgRWBuXJ04qYsqwzeopZFVAqi40rxBNIOxOHU+HR9hj4IUywrwBGQR8lmp41XUMBXhYex+yDAvEj6IYuYjJA4bal+3SCnrZemilbXDaTAYLnski0WU2dGLhW3+ln631rbNU8j8qKVxxQyLjK7dgQBwY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716439114; c=relaxed/simple; bh=U0m4XZd1AIv+0hALXaomAxzQtOvWE+WerAViUgfyrug=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ePolZU0iJFtQSPT009Aviu5j/6nZj/wJcGExiO9y6eKoXhLPgkBzj5X/ur3Wp3sYjIM5DVhERe3tMJKzFYEFxLx54BvvTNfZOs/WOAXL1gIiBCN9MAGjW7vWRWAQ6MiNdN8iOVkpEja3Sn7LcRGF5AuXnq15wbcM6+dqHl35Z7s= 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=JkBf948Z; arc=none smtp.client-ip=170.10.133.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="JkBf948Z" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716439111; 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=YgX6Cu5E7N2apTEs4XC6U+2EvwrXfbifiHWF2oc97wE=; b=JkBf948ZW9hlg7QPFW/LQUyM5t/kDN/X66d169aNKf0Xg1XB439N43AGK6LB4CCokTa+WG iK9/VVTAF9t5OQ5hkE88Sh64aAvdEv3euwBpNyMlBEibryxt8SSMtr2HtZ4tuC0ScIrEpE c/PS1o/HaLENCxobUf6Pof6bH018owE= Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-60-UN83E2M_PcOdOR5gSvA4aA-1; Thu, 23 May 2024 00:38:29 -0400 X-MC-Unique: UN83E2M_PcOdOR5gSvA4aA-1 Received: by mail-qv1-f70.google.com with SMTP id 6a1803df08f44-6ab895ee028so12878496d6.2 for ; Wed, 22 May 2024 21:38:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716439109; x=1717043909; 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=YgX6Cu5E7N2apTEs4XC6U+2EvwrXfbifiHWF2oc97wE=; b=VanjWgd95EmObzCCjMqadLvlrVMegCATXfiQRRRmoer+8dci0U1fQFK+OjByNM7X2z exyfs+WSFd/YAHVoY+MvRc6lVeMwPInFI/dUJvhFON7pUv8gvTgehXBxwnQZV/RKBNaY nRavwmqycWYr6KEsVyx1Q6xs6dkLvkTuOPrhYDQeFepVEPl9oYyY4ll36QNkOa9+gfWX h27Q47ijixbFxW7KK/lMv8v9u5xO8h1hjQECC3Lm5fCZStTRl49ms2AfCkldfwhU+AGF 5V/DozDG5ej7Fh0gnD/yEiFKknL/RRyY1DBYyILoCp44D6aMyp54y42CNER6quf0P+St 680g== X-Gm-Message-State: AOJu0YzuwdWD5VV2LPIlWtAVywnYEkZrv0Z/jXtIY/6MqWIHztdaruw0 MfVRmhDibYIvf2teITQsu/DpMPyrdD3wEQKXsVaIF6+JkCfJ/tpPy/ljTkYYBB8xA5kgZCnmvjf AK4pzSc3y1NoZZmnofnoowKVt7jlgsEpE+3hsD9uRiG1sM7jotJHl5+4js4fZMzOoflqsdaJtrV nerRrAU1YSn3vC0kZymK6pu3naAVtw7cYdjQ== X-Received: by 2002:a05:6214:440c:b0:6ab:656f:6a67 with SMTP id 6a1803df08f44-6ab7f3530f6mr33068086d6.15.1716439108982; Wed, 22 May 2024 21:38:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHs2NKpkzqn79efUmd0ebv1LuzTWeMhtAAlXomZlu0c/JEoQHRU50VCNu5R/npOOZ04KPU9VA== X-Received: by 2002:a05:6214:440c:b0:6ab:656f:6a67 with SMTP id 6a1803df08f44-6ab7f3530f6mr33067926d6.15.1716439108517; Wed, 22 May 2024 21:38: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-6a35969bcd5sm80952706d6.53.2024.05.22.21.38.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 May 2024 21:38:28 -0700 (PDT) From: Ian Wienand To: git@vger.kernel.org Cc: Ian Wienand Subject: [PATCH v3 3/3] run-command: show prepared command Date: Thu, 23 May 2024 14:37:56 +1000 Message-ID: <20240523043806.1223032-3-iwienand@redhat.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240523043806.1223032-1-iwienand@redhat.com> References: <20240523042143.1220862-1-iwienand@redhat.com> <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 This adds a trace point in prepare_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 For example, this can be very helpful when an alias is giving you an unexpected syntax error that is very difficult figure out from only the run_command trace point, e.g. test = "!for i in 1 2 3; do echo $i; done" will fail if there is an argument given, we can see why from the output. $ GIT_TRACE=1 test hello 11:02:39.813030 git.c:755 trace: exec: git-test hello 11:02:39.813233 run-command.c:657 trace: run_command: git-test hello 11:02:39.814384 run-command.c:657 trace: run_command: 'for i in 1 2 3; do echo $i; done' hello 11:02:39.814468 run-command.c:437 trace: prepare_cmd: /bin/sh -c 'for i in 1 2 3; do echo $i; done "$@"' 'for i in 1 2 3; do echo $i; done' hello for i in 1 2 3; do echo $i; done: -c: line 1: syntax error near unexpected token `"$@"' for i in 1 2 3; do echo $i; done: -c: line 1: `for i in 1 2 3; do echo $i; done "$@"' A test case is added. Signed-off-by: Ian Wienand --- run-command.c | 1 + t/t0014-alias.sh | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/run-command.c b/run-command.c index 1b821042b4..36b2b2f194 100644 --- a/run-command.c +++ b/run-command.c @@ -435,6 +435,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..75c8763a6c 100755 --- a/t/t0014-alias.sh +++ b/t/t0014-alias.sh @@ -44,4 +44,11 @@ test_expect_success 'run-command formats empty args properly' ' test_cmp expect actual ' +test_expect_success 'tracing a shell alias with arguments shows full prepared command' ' + git config alias.echo "!echo \$*" && + env GIT_TRACE=1 git echo argument 2>output && + cp output /tmp/output && + test_grep "^trace: prepare_cmd: /bin/sh -c '\''echo \$\* \"\$@\"" output +' + test_done