Commit graph

150 commits

Author SHA1 Message Date
Junio C Hamano 3fa7c3da37 work around an obnoxious bash "safety feature" on OpenBSD
Bash (4.0.24) on OpenBSD 4.6 refuses to run this snippet:

    $ cat gomi.sh
    #!/bin/sh
    one="/var/tmp/1 1"
    rm -f /var/tmp/1 "/var/tmp/1 1"
    echo hello >$one
    $ sh gomi.sh; ls /var/tmp/1*
    /var/tmp/1 1
    $ bash gomi.sh; ls /var/tmp/1*
    gomi.sh: line 4: $one: ambiguous redirect
    ls: /var/tmp/1*: No such file or directory

Every competent shell programmer knows that a <$word in redirection is not
subject to field splitting (POSIX.1 "2.7 Redirection" explicitly lists the
kind of expansion performed: "... the word that follows the redirection
operator shall be subjected to ...", and "Field Splitting" is not among
them).

Some clueless folks apparently decided that users need to be protected in
the name of "security", however.

Output from "git grep -e '> *\$' -- '*.sh'" indicates that rebase-i
suffers from this bogus "safety".  Work it around by surrounding the
variable reference with a dq pair.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-01-26 19:16:02 -08:00
Stephen Boyd 9524cf2993 fix portability issues with $ in double quotes
Using a dollar sign in double quotes isn't portable. Escape them with
a backslash or replace the double quotes with single quotes.

Signed-off-by: Stephen Boyd <bebarino@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-01-26 15:16:54 -08:00
Junio C Hamano 76c9c0db3d rebase -i: Export GIT_AUTHOR_* variables explicitly
There is no point doing self-assignments of these variables.  Instead,
just export them to the environment, but do so in a sub-shell, because

	VAR1=VAL1 VAR2=VAL2 ... command arg1 arg2...

does not mark the variables exported if command that is run
is a shell function, according to POSIX.1.

The callers of do_with_author do not rely on seeing the effect of any
shell variable assignments that may happen inside what was called through
this shell function (currently "output" is the only one), so running it in
the subshell doesn't have an adverse semantic effect.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-01-23 21:39:11 -08:00
Michael Haggerty 8cddaeec0d rebase -i: Avoid non-portable "test X -a Y"
Reported by: Eric Blake <ebb9@byu.net>

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-01-22 13:18:14 -08:00
Junio C Hamano 668993ff19 Merge branch 'mh/rebase-fixup'
* mh/rebase-fixup:
  rebase -i: Retain user-edited commit messages after squash/fixup conflicts
  t3404: Set up more of the test repo in the "setup" step
  rebase -i: For fixup commands without squashes, do not start editor
  rebase -i: Change function make_squash_message into update_squash_message
  rebase -i: Extract function do_with_author
  rebase -i: Handle the author script all in one place in do_next
  rebase -i: Extract a function "commit_message"
  rebase -i: Simplify commit counting for generated commit messages
  rebase -i: Improve consistency of commit count in generated commit messages
  t3404: Test the commit count in commit messages generated by "rebase -i"
  rebase -i: Introduce a constant AMEND
  rebase -i: Introduce a constant AUTHOR_SCRIPT
  rebase -i: Document how temporary files are used
  rebase -i: Use symbolic constant $MSG consistently
  rebase -i: Use "test -n" instead of "test ! -z"
  rebase -i: Inline expression
  rebase -i: Remove dead code
  rebase -i: Make the condition for an "if" more transparent
2010-01-20 14:42:07 -08:00
Junio C Hamano cea20f2473 Merge branch 'ns/rebase-auto-squash'
* ns/rebase-auto-squash:
  rebase -i --autosquash: auto-squash commits

Conflicts:
	git-rebase--interactive.sh
2010-01-20 14:42:04 -08:00
Junio C Hamano cc6b41cc7d Merge branch 'mh/rebase-fixup' (early part)
* 'mh/rebase-fixup' (early part):
  rebase-i: Ignore comments and blank lines in peek_next_command
  lib-rebase: Allow comments and blank lines to be added to the rebase script
  lib-rebase: Provide clearer debugging info about what the editor did
  Add a command "fixup" to rebase --interactive
  t3404: Use test_commit to set up test repository
2010-01-20 14:41:48 -08:00
Michael Haggerty 6bdcd0d2fc rebase -i: Retain user-edited commit messages after squash/fixup conflicts
When a squash/fixup fails due to a conflict, the user is required to
edit the commit message.  Previously, if further squash/fixup commands
followed the conflicting squash/fixup, this user-edited message was
discarded and a new automatically-generated commit message was
suggested.

Change the handling of conflicts within squash/fixup command series:
Whenever the user is required to intervene, consider the resulting
commit to be a new basis for the following squash/fixups and use its
commit message in later suggested combined commit messages.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-01-14 00:27:57 -08:00
Michael Haggerty a25eb13909 rebase -i: For fixup commands without squashes, do not start editor
If the "rebase -i" commands include a series of fixup commands without
any squash commands, then commit the combined commit using the commit
message of the corresponding "pick" without starting up the
commit-message editor.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-01-14 00:27:57 -08:00
Michael Haggerty bde1a68624 rebase -i: Change function make_squash_message into update_squash_message
Alter the file $SQUASH_MSG in place rather than outputting the new
message then juggling it around.  Change the function name
accordingly.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-01-14 00:27:56 -08:00
Michael Haggerty 7756ecffe7 rebase -i: Extract function do_with_author
Call it instead of repeating similar code blocks in several places.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-01-14 00:27:56 -08:00
Michael Haggerty 5c5d059a0d rebase -i: Handle the author script all in one place in do_next
This change has no practical effect but makes the code easier to
follow.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-01-14 00:27:56 -08:00
Michael Haggerty ee0a4afbe2 rebase -i: Extract a function "commit_message"
...instead of repeating the same short but slightly obscure blob of
code in several places.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-01-14 00:27:56 -08:00
Michael Haggerty f99e269c44 rebase -i: Simplify commit counting for generated commit messages
Read the old count from the first line of the old commit message
rather than counting the number of commit message blocks in the file.
This is simpler, faster, and more robust (e.g., it cannot be confused
by strange commit message contents).

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-01-14 00:27:56 -08:00
Michael Haggerty 5065ed296a rebase -i: Improve consistency of commit count in generated commit messages
Use the numeral "2" instead of the word "two" when two commits are
being interactively squashed.  This makes the treatment consistent
with that for higher numbers of commits.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-01-14 00:27:56 -08:00
Michael Haggerty a4049ae7ac rebase -i: Introduce a constant AMEND
Add a constant AMEND holding the filename of the $DOTEST/amend file,
and document how this temporary file is used.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-01-14 00:27:56 -08:00
Michael Haggerty 0aac0de4fe rebase -i: Introduce a constant AUTHOR_SCRIPT
Add a constant AUTHOR_SCRIPT, holding the filename of the
$DOTEST/author_script file, and document how this temporary file is
used.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-01-14 00:27:56 -08:00
Michael Haggerty 80883bb30a rebase -i: Document how temporary files are used
Add documentation, inferred by reverse-engineering, about how
git-rebase--interactive.sh uses many of its temporary files.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-01-14 00:27:56 -08:00
Michael Haggerty bdb011ade4 rebase -i: Use symbolic constant $MSG consistently
The filename constant $MSG was previously used in some places and
written out literally in others.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-01-14 00:27:56 -08:00
Michael Haggerty 699f13ca9a rebase -i: Use "test -n" instead of "test ! -z"
It is a tiny bit simpler.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-01-14 00:27:56 -08:00
Michael Haggerty aa7eaff8b1 rebase -i: Inline expression
Inline expression when generating output rather than overwriting the
"sha1" local variable with a short SHA1.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-01-14 00:27:56 -08:00
Michael Haggerty 50438340bc rebase -i: Remove dead code
This branch of the "if" is only executed if $no_ff is empty, which
only happens if $1 was not '-n'.  (This code has been dead since
1d25c8cf82eead72e11287d574ef72d3ebec0db1.)

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-01-14 00:27:56 -08:00
Michael Haggerty 1d621fea18 rebase -i: Make the condition for an "if" more transparent
Test $no_ff separately rather than testing it indirectly by gluing it
onto a comparison of two SHA1s.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-01-14 00:27:56 -08:00
Junio C Hamano 1f73566af5 Merge branch 'jc/checkout-merge-base'
* jc/checkout-merge-base:
  rebase -i: teach --onto A...B syntax
  rebase: fix --onto A...B parsing and add tests
  "rebase --onto A...B" replays history on the merge base between A and B
  "checkout A...B" switches to the merge base between A and B
2010-01-13 12:31:13 -08:00
Michael Haggerty 234b3dae2f rebase-i: Ignore comments and blank lines in peek_next_command
Previously, blank lines and/or comments within a series of
squash/fixup commands would confuse "git rebase -i" into thinking that
the series was finished.  It would therefore require the user to edit
the commit message for the squash/fixup commits seen so far.  Then,
after continuing, it would ask the user to edit the commit message
again.

Ignore comments and blank lines within a group of squash/fixup
commands, allowing them to be processed in one go.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-01-12 12:34:50 -08:00
Michael Haggerty 2b77029f4a rebase--interactive: Ignore comments and blank lines in peek_next_command
Previously, blank lines and/or comments within a series of
squash/fixup commands would confuse "git rebase -i" into thinking that
the series was finished.  It would therefore require the user to edit
the commit message for the squash/fixup commits seen so far.  Then,
after continuing, it would ask the user to edit the commit message
again.

Ignore comments and blank lines within a group of squash/fixup
commands, allowing them to be processed in one go.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-01-11 20:31:48 -08:00
Nanako Shiraishi 230a456638 rebase -i: teach --onto A...B syntax
When rewriting commits on a topic branch, sometimes it is easier to
compare the version of commits before and after the rewrite if they are
based on the same commit that forked from the upstream. An earlier commit
by Junio (fixed up by the previous commit) gives "--onto A...B" syntax to
rebase command, and rebases on top of the merge base between A and B;
teach the same to the interactive version, too.

Signed-off-by: しらいし ななこ <nanako3@lavabit.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-01-07 11:15:20 -08:00
Nanako Shiraishi f59baa502f rebase -i --autosquash: auto-squash commits
Teach a new option, --autosquash, to the interactive rebase.
When the commit log message begins with "!fixup ...", and there
is a commit whose title begins with the same ..., automatically
modify the todo list of rebase -i so that the commit marked for
squashing come right after the commit to be modified, and change
the action of the moved commit from pick to squash.

Signed-off-by: Nanako Shiraishi <nanako3@lavabit.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-01-06 17:18:56 -08:00
Junio C Hamano b6b9f83ea1 Merge branch 'maint'
* maint:
  rebase -i: abort cleanly if the editor fails to launch
  technical-docs: document hash API
  api-strbuf.txt: fix typos and document launch_editor()
2009-12-19 23:20:16 -08:00
Björn Gustavsson e49ca974d6 rebase -i: abort cleanly if the editor fails to launch
If the user's configured editor is emacsclient, the editor
will fail to launch if emacs is not running and the git
command that tried to lanuch the editor will abort. For most
commands, all you have to do is to start emacs and repeat
the command.

The "git rebase -i" command, however, aborts without cleaning
the "$GIT_DIR/rebase-merge" directory if it fails to launch the
editor, so you'll need to do "git rebase --abort" before
repeating the rebase command.

Change "git rebase -i" to terminate using "die_abort" (instead of
with "die") if the initial launch of the editor fails.

Signed-off-by: Björn Gustavsson <bgustavsson@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-12-19 23:20:05 -08:00
Michael Haggerty 0205e72f08 Add a command "fixup" to rebase --interactive
The command is like "squash", except that it discards the commit message
of the corresponding commit.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Acked-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-12-07 13:50:57 -08:00
Junio C Hamano 957f5db74f Merge branch 'rs/work-around-grep-opt-insanity' into maint
* rs/work-around-grep-opt-insanity:
  Protect scripted Porcelains from GREP_OPTIONS insanity
  mergetool--lib: simplify guess_merge_tool()
2009-12-03 13:53:58 -08:00
Junio C Hamano ad7ace714d Merge branch 'rs/work-around-grep-opt-insanity'
* rs/work-around-grep-opt-insanity:
  Protect scripted Porcelains from GREP_OPTIONS insanity
  mergetool--lib: simplify guess_merge_tool()

Conflicts:
	git-instaweb.sh
2009-11-25 11:45:07 -08:00
Junio C Hamano e1622bfcba Protect scripted Porcelains from GREP_OPTIONS insanity
If the user has exported the GREP_OPTIONS environment variable, the output
from "grep" and "egrep" in scripted Porcelains may be different from what
they expect.  For example, we may want to count number of matching lines,
by "grep" piped to "wc -l", and GREP_OPTIONS=-C3 will break such use.

The approach taken by this change to address this issue is to protect only
our own use of grep/egrep.  Because we do not unset it at the beginning of
our scripts, hook scripts run from the scripted Porcelains are exposed to
the same insanity this environment variable causes when grep/egrep is used
to implement logic (e.g. "grep | wc -l"), and it is entirely up to the
hook scripts to protect themselves.

On the other hand, applypatch-msg hook may want to show offending words in
the proposed commit log message using grep to the end user, and the user
might want to set GREP_OPTIONS=--color to paint the match more visibly.
The approach to protect only our own use without unsetting the environment
variable globally will allow this use case.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-11-23 16:31:07 -08:00
Junio C Hamano 4d8c325888 Merge branch 'fc/doc-fast-forward'
* fc/doc-fast-forward:
  Use 'fast-forward' all over the place

Conflicts:
	builtin-merge.c
2009-11-15 16:41:02 -08:00
Junio C Hamano cd0f8e6d63 Merge branch 'maint'
* maint:
  help -a: do not unnecessarily look for a repository
  Do not try to remove directories when removing old links
  rebase -i: more graceful handling of invalid commands
  help -i: properly error out if no info viewer can be found
2009-10-28 11:21:46 -07:00
Jan Krüger f1be316ada rebase -i: more graceful handling of invalid commands
Currently, when there is an invalid command, the rest of the line is
still treated as if the command had been valid, i.e. rebase -i attempts
to produce a patch, using the next argument as a SHA1 name. If there is
no next argument or an invalid one, very confusing error messages
appear (the line was '.'; path to git-rebase-todo substituted):

Unknown command: .
fatal: ambiguous argument 'Please fix this in the file $somefile.':
unknown revision or path not in the working tree.
Use '--' to separate paths from revisions
fatal: Not a valid object name Please fix this in the file $somefile.
fatal: bad revision 'Please fix this in the file $somefile.'

Instead, verify the validity of the remaining line and error out earlier
if necessary.

Signed-off-by: Jan Krüger <jk@jk.gs>
Acked-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-10-27 23:12:44 -07:00
Felipe Contreras a75d7b5409 Use 'fast-forward' all over the place
It's a compound word.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-10-24 23:50:28 -07:00
Stephen Boyd 7725cb5e8b rebase -i: fix reword when using a terminal editor
We don't want to use output() on git-commit --amend when rewording the
commit message. This leads to confusion as the editor is run in a
subshell with it's output saved away, leaving the user with a seemingly
frozen terminal.

Fix by removing the output part.

Signed-off-by: Stephen Boyd <bebarino@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-10-19 00:49:09 -07:00
Björn Gustavsson 6741aa6c39 Teach 'rebase -i' the command "reword"
Make it easier to edit just the commit message for a commit
using 'git rebase -i' by introducing the "reword" command.

Signed-off-by: Björn Gustavsson <bgustavsson@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-10-07 21:46:41 -07:00
Greg Price 1830d9cb62 Fix rebase -p --onto
In a rebase with --onto, the correct test for whether we can skip
rewriting a commit is if it is already on top of $ONTO, not $UPSTREAM.
Without --onto, this distinction does not exist and the behavior does
not change.

In a situation with two merged branches on a common base X:

 X---o---o---o---M
  \             /
   x---x---x---x

 Y

if we try to move the branches from their base on X to be based on Y,
so as to get

 X

 Y---o'--o'--o'--M'
  \             /
   x'--x'--x'--x'

then we fail.  The command `git rebase -p --onto Y X M` moves only the
first-parent chain, like so:

 X
  \
   x---x---x---x
                \
 Y---o'--o'--o'--M'

because it mistakenly drops the other branch(es) x---x---x---x from
the TODO file.  This tests and fixes this behavior.

Signed-off-by: Greg Price <price@ksplice.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-07-22 11:15:06 -07:00
Junio C Hamano a0c0447b8e Merge branch 'uk/maint-1.5.3-rebase-i-reflog' into maint
* uk/maint-1.5.3-rebase-i-reflog:
  rebase--interactive: remote stray closing parenthesis

Conflicts:
	git-rebase--interactive.sh
2009-06-11 14:14:00 -07:00
Uwe Kleine-König 795cbe938f rebase--interactive: remote stray closing parenthesis
it was introduced in 68a163c9b4

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Cc: Jöhännës "Dschö" Schindëlin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-06-11 14:01:15 -07:00
Johannes Schindelin 0e757e30c7 rebase -i: avoid 'git reset' when possible
When picking commits whose parents have not changed, we do not need to
rewrite the commit.  We do not need to reset the working directory to
the parent's state, either.

Requested by Sverre Rabbelier.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-03-03 10:56:22 -08:00
Junio C Hamano 29254142dd Merge branch 'js/maint-rebase-i-submodule'
* js/maint-rebase-i-submodule:
  Fix submodule squashing into unrelated commit
  rebase -i squashes submodule changes into unrelated commit
2009-01-31 18:07:55 -08:00
Johannes Schindelin 94c88edef7 Fix submodule squashing into unrelated commit
Actually, I think the issue is pretty independent of submodules; when
"git commit" gets an empty parameter, it misinterprets it as a file.

So avoid passing an empty parameter to "git commit".

Actually, this is a nice cleanup, as MSG_FILE and EDIT_COMMIT were mutually
exclusive; use one variable instead

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-01-28 14:54:58 -08:00
Junio C Hamano a6c7a27691 rebase -i: correctly remember --root flag across --continue
d911d14 (rebase -i: learn to rebase root commit, 2009-01-02) tried to
remember the --root flag across a merge conflict in a broken way.
Introduce a flag file $DOTEST/rebase-root to fix and clarify.

While at it, also make sure $UPSTREAM is always initialized to guard
against existing values in the environment.

[tr: added tests]

Signed-off-by: Thomas Rast <trast@student.ethz.ch>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-01-26 21:23:19 -08:00
Johannes Schindelin 277d7e91ae rebase -i --root: fix check for number of arguments
If we are not rebasing with --root, then $# can only be either 1 (base)
or 2 (base and the name of the branch to be rebased).

If we are rebasing with --root, then it is Ok if $# is 0 (rebase the
current branch down to everything) or 1 (rebase the named branch down to
everything).

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Acked-by: Thomas Rast <trast@student.ethz.ch>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-01-25 22:06:50 -08:00
Junio C Hamano 90abc19b5a Merge branch 'tr/rebase-root'
* tr/rebase-root:
  rebase: update documentation for --root
  rebase -i: learn to rebase root commit
  rebase: learn to rebase root commit
  rebase -i: execute hook only after argument checking
2009-01-17 23:06:38 -08:00
Junio C Hamano 1cbe69f649 Merge branch 'maint-1.6.0' into maint
* maint-1.6.0:
  Avoid spurious error messages on error mistakes.
  contrib/examples/README: give an explanation of the status of these files
2009-01-13 00:40:19 -08:00