From patchwork Mon May 27 00:30:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Wienand X-Patchwork-Id: 13674485 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 E83D510E4 for ; Mon, 27 May 2024 00:32:19 +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=1716769941; cv=none; b=RhaUgn8xoFc23RZsEq6VVrVHKmWrKH9x8siN+1mHtHnywXVcyWXFqWWDNC1Wj8UwGTrSJBqV20T3vaPZ69FpmrpReGD3yuMFKo5W27wz8rcbPN8JcHdf1nco7LH1fSkQ/ri8dete6DbCb20/i1dFBXJnQdjEq6tw6BiiCQPNW5w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716769941; c=relaxed/simple; bh=pDXRgrua6JJbUBTIL6Wugzrh2VWQLKVAmv7dGOEQyno=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aFJt7YjjON8rueYyX/TRRSL0xpN1u7dT8pNmsH00WUT51REldyPA8Uekawc0TvX7Sjp23tPB9tKBn2xLbzDrBSzGNLQTCh6uQ9Grt5H3iTUjTOqLwsQCdcK07K5a52CxUo3NZg2+RQLK17o+r2tGRc+0HjWzFHg64CZ4OVauM1g= 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=AC3ecsO0; 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="AC3ecsO0" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716769938; 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=AC3ecsO0AKUl8dRAZ3TUPFeRLVbFWpcgeJzQhnsFs0VXSmXqk0KelOnQaQFKDrhCVZdiqP 7LKyMXzO2qTRg1g/NoursC68UkrfGMQBVtAs7MmDY8ZwFQttCAGPl8LAuT50u9rrIORF7K kYDfHdtTkoepO5HlbJHng/FoMWVCxs0= 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-595-OyOcHa2qO-6dN13i77urFg-1; Sun, 26 May 2024 20:32:17 -0400 X-MC-Unique: OyOcHa2qO-6dN13i77urFg-1 Received: by mail-qk1-f197.google.com with SMTP id af79cd13be357-792fadf7b61so379191785a.2 for ; Sun, 26 May 2024 17:32:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716769937; x=1717374737; 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=tc54dTuD8WzWur/g72xVKBZ0ejpgxrEvAH3mj1wBmwTab35UB6f6NktBNP8nyfKvZ+ O577eZSJbgDxRNIG2HpPtSnxVlls37ijWH/rLrevUsh9ICU7FjAYVykyzmMksYQES9JA 4H533alEj3CfDH6gvBkfHZTEcLldpTRfnVkO6N6i3lZAWhVuDr2E8hjZ+m/yKddsqYto z7DuQyaxKboP8Z/7w4Ty7src7IBHPmStZwTXtAG+y2OtJVa5p/iq+CytsJeGVRZ3mFR0 FntjbZqNsBF/B6UG2DdBo428gbU7yucXkLIKgJ2e9yMOhWl5qevfaXJl9ls9pRH5ASeo O2sw== X-Gm-Message-State: AOJu0YyrXhimQBvjISBYYSw8qKcaYR12HJ9kqW0BJRZOU5mMkvHNxHtl nJWIWSCG0e3qukowJ3byq5VXhqolW0WdrNX/10TBwuAGXSdzIaei5IXlT7QAiBjv0MgAkTGg7Yk /0y/4nM8w7Jccb295Q8eBkWKZM+FjwMqkti1iwcQk+XusafhnJJP8G50ZniZ692rHbhVhaa4rBd 32B29f70H5nkI9jWd+fo+DmZFEmCstMwF5Uw== X-Received: by 2002:a05:620a:2551:b0:790:7fe3:9fe1 with SMTP id af79cd13be357-794ab11083dmr970700485a.68.1716769936488; Sun, 26 May 2024 17:32:16 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGMZ909n/cKAT+wuv8+iAaOh/Go8D8byx+RMa7kS93f0+W33IngHLoVtjk5s6s5q9FQgqroyg== X-Received: by 2002:a05:620a:2551:b0:790:7fe3:9fe1 with SMTP id af79cd13be357-794ab11083dmr970699285a.68.1716769936034; Sun, 26 May 2024 17:32:16 -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-794abcdca88sm257509685a.66.2024.05.26.17.32.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 May 2024 17:32:15 -0700 (PDT) From: Ian Wienand To: git@vger.kernel.org Cc: Ian Wienand Subject: [PATCH v7 1/3] Documentation: alias: rework notes into points Date: Mon, 27 May 2024 10:30:47 +1000 Message-ID: <20240527003208.1565249-1-iwienand@redhat.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240525234454.1489598-1-iwienand@redhat.com> References: <20240525234454.1489598-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 Mon May 27 00:30:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Wienand X-Patchwork-Id: 13674486 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 535942F44 for ; Mon, 27 May 2024 00:32:22 +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=1716769944; cv=none; b=SG4/974EzhNfhWfSmrV8o913398kPKMopgwXz6Ig+zKHTm0Q8JeS8HQhcgVtsuXQmCvlju782E3CL40cCxAgNZLsIsMXqjvCPpASEoKbrgqc20udGRlAlTF4lXpR5pHL41WjoxWcAuyUApFgQvHLWU151KvH94nWwyGm5S2ptUg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716769944; c=relaxed/simple; bh=ztnCmTljJwfBJ3tFhPDqS7GsURe/IXoQyy1M9stl9Y0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kRas7IFoww9MJeQnLpj75cWEfQWWYIDtl+5M48cVDRPtZAdcotcgLG2DE8nyf+zYId04d7cvfI/ytUDCsCJJQvhOeQcb7WQn50AlcN2y0Il+iwHKBoZp1UUa1Uu9PHvsJ4PB3V86xq4VOfzhuttdwzUImnAFWbBnNxRospO3hWo= 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=eU2oI1TU; 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="eU2oI1TU" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716769942; 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=98TkfPZOI2BsKcPPjkqplHnRFYZ2ypM6x+MrGj8jDFk=; b=eU2oI1TUH8SIxXpXRw6wXAxTiWSOAS497VaHY/iqw2xRteayZVpms5yPv+Y5OY0NTi0lpu 0MuTSFhixr7tJnTCDgcCV3ZA/0n/MBHUH5tc6jCczD6mI5OeGBNSI2fwcsuRkrodNaK6Rv qMo7obSxljA40d422KDfkHOfkBLprZ4= Received: from mail-vk1-f197.google.com (mail-vk1-f197.google.com [209.85.221.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-470-P60NHx4nM3WRW9SAJs4W0w-1; Sun, 26 May 2024 20:32:19 -0400 X-MC-Unique: P60NHx4nM3WRW9SAJs4W0w-1 Received: by mail-vk1-f197.google.com with SMTP id 71dfb90a1353d-4e4f030eaafso1286262e0c.3 for ; Sun, 26 May 2024 17:32:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716769939; x=1717374739; 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=98TkfPZOI2BsKcPPjkqplHnRFYZ2ypM6x+MrGj8jDFk=; b=CgiUnxmSr8voQX/7Y1+qeudJ0xy6zyYWQS2ph5xrj7gprBjN+9uqbqvOH9jv+Ficxx jrQGxy7nh9no9gFtYy1V/EUDFeLtbamYUAkt2w+zH4caf9IsIB/ZpVBwZ0NvbcOW9eii udcWwZw4sK5NBaNmxyBedkE3ZxAEZw4F3ia0CDEoosBzlE5D2yIfjNGnLIgFncv8TgTn MwDkCCCmr+lwuo6y95CSolt+nnNwmjQ7YR/2eMBdIF0IIYcHRQgxZJ2GgjRwuiF54J/S vK+boIz1IukYbaS2NlH5NpuuWoIZWMXODJtiityGsLOo9xVLc93ScD1EzPWfDaI2kpZI 3NtQ== X-Gm-Message-State: AOJu0YytpPpUiafbXn+uoarb+3bQm57ztdx8BH5EOljWPX4OPLn01/qu JOHO/GANjRy4tgbMkcBGpMLg7PDcLjGiyrIJ+fyeHBlAjLDmtgxXU1Iq3wpKXztkdogm01q5g4x 7z0ymQVUY1mgaqV38ImGjls7bE1EBHgnI2HZA+2TIiWy0WBbgJHjNB9A3g9z0IMs+o1+mRUhsW/ ekmN2K7KBySTlXaCq9TOy800NSqwbnh5rOFw== X-Received: by 2002:a05:6122:919:b0:4da:ced8:b09a with SMTP id 71dfb90a1353d-4e4f012a446mr8185068e0c.0.1716769939065; Sun, 26 May 2024 17:32:19 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEs7nbDZzPKDR8YQ/ken2E6Tktob5I8NstUXqMtOMwdBOy840bpEyVP0MAaT8X71zOth52X9A== X-Received: by 2002:a05:6122:919:b0:4da:ced8:b09a with SMTP id 71dfb90a1353d-4e4f012a446mr8185054e0c.0.1716769938647; Sun, 26 May 2024 17:32: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 af79cd13be357-794abcdca88sm257509685a.66.2024.05.26.17.32.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 May 2024 17:32:18 -0700 (PDT) From: Ian Wienand To: git@vger.kernel.org Cc: Ian Wienand Subject: [PATCH v7 2/3] Documentation: alias: add notes on shell expansion Date: Mon, 27 May 2024 10:30:48 +1000 Message-ID: <20240527003208.1565249-2-iwienand@redhat.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240527003208.1565249-1-iwienand@redhat.com> References: <20240525234454.1489598-1-iwienand@redhat.com> <20240527003208.1565249-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 | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Documentation/config/alias.txt b/Documentation/config/alias.txt index 40851ef429..75f9f5e26f 100644 --- a/Documentation/config/alias.txt +++ b/Documentation/config/alias.txt @@ -27,3 +27,17 @@ 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]. +* Shell command aliases always receive any extra arguments provided to + the Git command-line as positional arguments. +** Care should be taken if your shell alias is a "one-liner" script + with multiple commands (e.g. in a pipeline), references multiple + arguments, or is otherwise not able to handle positional arguments + appended via `"$@"`. For example: `alias.cmd = "!echo $1 | grep + $2"` called as `git cmd 1 2` will be executed as 'echo $1 | grep $2 + 1 2', which is not what you want. +** 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() { + echo $1 | grep $2 ; }; c" will correctly execute the prior example. +** Setting `GIT_TRACE=1` can help you debug the command being run for + your alias. From patchwork Mon May 27 00:30:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Wienand X-Patchwork-Id: 13674487 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 BFE024A22 for ; Mon, 27 May 2024 00:32:26 +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=1716769948; cv=none; b=Ml3NBcCVjZ5MP21pyzmr1bjbvMgkxyH8qrqNgTEzD5nYvziheRYeCJZI513yYFRLz4+gstxXOLSok2GyIZ0WDYoYFIWEKmC+osTr0gxnH+1ausQe0qBsBEY1+wJHIvPO6Hqls2cSM5blctO5VBc9jBYpKx1N1jG5yZ+Emz2HV7s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716769948; c=relaxed/simple; bh=yez0/WswF0A/selG5A1noMsTpFdgrU8U3xWiB8oScX4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FrMj7yP37oPKsozbTTjl3u2y0vcYpg4EsUrAsJXp6bUmddIinBb20KpcgOch0GXqUpZwa3p9MRKn5X6vL38yzGtF6zx1N+0XXWAZYJ2Or+uWVQtfoAw+zt00Y86axF1KG/CCi6Fi9noosdpiygJil9Xf5JxiZOvod4l5qaS3NOA= 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=MEZEDWO3; 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="MEZEDWO3" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716769945; 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=SUCCHwN+r6suSAIUcyoOMqSGuU2xLdZvgZ67T8AdgjA=; b=MEZEDWO3Hb/cPkopbNP/Cc/kcOESraTBKvSGkvLPJRYnUtkfwbSXPvU6XZRGt24l7Wrk7g YgQgRYAOGTFamwb/GOyZ+RPIVjAbwETOppDiSWq9sZZZt/xdA75PWW4keeccf7tiQnLfyU 7ruMyBD8OTV+QtCVhdCnQSmkkqpbqSs= 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-207-tjzyBd8WOj2N8HUCTUxjww-1; Sun, 26 May 2024 20:32:22 -0400 X-MC-Unique: tjzyBd8WOj2N8HUCTUxjww-1 Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-794ab09eff3so360088185a.2 for ; Sun, 26 May 2024 17:32:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716769942; x=1717374742; 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=SUCCHwN+r6suSAIUcyoOMqSGuU2xLdZvgZ67T8AdgjA=; b=CVbd7nwdrsub0DQrVUD7MAoLKaVEC/fp/SgZCKEOSTbo8LqSEp0HhkAFQxJH7djbnU wyCLb2TY2ee/8CZeGbZ/6PTqDTyqmuJGViO3g/X50NzDyaL+Rfum6w7WPAqhNcT3eQtl ktL1BfN6Sa7gx2O65bXdIEuWbxunB/T4BWrLZ/z3gSTMQT/ITPkVQvI3ZdRJ9xGaVZ7f BThZEHePBvBTWeRvi7taqe3wacGpKmH+9W11yVIhsZ1Yeyn+jUi3DLeUgxY0AxDmAcDU bFFvHzgptcu5f++nG19I+2eL81b/NFhAUAQ3jr5rlDe9GRhLQX58WW7an5W3lfn29Sd7 MAzQ== X-Gm-Message-State: AOJu0YyXkdr1gbWCX3AlzoMPcvgu97c3C+R5tDZzTGf5P/9gDnQyCzTK T83IjVy6HteBXcOSXG32F/pmQ0P6bCo7TUpTtLL9fDgYQ/U6RohBXYWoyMOHLWMv1QEQczHX97H a3kMUUKYQC2e6dJrTtLd116CdKa2OZuQjE7PAeVRZrozNyeUILONWO9HyeWuAAJQx8qOymbxRno wDDz3qlqy1UJDsDXctwB/YBvb4e4OvuX9Wdw== X-Received: by 2002:a05:620a:558f:b0:790:c7f9:4639 with SMTP id af79cd13be357-794ab05a965mr899813285a.3.1716769941775; Sun, 26 May 2024 17:32:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE5SKVJDdZ14cAt3sOwyjsXRlZsnYp+uFrNseqrjaWVxFc535UWfoj/5V1Ak1HbSeElnTzqJg== X-Received: by 2002:a05:620a:558f:b0:790:c7f9:4639 with SMTP id af79cd13be357-794ab05a965mr899811785a.3.1716769941253; Sun, 26 May 2024 17:32: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 af79cd13be357-794abcdca88sm257509685a.66.2024.05.26.17.32.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 May 2024 17:32:20 -0700 (PDT) From: Ian Wienand To: git@vger.kernel.org Cc: Ian Wienand Subject: [PATCH v7 3/3] run-command: show prepared command Date: Mon, 27 May 2024 10:30:49 +1000 Message-ID: <20240527003208.1565249-3-iwienand@redhat.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240527003208.1565249-1-iwienand@redhat.com> References: <20240525234454.1489598-1-iwienand@redhat.com> <20240527003208.1565249-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 to ensure the full command output is present in the execution flow. Signed-off-by: Ian Wienand --- run-command.c | 3 +++ t/t0014-alias.sh | 11 +++++++++++ 2 files changed, 14 insertions(+) diff --git a/run-command.c b/run-command.c index 1b821042b4..31b20123d8 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, "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..854d59ec58 100755 --- a/t/t0014-alias.sh +++ b/t/t0014-alias.sh @@ -44,4 +44,15 @@ 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' ' + cat >expect <<-EOF && + trace: start_command: SHELL -c ${SQ}echo \$* "\$@"${SQ} ${SQ}echo \$*${SQ} arg + EOF + git config alias.echo "!echo \$*" && + env GIT_TRACE=1 git echo arg 2>output && + # redact platform differences + sed -n -e "s/^\(trace: start_command:\) .* -c /\1 SHELL -c /p" output >actual && + test_cmp expect actual +' + test_done