git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v5 3/6] pull: refactor $rebase variable into $mode

From
Felipe Contreras <felipe.contreras@gmail.com>
Date
Apr 29, 2014, 11:17 UTC
Message-ID
<1398770226-9686-4-git-send-email-felipe.contreras@gmail.com>
In-Reply-To
<1398770226-9686-1-git-send-email-felipe.contreras@gmail.com>
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 git-pull.sh | 65 ++++++++++++++++++++++++++++++++-----------------------------
 1 file changed, 34 insertions(+), 31 deletions(-)
diff --git a/git-pull.sh b/git-pull.sh
index d4e25f1..3dfd856 100755
--- a/git-pull.sh
+++ b/git-pull.sh
@@ -57,16 +57,11 @@ then
 	mode=$(git config pull.mode)
 fi
 case "$mode" in
-merge)
-	rebase="false"
-	;;
-rebase)
-	rebase="true"
+merge|rebase|'')
 	;;
 rebase-preserve)
-	rebase="preserve"
-	;;
-'')
+	mode="rebase"
+	rebase_args="--preserve-merges"
 	;;
 *)
 	echo "Invalid value for 'mode'"
@@ -74,7 +69,8 @@ rebase-preserve)
 	exit 1
 	;;
 esac
-if test -z "$rebase"
+
+if test -z "$mode"
 then
 	rebase=$(bool_or_string_config branch.$curr_branch_short.rebase)
 	if test -z "$rebase"
@@ -153,10 +149,10 @@ do
 		rebase="${1#*=}"
 		;;
 	-r|--r|--re|--reb|--reba|--rebas|--rebase)
-		rebase=true
+		mode=rebase
 		;;
 	--no-r|--no-re|--no-reb|--no-reba|--no-rebas|--no-rebase)
-		rebase=false
+		mode=
 		;;
 	--recurse-submodules)
 		recurse_submodules=--recurse-submodules
@@ -187,19 +183,26 @@ do
 	shift
 done
 
-case "$rebase" in
-preserve)
-	rebase=true
-	rebase_args=--preserve-merges
-	;;
-true|false|'')
-	;;
-*)
-	echo "Invalid value for --rebase, should be true, false, or preserve"
-	usage
-	exit 1
-	;;
-esac
+if test -n "$rebase"
+then
+	case "$rebase" in
+	true)
+		mode="rebase"
+		;;
+	false)
+		mode="merge"
+		;;
+	preserve)
+		mode="rebase"
+		rebase_args=--preserve-merges
+		;;
+	*)
+		echo "Invalid value for --rebase, should be true, false, or preserve"
+		usage
+		exit 1
+		;;
+	esac
+fi
 
 error_on_no_merge_candidates () {
 	exec >&2
@@ -213,7 +216,7 @@ error_on_no_merge_candidates () {
 		esac
 	done
 
-	if test true = "$rebase"
+	if test "$mode" = rebase
 	then
 		op_type=rebase
 		op_prep=against
@@ -226,7 +229,7 @@ error_on_no_merge_candidates () {
 	remote=$(git config "branch.$curr_branch_short.remote")
 
 	if [ $# -gt 1 ]; then
-		if [ "$rebase" = true ]; then
+		if [ "$mode" = rebase ]; then
 			printf "There is no candidate for rebasing against "
 		else
 			printf "There are no candidates for merging "
@@ -249,7 +252,7 @@ error_on_no_merge_candidates () {
 	exit 1
 }
 
-test true = "$rebase" && {
+test "$mode" = rebase && {
 	if ! git rev-parse -q --verify HEAD >/dev/null
 	then
 		# On an unborn branch
@@ -306,7 +309,7 @@ case "$merge_head" in
 	then
 		die "$(gettext "Cannot merge multiple branches into empty head")"
 	fi
-	if test true = "$rebase"
+	if test "$mode" = rebase
 	then
 		die "$(gettext "Cannot rebase onto multiple branches")"
 	fi
@@ -327,7 +330,7 @@ then
 	exit
 fi
 
-if test true = "$rebase"
+if test "$mode" = rebase
 then
 	o=$(git show-branch --merge-base $curr_branch $merge_head $oldremoteref)
 	if test "$oldremoteref" = "$o"
@@ -337,8 +340,8 @@ then
 fi
 
 merge_name=$(git fmt-merge-msg $log_arg <"$GIT_DIR/FETCH_HEAD") || exit
-case "$rebase" in
-true)
+case "$mode" in
+rebase)
 	eval="git-rebase $diffstat $strategy_args $merge_args $rebase_args $verbosity"
 	eval="$eval --onto $merge_head ${oldremoteref:-$merge_head}"
 	;;
-- 
1.9.2+fc1.3.gade8541
Previous: Felipe ContrerasNext: Felipe Contreras
Message 10 of 19 in “Reject non-ff pulls by default”
  1. 0/6 Reject non-ff pulls by defaultFelipe Contreras, Apr 29, 2014
  2. 1/6 pull: rename pull.rename to pull.modeFelipe Contreras, Apr 29, 2014
  3. Marat RadchenkoApr 29, 2014
  4. Felipe ContrerasApr 29, 2014
  5. Philip OakleyApr 29, 2014
  6. Felipe ContrerasApr 29, 2014
  7. Philip OakleyApr 29, 2014
  8. Richard HansenApr 30, 2014
  9. 2/6 pull: migrate all the tests to pull.modeFelipe Contreras, Apr 29, 2014
  10. 3/6 pull: refactor $rebase variable into $modeFelipe Contreras, Apr 29, 2014
  11. 4/6 pull: add --merge optionFelipe Contreras, Apr 29, 2014
  12. 5/6 pull: add merge-ff-only optionFelipe Contreras, Apr 29, 2014
  13. 6/6 pull: only allow ff merges by defaultFelipe Contreras, Apr 29, 2014
  14. Junio C HamanoApr 30, 2014
  15. Felipe ContrerasApr 30, 2014
  16. Junio C HamanoApr 30, 2014
  17. Felipe ContrerasApr 30, 2014
  18. Junio C HamanoApr 30, 2014
  19. Junio C HamanoApr 30, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.