From patchwork Sat May 25 01:20:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Wienand X-Patchwork-Id: 13673868 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 31B6C19E for ; Sat, 25 May 2024 01:22:18 +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=1716600141; cv=none; b=VO5hbFQWfK554PXegIOJLWZfOwZr0HJfExQKFEHgcM5QRD4cgsr6mRu2+gqvzmwg7SPpWeGLfJSMb+il/K7ZqNkJSv18FrFMsuWIBY2DRU1PqISvNNlqYBdlTCmur5PeJ3tL8YSjBOwoEdJuvO4AP4Vka2f9EdTkQPxRJ0k6VHo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716600141; c=relaxed/simple; bh=pDXRgrua6JJbUBTIL6Wugzrh2VWQLKVAmv7dGOEQyno=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jiuBvusg32tuTes3CXMz9DJieDx34NqlLEXzCz2jhbZ1bsTTcCHBo/Mu3Jr1F0l7TVxwDAHIomJgsrcrF8zGjXYAm5/VsSFJzLQZE/Qbd3EZ05Ycf4vzGJKSO2ge770YoopwreVOLVMGgztHFhjaUe5E36FttnmTRfz/IHhHy84= 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=KA8piAN9; 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="KA8piAN9" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716600138; 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=KA8piAN9E/YqRbHLratxG2WfiJ0d4R+sKbO6XZPTowCv9/d9yDvOBfhflAi5UR2VxkvbiC fX4QrU1B+Wl5LvK/v9fExzcNP2sxKBxjjye1PG6kfiuyN0w8ZtAjijkhjpXHbIFAx0UEGH XwoHXMszcldrRyZhK6DaKvBGTdIlTLk= Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-168-sKNiUhirPnusTP5FN5VQnA-1; Fri, 24 May 2024 21:22:16 -0400 X-MC-Unique: sKNiUhirPnusTP5FN5VQnA-1 Received: by mail-qt1-f198.google.com with SMTP id d75a77b69052e-43e169f2a4aso19289451cf.1 for ; Fri, 24 May 2024 18:22:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716600136; x=1717204936; 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=apWZUsOklNlFAxAkhlwu0A1ptSi8ZLeQtrhrmJqiwgoH37/Njwmpcizu00OkFRX2c1 IIs/shPhaIupPup41DvTspfpZeCpResq9WjrUfrEpBr6uy4mi6EAF8F2dqkUWz66hQVK cmDP0MbhnjXevP+ev0iYYTPRZmEL6PD8jEaGt2yHXSHwuiHThErOhUzt9cYxVcqAglu5 z5GqnW9l036Aa+kavtiIiRntISYBsg0D/EMkIxIZLmopmEejQ656V2403bEcNM07680e wN4eu8Gr+gFQbgtvP4ZLveZO3NYKGPquckahaQ2tkhem05wlGynxycB4llCHJGON/YQc WLyw== X-Gm-Message-State: AOJu0YwRoglH69gCgbhjtPdJLENcolDbAI9KWwqyyTHGcOjucKw9ypav 6ek+nqh9Enf5sbxwKPfODMHA9ZSnkzvCDbgWvk95wqEvmUXlKdAVeORfenj5UJ/EbKI2gNNxuNu XrSxYx2pcyfcGtIxUEzuD30IorruP4/YLQrSLJLr2YrxtP/vqYjF97Uhnx5ix9vaLSa5RBE74Nm HALk+HJvRK+6OCCNMDWLudpvd6yUWaWun5wQ== X-Received: by 2002:a05:622a:14:b0:43a:df49:f8b7 with SMTP id d75a77b69052e-43fb0ea56a6mr38948041cf.36.1716600136075; Fri, 24 May 2024 18:22:16 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFPX0IvM4ng2tgbvwYv1V1qkbyBMQM4BSD20qWIWkQFUtvPetMtbh0eCjQFv7dmH1tbamDI2w== X-Received: by 2002:a05:622a:14:b0:43a:df49:f8b7 with SMTP id d75a77b69052e-43fb0ea56a6mr38947881cf.36.1716600135450; Fri, 24 May 2024 18:22:15 -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 d75a77b69052e-43fb16b6a79sm13347841cf.13.2024.05.24.18.22.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 May 2024 18:22:15 -0700 (PDT) From: Ian Wienand To: git@vger.kernel.org Cc: Ian Wienand Subject: [PATCH v5 1/3] Documentation: alias: rework notes into points Date: Sat, 25 May 2024 11:20:50 +1000 Message-ID: <20240525012207.1415196-1-iwienand@redhat.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240524073411.1355958-1-iwienand@redhat.com> References: <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 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 Sat May 25 01:20:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Wienand X-Patchwork-Id: 13673869 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 771F4184E for ; Sat, 25 May 2024 01:22:23 +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=1716600145; cv=none; b=GFKHTpjDhtkgPOmVDqF8sirLpgVClgg42vXvINh2jc0zYnRrguTDk8ESvCum/qhe++gfKpqZPOX0evWn81D0e+ty5eX4MUwPn+IJn8B/2Uo+ysIRW+Ls5vhFNcegiM2yaeqMhC7OlF0Ce0L50BKK2SbcKH1/OUxHb28PvLuWfPk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716600145; c=relaxed/simple; bh=lmqbNgGMmABTQP5nSU3AMvzls+Vfe0MU4r19Mys/S7Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kfBTbMgge/ZzNv7i3ZUE2TgWAvg4W8rdF50O+nRNHCV8K2u/5DJzca9IeB17ENfszHZAawXeNloFu/u0tZW5hpk/CWvkBmd5pKj+COW9b6EdyVq4cwinNZ+4UoXyBAWYvojHZCXYRdX0KeXFC50Eri2TYJanXBPRTJXQoBrSq0Y= 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=jDX0qYxu; 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="jDX0qYxu" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716600141; 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=HA6j17gQrsO2y+zRbGT2fkxHEsbsSXgNNVrSzERTX+0=; b=jDX0qYxuRdMU6b5VETzE7FQHSLK7CbHmd27TJUgb7dj4GFeHFTTRPhtraTae23Es35eCeB x5ORLjB3xjK3JD81Yft5tSXrNRgIXJwetII+eP4XAKeyk8zDP1PfXgzsYbYfH69YzxIuj8 D0/8nNeR4F+u2Fz7DaHrLO9NNqLfrbM= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-173-ffHE5S3zMNqiukHkQvPiSQ-1; Fri, 24 May 2024 21:22:20 -0400 X-MC-Unique: ffHE5S3zMNqiukHkQvPiSQ-1 Received: by mail-qt1-f197.google.com with SMTP id d75a77b69052e-43e0e94fa82so18206141cf.0 for ; Fri, 24 May 2024 18:22:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716600139; x=1717204939; 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=HA6j17gQrsO2y+zRbGT2fkxHEsbsSXgNNVrSzERTX+0=; b=HoN8rURUXc0Bcflu3NsRVBPyw/it7JIShKSAZH2rZV369XWOA3/SnRAewiAh/VmNId fRAWjzbrJEy68+bB3+rgd70R9/Qd3uQinxDj1F4BVqRYyWGt8yhhOa2bQRmkANvIdsTf pUjoBpHAUcJgOFmMGn1kJQ5uwqD5kqCKNv0Np8HUB81yd/YykCe3codszgBs5CN2m1jw NkrDh7YNiSl/Ax1YhgvrzqODslMYwBc0x0TgPM6qPC0daeVXnpTHc7CICnSd3eNiVtjc pzTGKjSoaMGcarFsVEAq7GZWUIIx5XTUHcXEnEmDGO45dWbhvRnmEZwlpzyedU1oXGAe vNPA== X-Gm-Message-State: AOJu0YyczUlxx0v4qxSITsgty/Y/JbbakG1D1NALNgFv0WrySRYe0k9b MMT8jC2RC1WeAa6ZA7hvTZOsli2z2Ywk5pogs3FsqNTCd42uquRlCDrL4i0YfLVKCSfoQvB8ehX jTS8q/EPFS9iY9AfGDDWyqD5rWxIR+xe0keRg3s+YrQ2TMSzWU8prKSQ21rf2ELNy8NrIOfiPqN bW52SKiyPS8CBezF8EZHPj3rPi7xU5MaOAow== X-Received: by 2002:a05:622a:111:b0:43a:ed56:4c86 with SMTP id d75a77b69052e-43fb0f252eemr44660321cf.56.1716600138748; Fri, 24 May 2024 18:22:18 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFurCTtcWYn9JNdC//5Fp9xiSLJlIFYBHID2vi7cYF8KlSGW2u5gwkhPOpMjKEM6059147Jow== X-Received: by 2002:a05:622a:111:b0:43a:ed56:4c86 with SMTP id d75a77b69052e-43fb0f252eemr44660161cf.56.1716600138287; Fri, 24 May 2024 18:22:18 -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 d75a77b69052e-43fb16b6a79sm13347841cf.13.2024.05.24.18.22.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 May 2024 18:22:17 -0700 (PDT) From: Ian Wienand To: git@vger.kernel.org Cc: Ian Wienand Subject: [PATCH v5 2/3] Documentation: alias: add notes on shell expansion Date: Sat, 25 May 2024 11:20:51 +1000 Message-ID: <20240525012207.1415196-2-iwienand@redhat.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240525012207.1415196-1-iwienand@redhat.com> References: <20240524073411.1355958-1-iwienand@redhat.com> <20240525012207.1415196-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 | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/Documentation/config/alias.txt b/Documentation/config/alias.txt index 40851ef429..f32b86cde3 100644 --- a/Documentation/config/alias.txt +++ b/Documentation/config/alias.txt @@ -27,3 +27,31 @@ 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 as positional arguments. +* If the alias contains any white-space or reserved characters, it + will be considered an inline script and run as an argument to `sh + -c`. +* When running as a script, if arguments are provided to the alias + call, Git makes them available to the process by appending "$@" to + the alias shell command. This is not appended if arguments are not + provided. +** For "simple" commands, such as calling a single binary + (e.g. `alias.myapp = !myapp --myflag1`) this will result in any + arguments becoming additional regular positional arguments to the + called binary, appended after any arguments specified in the aliased + command. +** Care should be taken if your alias script has multiple commands + (e.g. in a pipeline), references argument variables, or is + otherwise not expecting the presence of the appended `"$@"`. 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`. When writing such aliases, you should ensure + that the appended "$@" when arguments are present does not cause + syntax errors or unintended side-effects. +** 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.cmd = "!c() { + cmd $1 | cmd $2 ; }; c" will allow you to work with separate + arguments. +** Setting `GIT_TRACE=1` can help debug the command being run. From patchwork Sat May 25 01:20:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Wienand X-Patchwork-Id: 13673870 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 2FF33391 for ; Sat, 25 May 2024 01:22:24 +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=1716600146; cv=none; b=ZO2XeIt93FEIbY1Q9EvIVStuzbJKFfkdEpgOo7vIaEiF8/5NcBYBAqbqWAmPlCS7vAUff5bc+JYNN/rowjuPi0FOc7Z7NyoEq9cc0kh3tW1ooLRHQDeDVOqypU9EQbQYrcUMZg40WQz19hV+fnflNRJ9LEoQgmwdu8bMQUCrkBw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716600146; c=relaxed/simple; bh=JI0JSSenzJoScZQtRlnx/zzXicQlXXYsaK18lBM+8sY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NjJeQI/MBXHAG0cdCNO9o+XShO+qtB/HgqwvGCDjVDeO1IWnjoE0xGz9i5jt910ThdHNgthRN8xozNddtocaj3BwVXj1w1uOFSRHPzr0DKN+bsCcya/XLn5xDmHeqo7iYr947El/+i+iphixTMT2qTm9y/otEaeN1YX3YJ//XOE= 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=QafTpg9m; 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="QafTpg9m" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716600144; 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=LgfPt2o6pq/B1K+nzHLUtdowfTGR+xIywUSytWRHK+E=; b=QafTpg9mY5tS+BFNeFuQic2EoKUdX6Wng84OW/Yak7hvDi+zivYVq0ukMwAcUZ2fnu+nbf kb9htQyVgSDaELm8+yDYZrZvfkroGTPp0E6vRQOOi5UgM98k22y+rkVj/6aNtZ5Uf6jBUc Z/ENNewwPklhHXMJuyELSEYLci5Zuio= Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-447-Kx6anINQPyGRj53VHKH_-g-1; Fri, 24 May 2024 21:22:22 -0400 X-MC-Unique: Kx6anINQPyGRj53VHKH_-g-1 Received: by mail-qt1-f199.google.com with SMTP id d75a77b69052e-43f7eb72eccso28709901cf.0 for ; Fri, 24 May 2024 18:22:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716600142; x=1717204942; 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=LgfPt2o6pq/B1K+nzHLUtdowfTGR+xIywUSytWRHK+E=; b=ko0g5re12vD6krtlhGAbCY8WN+FPWxT4Vpr3BgLT8ThvVPV4OoEjYrp1c6i12rbiB/ 9WM9pzC7uKFpibs7fMWEdbTyzAgfmq6AGZUZd/xRt7KnyMTmSzZTwUuugKpcx9otJ35B J6CBGhUhh/+3XqYGhIBKDRCuU+kBhDFkRgnQPswlRq0WdzO4cOHwnBJZ2Wr2KqqvooO0 Rwkj3DiqnOHU6T4e5KzJBGjKBqUY5Y8S41PwuoCYWOKbv83IF3EmdmRddlOz2nH+1qMj aqPRORvNk44DXajPaU6MmkVXq+Ts7omOHp3rkTaiwhMnbRHrjcA7hCTyWDgGjuBXDVIF tSGg== X-Gm-Message-State: AOJu0YybdPGcIMN74JxxHRcgX3nmOIZhHJgxVNqVPahv0VElQiDJpFWL obC0+53DTh/3Enq6CNFc15hAsEhmqby4fNy+9+YkxLNxOfaEomcY9JobH38lS+zZfCTnIevWWJ5 H/c1BOx+xw+Ie+uePmgtpMqTAYrkgmjrZfx8d63bdwhZhp/N/NETNPVsqWsM2rRX6Wm67Bkq74N G3VGv1RLyyIW1FPkWsmBrWvP3C27+hs8w4iA== X-Received: by 2002:ac8:588c:0:b0:43a:7886:eca7 with SMTP id d75a77b69052e-43fa736ae92mr126847351cf.0.1716600141645; Fri, 24 May 2024 18:22:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHHkM6EsEBJmmyqZ27NhZ5Fr+Wch2AzTqrNZL+oqvxSGgJ3+JKEUbU2fZZtAhdlSYJFk2XgxQ== X-Received: by 2002:ac8:588c:0:b0:43a:7886:eca7 with SMTP id d75a77b69052e-43fa736ae92mr126847131cf.0.1716600141135; Fri, 24 May 2024 18:22:21 -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 d75a77b69052e-43fb16b6a79sm13347841cf.13.2024.05.24.18.22.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 May 2024 18:22:20 -0700 (PDT) From: Ian Wienand To: git@vger.kernel.org Cc: Ian Wienand Subject: [PATCH v5 3/3] run-command: show prepared command Date: Sat, 25 May 2024 11:20:52 +1000 Message-ID: <20240525012207.1415196-3-iwienand@redhat.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240525012207.1415196-1-iwienand@redhat.com> References: <20240524073411.1355958-1-iwienand@redhat.com> <20240525012207.1415196-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 start_command so we can see the full command invocation without having to resort to strace/code inspection. For example: $ GIT_TRACE=1 git test foo git.c:755 trace: exec: git-test foo run-command.c:657 trace: run_command: git-test foo run-command.c:657 trace: run_command: 'echo $*' foo run-command.c:749 trace: start_command: /bin/sh -c 'echo $* "$@"' 'echo $*' foo 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 | 3 +++ t/t0014-alias.sh | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/run-command.c b/run-command.c index 1b821042b4..9892c4421c 100644 --- a/run-command.c +++ b/run-command.c @@ -746,6 +746,8 @@ int start_command(struct child_process *cmd) goto end_of_spawn; } + trace_argv_printf(&argv.v[1], "trace: start_command:"); + if (pipe(notify_pipe)) notify_pipe[0] = notify_pipe[1] = -1; @@ -913,6 +915,7 @@ int start_command(struct child_process *cmd) else if (cmd->use_shell) cmd->args.v = prepare_shell_cmd(&nargv, sargv); + trace_argv_printf(&cmd->args.v[1], "trace: start_command:"); cmd->pid = mingw_spawnvpe(cmd->args.v[0], cmd->args.v, (char**) cmd->env.v, cmd->dir, fhin, fhout, fherr); diff --git a/t/t0014-alias.sh b/t/t0014-alias.sh index 95568342be..db747950c7 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: start_command:.*" output +' + test_done