From patchwork Thu May 23 04:20:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Wienand X-Patchwork-Id: 13671249 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 22488273FD for ; Thu, 23 May 2024 04:21:59 +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=1716438121; cv=none; b=XAudfYeKuZw5cYSjadrFgf5GsmUohY9xzvgA6h9EkctL0aLGDd8uN3P7auDV9asY63wLhM9wWhP4Q+zMqnwrRf6CKgJnCBOo1yQnjwNXyqY1D35b9BfnYXzxoYpX8OHleKCmMcGIRI226w/25SxuuWxlt/baY3puH2TYuggctoM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716438121; c=relaxed/simple; bh=nZGOCaO/XYrjYwmmTMJFxQbkww/8y97A/ZwnXbuAFQ4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aeeYCEwyIjz/gNGwa7IVLIX8a0DHC8skhZ865rWLNMRfggwFjOsfyvosLXTkj7nW29kcQdG5cgZ7rh1/pZ/ayOuKmlVloysVnAZPCxYqGLG3gTSa46L1duk3DR4WeCAD08zqcrYl46+JdxPCOOu1vy2kEaOv4MmNKEg82CywEJU= 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=cJQnj4Mk; 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="cJQnj4Mk" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716438119; 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=yV2xFmpXgf0YMwvxbETIiihVXVglQJa/L7LbJ2xpF0U=; b=cJQnj4Mk8QhsQ7Kf2SfG9R/g9poGqBWyraviYE8PxjCBnOWeauyIFMBpcdescdoqpqB6hd LdF+wOCJgpkuaWS75pa+HGLt+ZuiXh3AdphNv7QN6aZdWf27/lM0nje8vxjvvvbYd0aADu eloZ93oBnwaDIN7cVhzmBNCWR6bnydU= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-206-OyD0kNWwMa-Mw90CObUNoQ-1; Thu, 23 May 2024 00:21:57 -0400 X-MC-Unique: OyD0kNWwMa-Mw90CObUNoQ-1 Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-792baeb223bso1868135385a.1 for ; Wed, 22 May 2024 21:21:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716438115; x=1717042915; 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=yV2xFmpXgf0YMwvxbETIiihVXVglQJa/L7LbJ2xpF0U=; b=AWit8Znkx1Ov7/PsmjFcL3qe1RmeAdyZwRGZ4NhXQNxkkc+z0g4XbViXRE47+cye10 l6IwtQAcKh9Yjv5geIzdQMgjniQ3xiKBwZjezqQ3rFnhMKoAVPm75D+UgHMOsEQKMXzz tWaK4fVbGbvdomPRDbdTS3hZ4vjWmqBsItOh8U4lvLcEFx1MzyHxorJ4/cIKKFOhiPBI 4LQNILnOXENh130L3rYKm8S/pMP8H/LXuXQ2vR5LmASS7jC6MFy7o/U6LPuS7owi45/N KX7w/9i1CXjsykJUDqZmWFK4esjy8U0wLFP33m+4r+HCxqzc26huA3PI1gHIms4JnMDy Nhnw== X-Gm-Message-State: AOJu0Yzv1Mal652kJwUyByuPRsj0ctu+wnzUpyhv3sFW775Ulm/pVal5 ck62iKdXUsoQlI5X9hwWxVGK1qlSiuSPur9F70ffD7TENDZn3TqCrl4K90s6Ii+tBmfGacHGwnY RxwhcbamyvzLP9Vo4XM+juOY4QdY2qxEB/oobisA13DHwqCQoVYOSPUm2F4hd3aaVL99xT88pdY Nmqxh+yz5xIRIJdYIPoTJ0vaI67J4H6HUHMw== X-Received: by 2002:ae9:e40d:0:b0:790:cc3b:fe65 with SMTP id af79cd13be357-7949941cbfcmr523345385a.10.1716438115695; Wed, 22 May 2024 21:21:55 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFZIPqF/DqV07HSYFLxxCxsQmmdobWdpQrbs/MTdQ2323YdTgTwGdi9ALEsuw6f3jPjtrA1BA== X-Received: by 2002:ae9:e40d:0:b0:790:cc3b:fe65 with SMTP id af79cd13be357-7949941cbfcmr523343485a.10.1716438115198; Wed, 22 May 2024 21:21:55 -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 af79cd13be357-794807f4465sm412760385a.62.2024.05.22.21.21.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 May 2024 21:21:54 -0700 (PDT) From: Ian Wienand To: git@vger.kernel.org Cc: Ian Wienand Subject: [PATCH v2 1/3] Documentation: alias: rework notes into points Date: Thu, 23 May 2024 14:20:57 +1000 Message-ID: <20240523042143.1220862-1-iwienand@redhat.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240522024133.1108005-1-iwienand@redhat.com> References: <20240522024133.1108005-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. --- 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:20:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Wienand X-Patchwork-Id: 13671250 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 4BBED273FD for ; Thu, 23 May 2024 04:22:03 +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=1716438124; cv=none; b=Xc0in2/6BMIidLcy00dd2U+TUsyeqSznQsOqG+MFG/sthsvh5GnnnvWypOtzFcED1xLEH6ixV7Ep3O1uiLTsb2bpzrn7KVkFuNxbky/tOy16ePUzJNIJQmr1yjKbdIDVNhG2/ykXl3N53Jor/3gLWjQ8xCBSmzxr/O2p0S/6Jj0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716438124; c=relaxed/simple; bh=InrIxLZ21i97yZ5gQYuP/QqcWLw8Yc5XNjt7x6yPKrE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AJKITqUyy9myFyo7qwZM4CCIybBGRJzBIxmoc5/okQTLshqAr5mOg5fmbW171kkjxudkrYMa3R3jLUKCvWaE/ioa3XHGnjBSkRg+FQxdyo3l8m+dKtZzN9wmGgodWjlcEt2Rtm8VcewAq5F/i1JMD/k7cHFwzYDxfenoBdKxr5k= 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=W1OiZeKO; 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="W1OiZeKO" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716438122; 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=e1bgTsidDxCIHu84my8YvIw/c400mMz313EXbhPpPC8=; b=W1OiZeKOKfqk0ubV8VXh7LIau4OGkow9zVN/l7F/Sfv/lc8a8hTyFr/D/p4Ohr3DKROInm 5t+kxDD3LHCPHHW+ncdvFJcHpR5GYaeOGgLQyEaKGoQvgn1qYzXLg44/+nu7JPq94SY2Gv yQxkJ+FyfDQvHd4E/WBLnvbJ6l5VasM= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-47-xaPeYzigORiA-jTnFeu4ZQ-1; Thu, 23 May 2024 00:22:00 -0400 X-MC-Unique: xaPeYzigORiA-jTnFeu4ZQ-1 Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-792d2abbc65so1509453285a.2 for ; Wed, 22 May 2024 21:22:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716438119; x=1717042919; 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=e1bgTsidDxCIHu84my8YvIw/c400mMz313EXbhPpPC8=; b=CPsBIf3ewVY+fGUx0iUKW7BemLhZGCTFUQbh64HdYoJSvppVhwv9xsxgpU+QrmwIGO t+SJ8Fub9/5phJfXNKt1EQHlBP1LmKm+RxbnejDRnXq46PmfLItz7r3yWD/VoiDSvCZ7 bark+7Xbwj4yLyOicVP3CfIaN32u7M6UHK+5j/2JB8tOIe+Cl9fNPPWW3fhsr05Hoz0o 0ECtbpO171r0yiWiibOmiGY2Cr/C1GzgoVUpRLlnc+L1KwmLnVgIot3XgXz0RsxGVTxm ZTKXdQFzSK3msMun2gTVahZurwTeUfjd9oGrZx2ZRPS0BmaBo7HO7GsKJsEN980R72t0 VRjg== X-Gm-Message-State: AOJu0Yy8YMWV4ioTnVJBcirNM/DiYQGC/VfeDzXoLORA20vsKV5UIET2 e7i/TefKQ50ix3PTHAc3w7OmI13rU6kEjzZggZfizqxYiBLoYBTPm+I26fXtFJ4lRM2L/Gxvv2v zgJcO7jEPAZLvbE6DiF+LR+UL4/LiK2KoDs1R/OA0hm1Q9qk7EwExIsKx1BljTGW7YD4gwqpslc bOlEa7ofbJ0ypphQswvkFwXeZiCNIX5V0HZw== X-Received: by 2002:a05:620a:5603:b0:792:9ca7:212f with SMTP id af79cd13be357-79499444105mr399928385a.31.1716438119064; Wed, 22 May 2024 21:21:59 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHzTuuIxJXhXG6KtNeM3PkBUkV9a7KbL0YeUrmMRQQ8BdZ+JB6VptA2juAo96Oeyi90Sc1nRQ== X-Received: by 2002:a05:620a:5603:b0:792:9ca7:212f with SMTP id af79cd13be357-79499444105mr399926785a.31.1716438118655; Wed, 22 May 2024 21:21:58 -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 af79cd13be357-794807f4465sm412760385a.62.2024.05.22.21.21.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 May 2024 21:21:57 -0700 (PDT) From: Ian Wienand To: git@vger.kernel.org Cc: Ian Wienand Subject: [PATCH v2 2/3] Documentation: alias: add notes on shell expansion Date: Thu, 23 May 2024 14:20:58 +1000 Message-ID: <20240523042143.1220862-2-iwienand@redhat.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240523042143.1220862-1-iwienand@redhat.com> References: <20240522024133.1108005-1-iwienand@redhat.com> <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 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. --- 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:20:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Wienand X-Patchwork-Id: 13671251 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 5F2D9273FD for ; Thu, 23 May 2024 04:22:06 +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=1716438129; cv=none; b=TaaSbqaewmkrMahRxVrvmFqhjxmJHyoUMORGdx7nHwK7eJZPzeHSiBnxBlZfXB7YW/wz5EQKL0zNV1LN7YtIphVpbnUEPkDmczfd3ZxzTmHRVvlTmld9IslcoXg7y7Wg4Y5btIJIrqzXUeShqqCjPXcPf8VIWiaEvdBI5+BP6OY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716438129; c=relaxed/simple; bh=5UV8X0C1bHlWHIZWmdgc8u/RMDGllHb7PQDcU17PwcI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=H4eSHTvGBFQuagX4HZ4AWqjJJwhYLOJab3xruFMjPYN3gYJP4Dg7EorQo/qLxvwBy5tSAq6JQ2bKugOruVjnOvLJ3qbx2yheEtk3wpNPBBf1F7oXNl07ZVzeF928dvN3fJZlR5rYgpznoPpeRk7AC7Uu4GRLclwNZpggTTiwOqY= 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=TtjKJzyH; 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="TtjKJzyH" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716438125; 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=2VO8ZpnP2I9ExOAtOfJGRxjkiuWI3o4kaK1wa7Ypiv0=; b=TtjKJzyH4JX8rV2OnYQmL8mwz2vLSfVE6h/boPoj+JzjEgbR4eZ9BsgcuOwZ6oXx33lVB3 lYO5Dr5Ywr8oL1RSZWwMtT2fmOPVxm4qcML28DYcfJFCCF33VOPUUQx1cEuakosmtp+Q+7 8I7lS9AmxTUMXSP8yCNV/CqnlB/Yrk8= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-55-ZaDDMkuPOnC1kO_Ud7wYWA-1; Thu, 23 May 2024 00:22:04 -0400 X-MC-Unique: ZaDDMkuPOnC1kO_Ud7wYWA-1 Received: by mail-qk1-f197.google.com with SMTP id af79cd13be357-792ff352462so1141957885a.1 for ; Wed, 22 May 2024 21:22:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716438122; x=1717042922; 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=2VO8ZpnP2I9ExOAtOfJGRxjkiuWI3o4kaK1wa7Ypiv0=; b=qaxsUI2+0uN+x7H56xebS0VeoHPDkvr5z5hsTuItXJxxB0sU3QMu54M+JVQJ6ps3Vg 2j2YmolluOSNgQ1f7jhfZlmgbjF5jW29nX20/i4faPsvZyu7jsMD+mOhOhIYXsrbN9pp XXs1S1MUdAryaBP/jtfyE5SuIn6JewMcl2MCyEDX0h4HUtoKGUmVovqUM00THEHsZ7uM AWoejoPc4qS/wl+ZC7GFZ8lgbbRJ1QzhlFkd54eK5D9JAqc+Lz6LSVV2sIyIzaIRbZ2X L2Dy7Mq7sKTZ7oZfUD7C5nhYx1rtpPHplpE2Z6E8dZUEq80mw8zqhZXyR0xO6fOi8yv7 WqNA== X-Gm-Message-State: AOJu0YxKiHu/UxdwsPynF+mYDIL5aJHNxT0XqdUNTr5mUn2anrWuK9Mq bCgVOFTI/sugGuvI/mIQtnRvH1N23b3JGDTwx8L8TGRQ/zemhhLuLSDi427iEoJkudm+HxBTHrm gurr3+v1xQrhDxUUhZwfrxCa6g2K7UH9/hsPXmFKuWKhsl200U2cvfa9qAaP5m7dt27Ww1obwvJ H5GOKuq2IOPGas/F+qrF8QouhhjAsP0Cokqg== X-Received: by 2002:a05:620a:350:b0:792:fa98:276 with SMTP id af79cd13be357-7949943e3d7mr356925885a.27.1716438122554; Wed, 22 May 2024 21:22:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE0rV9OZDWDTurFkvN8eo9+NXQ+Y6Uq4bSZJhQu7mo9A/DVWj6gtfqYeorFECvh+A3tyTTAvQ== X-Received: by 2002:a05:620a:350:b0:792:fa98:276 with SMTP id af79cd13be357-7949943e3d7mr356923985a.27.1716438121972; Wed, 22 May 2024 21:22:01 -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 af79cd13be357-794807f4465sm412760385a.62.2024.05.22.21.21.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 May 2024 21:22:00 -0700 (PDT) From: Ian Wienand To: git@vger.kernel.org Cc: Ian Wienand Subject: [PATCH v2 3/3] run-command: show prepared command Date: Thu, 23 May 2024 14:20:59 +1000 Message-ID: <20240523042143.1220862-3-iwienand@redhat.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240523042143.1220862-1-iwienand@redhat.com> References: <20240522024133.1108005-1-iwienand@redhat.com> <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 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. --- 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