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

Re: [PATCH] rebase [-i --exec | -ix] <CMD>...

From
Junio C Hamano <gitster@pobox.com>
Date
Jun 4, 2012, 17:42 UTC
Message-ID
<7vhaurt1m6.fsf@alter.siamese.dyndns.org>
In-Reply-To
<1338817674-22877-1-git-send-email-Lucien.Kong@ensimag.imag.fr>
Kong Lucien <Lucien.Kong@ensimag.imag.fr> writes:
Show 19 quoted lines
> diff --git a/Documentation/git-rebase.txt b/Documentation/git-rebase.txt
> index 147fa1a..96dbf26 100644
> --- a/Documentation/git-rebase.txt
> +++ b/Documentation/git-rebase.txt
> @@ -210,6 +210,17 @@ rebase.autosquash::
>  
>  OPTIONS
>  -------
> +<cmd>::
> +	Shell command executed between each commit applications. The
> +	--exec option has to be specified.
> ++
> +You may execute several commands between each commit applications.
> +Therefore, you can use one instance of exec:
> +	git rebase -i --exec "cmd1; cmd2; ...".
> +You can also insert several instances of exec, if you wish to
> +only have one command per line for example:
> +	git rebase -i --exec "cmd1" --exec "cmd2" ...
> +

The description of this and exisitng <newbase> look very odd. The usual way to describe an option that take a parameter in the OPTIONS section is to instead do:

	--onto <newbase>::
		Description of what --onto option does and how <newbase>
		is used in what it does.
	--exec <cmd>::
		Description of what --exec option does, and how	<cmd> 
                is used in what it does.
Show 11 quoted lines
> @@ -336,6 +347,13 @@ link:howto/revert-a-faulty-me
>  	user edit that list before rebasing.  This mode can also be used to
>  	split commits (see SPLITTING COMMITS below).
>  
> +-x::
> +--exec::
> +	Automatically add "exec" followed by <cmd> between each commit
> +	applications (see INTERACTIVE MODE below).
> ++
> +This has to be used along with the `--interactive` option explicitly.
> +
OK.
> @@ -521,6 +539,27 @@ in `$SHELL`, or the default shell if
> ...
> +If the option '-i' is missing, The command will return the usage page
> +of "git rebase". Same if there is no <cmd> specified behind --exec.
OK.
Show 20 quoted lines
> diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
> index 0c19b7c..7444160 100644
> --- a/git-rebase--interactive.sh
> +++ b/git-rebase--interactive.sh
> @@ -876,6 +876,19 @@ cat >> "$todo" << EOF
>  #
>  EOF
>  
> +if test -n "$cmd"
> +then
> +	OIFS=$IFS
> +	IFS=','
> +	for i in $cmd
> +	do
> +		sed "/^pick .*/aexec $i" "$todo" >tmp
> +		cat tmp >"$todo"
> +	done
> +	rm tmp
> +	IFS=$OIFS
> +fi

Where does this "we split at comma", implying "the user is forbidden to have a comma in the executed command and its arguments" come from?

A more conventional way that would be less troublesome in the real life is to use LF instead in a case like this (and git-rebase.sh already defines it for exactly a case like this).

I am not sure if that "aexec" is portable outside GNUism, though. Traditionally the a(ppend) command is spelled like this:

	[1addr]a\
        text
to write one line (cf. http://pubs.opengroup.org/onlinepubs/9699919799/utilities/sed.html#tag_20_116_13_03).

Why is "pick" special? Don't you want to run the commands after "edit", "reword", "squash", "fixup"?

This should come immediately after autosquash rearranged the insns in the $todo file, before the help text is appended to it.

Show 12 quoted lines
> diff --git a/git-rebase.sh b/git-rebase.sh
> index 24a2840..a8b1793 100755
> --- a/git-rebase.sh
> +++ b/git-rebase.sh
> @@ -76,6 +78,7 @@ If you would prefer to skip this patch, instead run \"git rebase --skip\".
>  To check out the original branch and stop rebasing run \"git rebase --abort\".
>  "
>  unset onto
> +unset cmd
>  strategy=
>  strategy_opts=
>  do_merge=

You copied badness from the existing "unset onto"; I do not think the rest of the code (and especially the new code you add) treats a variable that is not set and set to an empty string any different, and setting it to empty is the right thing to do in such a case.

Show 6 quoted lines
> @@ -219,6 +222,24 @@ do
>  		onto="$2"
>  		shift
>  		;;
> +	-x)
> +		exec_flag=true

exec_flag is not cleared at the beginning of the script, so if the command is run without "-x" on the command line, it can have whatever garbage value that was in the environment. You know that $cmd is empty if "-x" was not given, and you can make sure $cmd becomes non-empty when "-x" is given, so remove use of this variable and replace any 'test -n "$exec_flag"' with 'test -n "$cmd"'.

> +		test 3 -le "$#" || usage

Why 3? You only care about the presense of $2 you are about to read, no?

Show 15 quoted lines
> +		if orig_head=$(git rev-parse -q --verify "$2") ||
> +		   test `expr substr "$2" 1 1` = -
> +		then
> +			echo "You must specify a command after --exec option\n"
> +			usage
> +		else
> +			if test -n "$cmd"
> +			then
> +				cmd="$2,$cmd"
> +			else
> +				cmd="$2"
> +			fi
> +		fi
> +		shift
> +		;;

Are you telling me that I cannot have a branch named "make"? Drop this nonsense, and just write it in a more straightforward way, e.g.

	-x)
		test 2 -le "$#" || usage
                cmd="${cmd:+"$cmd$LF"} $2"
                shift
                ;;
                
Show 10 quoted lines
>  	-i)
>  		interactive_rebase=explicit
>  		;;
> @@ -304,6 +325,13 @@ do
>  done
>  test $# -gt 2 && usage
>  
> +if test -n "$exec_flag" &&
> +   test -z "$interactive_rebase"
> +then
I think this should be
	if test -n "$cmd" && test "$interactive_rebase" != explicit
        then
Show 8 quoted lines
> @@ -348,7 +376,6 @@ abort)
>  	exit
>  	;;
>  esac
> -
>  # Make sure no rebase is in progress
>  if test -n "$in_progress"
>  then
Why?
Previous: Kong LucienNext: Matthieu Moy
Message 2 of 50 in “rebase [-i --exec | -ix] <CMD>...”
  1. rebase [-i --exec | -ix] <CMD>...Kong Lucien, Jun 4, 2012
  2. Junio C HamanoJun 4, 2012
  3. Matthieu MoyJun 4, 2012
  4. Junio C HamanoJun 4, 2012
  5. konglu@minatec.inpg.frJun 5, 2012
  6. Junio C HamanoJun 5, 2012
  7. Matthieu MoyJun 4, 2012
  8. [PATCHv2] rebase [-i --exec | -ix] <CMD>...Lucien Kong, Jun 6, 2012
  9. Matthieu MoyJun 6, 2012
  10. Junio C HamanoJun 6, 2012
  11. Zbigniew Jędrzejewski-SzmekJun 7, 2012
  12. Johannes SixtJun 7, 2012
  13. konglu@minatec.inpg.frJun 7, 2012
  14. Matthieu MoyJun 7, 2012
  15. 1/2 git-rebase.txt: "--onto" option updatedLucien Kong, Jun 8, 2012
  16. 2/2 rebase [-i --exec | -ix] <CMD>...Lucien Kong, Jun 8, 2012
  17. Johannes SixtJun 8, 2012
  18. Torsten BögershausenJun 8, 2012
  19. konglu@minatec.inpg.frJun 8, 2012
  20. Torsten BögershausenJun 8, 2012
  21. konglu@minatec.inpg.frJun 8, 2012
  22. Torsten BögershausenJun 8, 2012
  23. konglu@minatec.inpg.frJun 8, 2012
  24. Torsten BögershausenJun 9, 2012
  25. konglu@minatec.inpg.frJun 9, 2012
  26. [PATCHv4] rebase [-i --exec | -ix] <CMD>...Lucien Kong, Jun 10, 2012
  27. Johannes SixtJun 10, 2012
  28. Junio C HamanoJun 11, 2012
  29. Johannes SixtJun 12, 2012
  30. Junio C HamanoJun 12, 2012
  31. [PATCHv5] rebase [-i --exec | -ix] <CMD>...Lucien Kong, Jun 12, 2012
  32. Zbigniew Jędrzejewski-SzmekJun 12, 2012
  33. Junio C HamanoJun 12, 2012
  34. Zbigniew Jędrzejewski-SzmekJun 13, 2012
  35. Junio C HamanoJun 13, 2012
  36. konglu@minatec.inpg.frJun 13, 2012
  37. Junio C HamanoJun 13, 2012
  38. konglu@minatec.inpg.frJun 13, 2012
  39. Johannes SixtJun 13, 2012
  40. Zbigniew Jędrzejewski-SzmekJun 13, 2012
  41. Junio C HamanoJun 13, 2012
  42. Junio C HamanoJun 13, 2012
  43. Zbigniew Jędrzejewski-SzmekJun 13, 2012
  44. Matthieu MoyJun 14, 2012
  45. Marc BranchaudJun 14, 2012
  46. Matthieu MoyJun 8, 2012
  47. Junio C HamanoJun 8, 2012
  48. konglu@minatec.inpg.frJun 8, 2012
  49. Junio C HamanoJun 8, 2012
  50. konglu@minatec.inpg.frJun 8, 2012

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.