Re: git-branch -m interprets first argument differently when two are supplied

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Brandon Casey schrieb:
> The first non-option argument is interpreted differently depending on
> whether one argument or two arguments have been supplied.
> 
> 	git-branch -m [<oldbranch>] <newbranch>
> 
> Has anyone considered whether this is inconsistent with how other
> commands operate?

Funny, I fell into this trap just yesterday and accidentally renamed
my master branch to something else. IMO git-branch -m should take two
arguments. Full stop.

Something like this.

-- >8 --
From: Johannes Sixt <johannes.sixt@xxxxxxxxxx>
Subject: [PATCH] git-branch: Deprecate -m with only one argument.

"git branch -m" can be invoked with only one argument, in which case
it renames the current branch to the new name. This is inconsistent since
the first argument is either a source or destination depending on whether
a second argument follows. Furthermore, it is surprising that a rename
command that is given only one argument succeeds at all.

Let's aim for removing this feature.

Signed-off-by: Johannes Sixt <johannes.sixt@xxxxxxxxxx>
---
 Documentation/git-branch.txt |    4 ++--
 builtin-branch.c             |    9 ++++++---
 2 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/Documentation/git-branch.txt b/Documentation/git-branch.txt
index 7e8874a..56bea06 100644
--- a/Documentation/git-branch.txt
+++ b/Documentation/git-branch.txt
@@ -12,7 +12,7 @@ SYNOPSIS
 	   [-v [--abbrev=<length> | --no-abbrev]]
 	   [--contains <commit>]
 'git-branch' [--track | --no-track] [-l] [-f] <branchname> [<start-point>]
-'git-branch' (-m | -M) [<oldbranch>] <newbranch>
+'git-branch' (-m | -M) <oldbranch> <newbranch>
 'git-branch' (-d | -D) [-r] <branchname>...

 DESCRIPTION
@@ -136,7 +136,7 @@ OPTIONS

 <newbranch>::
 	The new name for an existing branch. The same restrictions as for
-	<branchname> applies.
+	<branchname> apply.


 Examples
diff --git a/builtin-branch.c b/builtin-branch.c
index e414c88..14df594 100644
--- a/builtin-branch.c
+++ b/builtin-branch.c
@@ -17,7 +17,7 @@ static const char * const builtin_branch_usage[] = {
 	"git-branch [options] [-r | -a]",
 	"git-branch [options] [-l] [-f] <branchname> [<start-point>]",
 	"git-branch [options] [-r] (-d | -D) <branchname>",
-	"git-branch [options] (-m | -M) [<oldbranch>] <newbranch>",
+	"git-branch [options] (-m | -M) <oldbranch> <newbranch>",
 	NULL
 };

@@ -609,9 +609,12 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
 		return delete_branches(argc, argv, delete > 1, kinds);
 	else if (argc == 0)
 		print_ref_list(kinds, detached, verbose, abbrev, with_commit);
-	else if (rename && (argc == 1))
+	else if (rename && (argc == 1)) {
+		fprintf(stderr, "'git branch -m' with only one parameter is deprecated.\n"
+			"Will continue, assuming that you meant\n"
+			"    git branch -m %s %s\n", head, argv[0]);
 		rename_branch(head, argv[0], rename > 1);
-	else if (rename && (argc == 2))
+	} else if (rename && (argc == 2))
 		rename_branch(argv[0], argv[1], rename > 1);
 	else if (argc <= 2)
 		create_branch(argv[0], (argc == 2) ? argv[1] : head,
-- 
1.5.4.1.104.g84d88

-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux