threads / patch / 20920

patchgit-push: Accept -n as a synonym for --dry-run.

Subject: [PATCH] git-push: Accept -n as a synonym for --dry-run.

## tl;dr

8 messages between Sep 13, 2009 and Sep 13, 2009. Diffs are folded; open one to read it.

replies: 7people: 2as markdown or json

Nelson Elhage· Sep 13, 2009, 00:05 UTC · lore
'-n' is the standard way to specify a dry run for other git commands,
so make 'git-push' accept it as well.
---
 Documentation/git-push.txt |    3 ++-
 builtin-push.c             |    4 ++--
 2 files changed, 4 insertions(+), 3 deletions(-)
Show changes to 2 files +4 −3

Documentation/git-push.txt, builtin-push.c

diff --git a/Documentation/git-push.txt b/Documentation/git-push.txt
index 58d2bd5..ba6a8a2 100644
--- a/Documentation/git-push.txt
+++ b/Documentation/git-push.txt
@@ -9,7 +9,7 @@ git-push - Update remote refs along with associated objects
 SYNOPSIS
 --------
 [verse]
-'git push' [--all | --mirror | --tags] [--dry-run] [--receive-pack=<git-receive-pack>]
+'git push' [--all | --mirror | --tags] [-n | --dry-run] [--receive-pack=<git-receive-pack>]
 	   [--repo=<repository>] [-f | --force] [-v | --verbose]
 	   [<repository> <refspec>...]
 
@@ -82,6 +82,7 @@ nor in any Push line of the corresponding remotes file---see below).
 	if the configuration option `remote.<remote>.mirror` is
 	set.
 
+-n::
 --dry-run::
 	Do everything except actually send the updates.
 
diff --git a/builtin-push.c b/builtin-push.c
index 787011f..5e5f3ad 100644
--- a/builtin-push.c
+++ b/builtin-push.c
@@ -10,7 +10,7 @@
 #include "parse-options.h"
 
 static const char * const push_usage[] = {
-	"git push [--all | --mirror] [--dry-run] [--porcelain] [--tags] [--receive-pack=<git-receive-pack>] [--repo=<repository>] [-f | --force] [-v] [<repository> <refspec>...]",
+	"git push [--all | --mirror] [-n | --dry-run] [--porcelain] [--tags] [--receive-pack=<git-receive-pack>] [--repo=<repository>] [-f | --force] [-v] [<repository> <refspec>...]",
 	NULL,
 };
 
@@ -182,7 +182,7 @@ int cmd_push(int argc, const char **argv, const char *prefix)
 		OPT_BIT( 0 , "mirror", &flags, "mirror all refs",
 			    (TRANSPORT_PUSH_MIRROR|TRANSPORT_PUSH_FORCE)),
 		OPT_BOOLEAN( 0 , "tags", &tags, "push tags"),
-		OPT_BIT( 0 , "dry-run", &flags, "dry run", TRANSPORT_PUSH_DRY_RUN),
+		OPT_BIT('n' , "dry-run", &flags, "dry run", TRANSPORT_PUSH_DRY_RUN),
 		OPT_BIT( 0,  "porcelain", &flags, "machine-readable output", TRANSPORT_PUSH_PORCELAIN),
 		OPT_BIT('f', "force", &flags, "force updates", TRANSPORT_PUSH_FORCE),
 		OPT_BOOLEAN( 0 , "thin", &thin, "use thin pack"),
-- 
1.6.3.1.499.ge7b8da
Junio C Hamano· Sep 13, 2009, 02:44 UTC · re: Nelson Elhage · lore

Re: [PATCH] git-push: Accept -n as a synonym for --dry-run.

Nelson Elhage <nelhage@MIT.EDU> writes:
> '-n' is the standard way to specify a dry run for other git commands,
> so make 'git-push' accept it as well.
> ---
Sign-off?

Indeed -n is used in many places for --dry-run, but it is not _the_ standard way.

commit, push (as you identified), reflog, and send-email have --dry-run but -n is not a synonym for it. Some of them even use -n as a shorthand for a more often used option than --dry-run.

So the justification should be more like "push does not any other option that deserves a short-and-sweet -n better, it will not have any such option in the future, and --dry-run is very often used that it deserves to use -n as its short-hand."

I tend to agree with the first two points, but I am not sure about the third point. Do people dry-push that often?

Nelson Elhage· Sep 13, 2009, 03:40 UTC · re: Junio C Hamano · lore

Re: [PATCH] git-push: Accept -n as a synonym for --dry-run.

On Sat, Sep 12, 2009 at 07:44:29PM -0700, Junio C Hamano wrote:
> Sign-off?
Signed-off-by: Nelson Elhage <nelhage@mit.edu>

(I can resend the entire patch, but I'll resend with a new commit message if appropriate after any discussion plays itself out).

Show 7 quoted lines
> 
> Indeed -n is used in many places for --dry-run, but it is not _the_
> standard way.
> 
> commit, push (as you identified), reflog, and send-email have --dry-run
> but -n is not a synonym for it.  Some of them even use -n as a shorthand
> for a more often used option than --dry-run.

Can you point to an example of a git command supporting --dry-run, and using -n for something else? I personally would find that confusing, since -n is a common alias for dry-run both inside and outside of git (c.f. make, rsync, libtool). I guess patch(1) has that property, but none of your examples from git use -n to mean something else.

In fact, reflog already supports '-n' to mean dry-run, it's just not documented. I'll send along a documentation patch to fix that.

I got the claim that -n was "standard" from parse-options.h, which defines OPT__DRY_RUN, which defines both -n and --dry-run switches at the same time. Given the number of commands that treat them as synonymous, I think it would be a win for UI consistency to make them synonymous everywhere.

Show 8 quoted lines
> 
> So the justification should be more like "push does not any other option
> that deserves a short-and-sweet -n better, it will not have any such
> option in the future, and --dry-run is very often used that it deserves to
> use -n as its short-hand."
> 
> I tend to agree with the first two points, but I am not sure about the
> third point.  Do people dry-push that often?

I personally use --dry-run almost every time I push, which is what inspired this patch. Especially now that the push.default can change the behavior of push from repo to repo, I want to be sure I know what I'm about to push. The recent 'git push --confirm' thread suggests I am not the only person with this concern.

Nelson Elhage· Sep 13, 2009, 03:54 UTC · re: Nelson Elhage · lore

Re: [PATCH] git-push: Accept -n as a synonym for --dry-run.

On Sat, Sep 12, 2009 at 11:40:31PM -0400, Nelson Elhage wrote:
Show 6 quoted lines
> On Sat, Sep 12, 2009 at 07:44:29PM -0700, Junio C Hamano wrote:
> Can you point to an example of a git command supporting --dry-run, and
> using -n for something else? I personally would find that confusing,
> since -n is a common alias for dry-run both inside and outside of git
> (c.f. make, rsync, libtool). I guess patch(1) has that property, but
> none of your examples from git use -n to mean something else.

Oops, I missed 'commit' in your list, which I see (as of recently) has that property. In that case, though, --dry-run was added after an established -n option had been there for a long time; I think my general argument still stands for commands where that is not the case.

- Nelson
Junio C Hamano· Sep 13, 2009, 05:23 UTC · re: Nelson Elhage · lore

Re: [PATCH] git-push: Accept -n as a synonym for --dry-run.

Nelson Elhage <nelhage@MIT.EDU> writes:
> ... I think my
> general argument still stands for commands where that is not the case.
Cool down.

It is a mere subset of what I already said, so you are not arguing against me at all.

    So the justification should be more like "push does not have any other
    option that deserves a short-and-sweet -n better, it will not have any
    such option in the future, and --dry-run is very often used that it
    deserves to use -n as its short-hand."

and I already said I tend to agree with the first two points. Indeed the first point is an absolute truth (the statement is about the current state).

To answer the second point you need to look into the future, but I do not foresee us adding a very useful option to the command whose usefulness far outweigh that of dry-run and whose name begins with 'n' to want to use it as the short-hand. In such a case, it is likely that we would try very hard to find a name that does not begin with 'n' to avoid the issue.

Junio C Hamano· Sep 13, 2009, 06:10 UTC · re: Junio C Hamano · lore

Re: [PATCH] git-push: Accept -n as a synonym for --dry-run.

Junio C Hamano <gitster@pobox.com> writes:
> ..., so you are not arguing against
> me at all.
> ... it is likely that we would try very
> hard to find a name that does not begin with 'n' to avoid the issue.
So what's my objection, in short?

It is just the wording "_the_ standard" that implies that anything that uses -n to mean something other than --dry-run is _wrong_.

I didn't want to see anybody arguing against "commit -n". It is used to defeat pre-commit hook and has been there with us for a long time.

Nelson Elhage· Sep 13, 2009, 17:07 UTC · re: Junio C Hamano · lore

Re: [PATCH] git-push: Accept -n as a synonym for --dry-run.

On Sat, Sep 12, 2009 at 10:23:47PM -0700, Junio C Hamano wrote:
Show 9 quoted lines
> Nelson Elhage <nelhage@MIT.EDU> writes:
> 
> > ... I think my
> > general argument still stands for commands where that is not the case.
> 
> Cool down.
> 
> It is a mere subset of what I already said, so you are not arguing against
> me at all.

My apologies for continuing an argument where there was none. I've sent a patch with an improved commit message, and we can continue discussing on that thread if necessary.

- Nelson
Junio C Hamano· Sep 13, 2009, 05:18 UTC · re: Nelson Elhage · lore

Re: [PATCH] git-push: Accept -n as a synonym for --dry-run.

Nelson Elhage <nelhage@MIT.EDU> writes:
Show 6 quoted lines
>> commit, push (as you identified), reflog, and send-email have --dry-run
>> but -n is not a synonym for it.  Some of them even use -n as a shorthand
>> for a more often used option than --dry-run.
>
> Can you point to an example of a git command supporting --dry-run, and
> using -n for something else?

Doesn't commit -n stand for no-verify? I think that is how it is documented.

> In fact, reflog already supports '-n' to mean dry-run,
Huh?  "git reflog -n 4" is for show-four-entries-from-the-top.

← back to recent threads