Skip to contentSkip to conversation

disallow providing multiple upstream branches to rebase, pull --rebase

PATCH In review Jay Soffian 2 participants 6 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 disallow providing multiple upstream branches to rebase, pull --rebase

It does not make sense to provide multiple upstream branches to either git pull --rebase, or to git rebase, so disallow both.

---
 git-pull.sh   |    5 +++++
 git-rebase.sh |    1 +
 2 files changed, 6 insertions(+), 0 deletions(-)
git-pull.sh +5 -0
index 2c7f432..25adddf 100755
@@ -171,6 +171,11 @@ case "$merge_head" in
 		echo >&2 "Cannot merge multiple branches into empty head"
 		exit 1
 	fi
+	if test true = "$rebase"
+	then
+		echo >&2 "Cannot rebase onto multiple branches"
+		exit 1
+	fi
 	;;
 esac
 
git-rebase.sh +1 -0
index 5d9a393..ffb6027 100755
@@ -319,6 +319,7 @@ do
 	esac
 	shift
 done
+test $# -gt 1 && usage
 
 # Make sure we do not have $GIT_DIR/rebase-apply
 if test -z "$do_merge"
Signature · 1 line
1.6.2.rc1.210.g159a
#1 lore raw

Hi,

Quoted 15 lines · Jay Soffian

It does not make sense to provide multiple upstream branches to either git pull --rebase, or to git rebase, so disallow both.

---
 git-pull.sh   |    5 +++++
 git-rebase.sh |    1 +
 2 files changed, 6 insertions(+), 0 deletions(-)
git-pull.sh +0 -0
index 2c7f432..25adddf 100755
@@ -171,6 +171,11 @@ case "$merge_head" in
 		echo >&2 "Cannot merge multiple branches into empty head"

git-pull.sh case "$merge_head" in · line 181

Quoted 10 lines
git-pull.sh +5 -0
 		exit 1
 	fi
+	if test true = "$rebase"
+	then
+		echo >&2 "Cannot rebase onto multiple branches"
+		exit 1
+	fi
 	;;
 esac
 

Good catch!

git-rebase.sh do · line 322

Quoted 9 lines
git-rebase.sh +1 -0
index 5d9a393..ffb6027 100755
@@ -319,6 +319,7 @@ do
 	esac
 	shift
 done
+test $# -gt 1 && usage

Did you just break

	$ git rebase $UPSTREAM $BRANCH_TO_SWITCH_TO

?

Ciao,
Dscho

#2 lore raw
Quoted 12 lines · Johannes Schindelin

git-rebase.sh do · line 322

Quoted 9 lines
git-rebase.sh +1 -0
index 5d9a393..ffb6027 100755
@@ -319,6 +319,7 @@ do
      esac
      shift
 done
+test $# -gt 1 && usage

Did you just break

Quoted 1 line
       $ git rebase $UPSTREAM $BRANCH_TO_SWITCH_TO

Crap, I missed that usage somehow (and I guess the test suite doesn't rely on it either...). I think moving the "test $# -gt 1 && usage" below:

if test -z "$rebase_root"
then

	# The upstream head must be given.  Make sure it is valid.
	upstream_name="$1"
	shift
	upstream=`git rev-parse --verify "${upstream_name}^0"` ||
	die "invalid upstream $upstream_name"
	unset root_flag
	upstream_arg="$upstream_name"
else
	test -z "$newbase" && die "--root must be used with --onto"
	unset upstream_name
	unset upstream
	root_flag="--root"
	upstream_arg="$root_flag"

fi

will do the trick, yes?

j.

#3 lore raw

Hi,

Quoted 35 lines · Jay Soffian
Quoted 12 lines · Johannes Schindelin

git-rebase.sh do · line 322

Quoted 9 lines
git-rebase.sh +1 -0
index 5d9a393..ffb6027 100755
@@ -319,6 +319,7 @@ do
      esac
      shift
 done
+test $# -gt 1 && usage

Did you just break

Quoted 1 line
       $ git rebase $UPSTREAM $BRANCH_TO_SWITCH_TO

Crap, I missed that usage somehow (and I guess the test suite doesn't rely on it either...). I think moving the "test $# -gt 1 && usage" below:

if test -z "$rebase_root"
then

	# The upstream head must be given.  Make sure it is valid.
	upstream_name="$1"
	shift
	upstream=`git rev-parse --verify "${upstream_name}^0"` ||
	die "invalid upstream $upstream_name"
	unset root_flag
	upstream_arg="$upstream_name"
else
	test -z "$newbase" && die "--root must be used with --onto"
	unset upstream_name
	unset upstream
	root_flag="--root"
	upstream_arg="$root_flag"
Quoted 3 lines

fi

will do the trick, yes?

Nope. Note the "shift" in the first arm? It is so that the code below can check for $#, and it indeed does, in a 'case' statement.

(Note: I am writing all this from memory, it could be slightly different, but the essence is still valid.)

Ciao,
Dscho

#4 lore raw
Quoted 17 lines · Johannes Schindelin
Quoted 17 lines

if test -z "$rebase_root"
then
# The upstream head must be given. Make sure it is valid. upstream_name="$1"
shift
upstream=git rev-parse --verify "${upstream_name}^0" || die "invalid upstream $upstream_name"
unset root_flag
upstream_arg="$upstream_name"
else

      test -z "$newbase" && die "--root must be used with --onto"
      unset upstream_name
      unset upstream
      root_flag="--root"
      upstream_arg="$root_flag"

fi

Quoted 4 lines
Quoted 1 line

will do the trick, yes?

Nope. Note the "shift" in the first arm? It is so that the code below can check for $#, and it indeed does, in a 'case' statement.

The case statement checks $# against 1 and *, not 1 and 0. And I don't see how > 1 is valid at that point. So I can modify the case statement to check against 1, 0, and have * emit usage, or I think moving the "test $# -gt 1 && usage" to where I suggested in the last message would do the trick. The only difference would be whether a pre-rebase hook runs in the case of invalid arguments (the case statement is after that hook runs).

j.

#5 lore raw

Hi,

Quoted 24 lines · Jay Soffian
Quoted 17 lines · Johannes Schindelin
Quoted 17 lines

if test -z "$rebase_root"
then
# The upstream head must be given. Make sure it is valid. upstream_name="$1"
shift
upstream=git rev-parse --verify "${upstream_name}^0" || die "invalid upstream $upstream_name"
unset root_flag
upstream_arg="$upstream_name"
else

      test -z "$newbase" && die "--root must be used with --onto"
      unset upstream_name
      unset upstream
      root_flag="--root"
      upstream_arg="$root_flag"

fi

Quoted 4 lines
Quoted 1 line

will do the trick, yes?

Nope. Note the "shift" in the first arm? It is so that the code below can check for $#, and it indeed does, in a 'case' statement.

Quoted 7 lines

The case statement checks $# against 1 and *, not 1 and 0. And I don't see how > 1 is valid at that point. So I can modify the case statement to check against 1, 0, and have * emit usage, or I think moving the "test $# -gt 1 && usage" to where I suggested in the last message would do the trick. The only difference would be whether a pre-rebase hook runs in the case of invalid arguments (the case statement is after that hook runs).

Of course, you could also leave the test where it was, and just replace the 1 by a 2.

Ciao,
Dscho