diff mbox series

[RFC,04/20] git-submodule.sh: normalize parsing of "--branch"

Message ID RFC-patch-04.20-f27723aa0a2-20220610T011725Z-avarab@gmail.com (mailing list archive)
State New, archived
Headers show
Series submodule: remove git-submodule.sh, create bare builtin/submodule.c | expand

Commit Message

Ævar Arnfjörð Bjarmason June 10, 2022, 2:01 a.m. UTC
In 5c08dbbdf1a (git-submodule: fix subcommand parser, 2008-01-15) the
"--branch" option was supported as an option to "git submodule"
itself, i.e. "git submodule --branch" as a side-effect of its
implementation.

Then in b57e8119e6e (submodule: teach set-branch subcommand,
2019-02-08) when the "set-branch" subcommand was added the assertion
that we shouldn't have "--branch" anywhere except as an argument to
"add" and "set-branch" was copy/pasted from the adjacent check for
"--cache" added (or rather modified) in 496eeeb19b9 (git-submodule.sh:
avoid "test <cond> -a/-o <cond>", 2014-06-10).

But there's been a logic error in that check, this looked like it
should be supporting:

    git submodule --branch <branch> (add | set-branch) [<options>]

But due to "||" in the condition (as opposed to "&&" for "--cache") if
we have "--branch" here already we'll emit usage, even for "add" and
"set-branch".

Since nobody's complained about "--branch <branch>" not being
supported as argument to "git submodule" itself, i.e. we want to
support:

    git submodule (add | set-branch) --branch <branch>  [<options>]

But not the first form noted above. Let's just remove this code, we've
never documented "--branch" as a top-level option (unlike "--quiet"),
so this looks like it was an accident of the implementation, which we
broke v2.22.0, so we also know it must not have been important to
anyone.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 git-submodule.sh | 14 --------------
 1 file changed, 14 deletions(-)
diff mbox series

Patch

diff --git a/git-submodule.sh b/git-submodule.sh
index 53847bbf6e2..1b0a31b8383 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -574,14 +574,6 @@  do
 	-q|--quiet)
 		GIT_QUIET=1
 		;;
-	-b|--branch)
-		case "$2" in
-		'')
-			usage
-			;;
-		esac
-		branch="$2"; shift
-		;;
 	--cached)
 		cached="$1"
 		;;
@@ -609,12 +601,6 @@  then
     fi
 fi
 
-# "-b branch" is accepted only by "add" and "set-branch"
-if test -n "$branch" && (test "$command" != add || test "$command" != set-branch)
-then
-	usage
-fi
-
 # "--cached" is accepted only by "status" and "summary"
 if test -n "$cached" && test "$command" != status && test "$command" != summary
 then