2888605c64 (builtin-commit: fix
partial-commit support) mindlessly cut and pasted from
builtin-ls-files.c, and included a part that was meant to
exclude redundant path after "ls-files --with-tree" overlayed
the HEAD commit on top of the index. This logic does not apply
to what git-commit does and should not have been copied, even
though it would not hurt.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
When running "git commit paths" to create a partial commit, we
used to carefully build the temporary index so that we do not
lose the cached stat information. The rewrite of the command in
C lost it by carelessly using read_tree().
This resurrects the earlier behaviour to keep the cached stat
information as much as possible by using one-tree merge logic.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Although we traditionally stripped away excess blank lines, trailing
whitespaces and lines that begin with "#" from the commit log message,
sometimes the message just has to be the way user wants it.
For instance, a commit message template can contain lines that begin with
"#", the message must be kept as close to its original source as possible
if you are converting from a foreign SCM, or maybe the message has a shell
script including its comments for future reference.
The cleanup modes are default, verbatim, whitespace and strip. The
default mode depends on if the message is being edited and will either
strip whitespace and comments (if editor active) or just strip the
whitespace (for where the message is given explicitely).
Signed-off-by: Alex Riesen <raa.lkml@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
The flag no_edit meant "we have got final message from the user
and will not editing it any further", but there were quite a few
places that needed to check !no_edit. Rename the variable to
use_editor and reverse the logic everywhere.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
When amending initial commit without editor, the command
incorrectly barfed because the check to see if there is anything
to commit referenced the non-existent HEAD^1.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
The prepare_log_message() function serves two purposes:
- Prepares the commit log message template, to be given to the end
user;
- Return true if there is something committable;
7168624c35 (Do not generate full commit
log message if it is not going to be used) cheated to omit the former
when we know the log message template is not going to be used. However,
its replacement logic to see if there is something committable was
botched. When amending, it should compare the index with the parent of
the HEAD, not the current HEAD. Otherwise you cannot run --amend to
fix only the message without changing the tree.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This enables -B -M to the summary output after a commit is made so that
it is in line with what is shown in git-status and commit log template.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Because print_summary() forgot to call diff_setup_done() after futzing with
diff output options, it failed to activate recursive diff, which resulted in
an incorrect summary.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
After tentatively applying a patch from a contributor, you can get a
replacement patch with corrected code and unusable commit log message.
In such a case, this sequence ought to give you an editor based on the
message in the earlier commit, to let you describe an incremental
improvement:
git reset --hard HEAD^ ;# discard the earlier one
git am <corrected-patch
git commit --amend -c HEAD@{1}
Unfortunately, --amend insisted reusing the message from the commit
being amended, ignoring the -c option. This corrects it.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
When recording a merge that conflicted and ends up in no changes after
manual resolution, commit callchain looked like this:
cmd_commit() ->
prepare_log_message() ->
run_status() ->
wt_status_print()
This invocation of run_status() is asked to find out if there is a
committable change, but it unconditionally gave instructions such as
"use git-add" at the same time. When in merge, we do allow an empty
change to be recorded, so after showing this message the code still went
ahead and made a commit.
This introduces "nowarn" parameter to run_status() to avoid these
useless messages. If we are not allowed to create an empty commit, we
already call run_status() again in the original codepath, and the
message will be shown from that call anyway.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
The scripted version relied on the nice "auto-strip the terminating LF"
behaviour shell gives to "var=$(cmd)" construct, but we have to roll
that ourselves.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
An earlier fix to the said commit was incomplete; it mixed up the
meaning of the flag parameter passed to the internal fmt_ident()
function, so this corrects it.
git_author_info() and git_committer_info() can be told to issue a
warning when no usable user information is found, and optionally can be
told to error out. Operations that actually use the information to
record a new commit or a tag will still error out, but the caller to
leave reflog record will just silently use bogus user information.
Not warning on misconfigured user information while writing a reflog
entry is somewhat debatable, but it is probably nicer to the users to
silently let it pass, because the only information you are losing is who
checked out the branch.
* git_author_info() and git_committer_info() used to take 1 (positive
int) to error out with a warning on misconfiguration; this is now
signalled with a symbolic constant IDENT_ERROR_ON_NO_NAME.
* These functions used to take -1 (negative int) to warn but continue;
this is now signalled with a symbolic constant IDENT_WARN_ON_NO_NAME.
* fmt_ident() function implements the above error reporting behaviour
common to git_author_info() and git_committer_info(). A symbolic
constant IDENT_NO_DATE can be or'ed in to the flag parameter to make
it return only the "Name <email@address.xz>".
* fmt_name() is a thin wrapper around fmt_ident() that always passes
IDENT_ERROR_ON_NO_NAME and IDENT_NO_DATE.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
The old git-commit.sh script allowed the commit-msg hook to not only
prevent a commit from proceding, but also to edit the commit message
on the fly and allow it to proceed. So here we teach builtin-commit
to do the same.
This is based on Wincent's patch, but redone with a clarified logic.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
At the moment the --no-verify switch to "git commit" instructs it to
skip over the pre-commit hook. Here we teach "git commit --no-verify"
to skip over the commit-msg hook as well. This brings the behaviour
of builtin-commit back in line with git-commit.sh.
Signed-off-by: Wincent Colaiuta <win@wincent.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
The output of git-status was recently changed to output relative
paths. Setting this variable to false restores the old behavior for
any old-timers that prefer it.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
* wc/add-i:
git-add -i: add help text for list-and-choose UI
add -i: allow prefix highlighting for "Add untracked" as well.
Highlight keyboard shortcuts in git-add--interactive
Document all help keys in "git add -i" patch mode.
Add "--patch" option to git-add--interactive
add -i: Fix running from a subdirectory
builtin-add: fix command line building to call interactive
git-add -i: allow multiple selection in patch subcommand
Add path-limiting to git-add--interactive
Teach builtin-add to pass multiple paths to git-add--interactive
It does not usually make sense to record a commit that has the exact
same tree as its sole parent commit and that is why git-commit prevents
you from making such a mistake, but when data from foreign scm is
involved, it is a different story. We are equipped to represent such an
(perhaps insane, perhaps by mistake, or perhaps done on purpose) empty
change, and it is better to represent it bypassing the safety valve for
native use.
This is primarily for use by foreign scm interface scripts.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Normally, it should not be allowed to generate an empty commit. A merge
commit generated with git 'merge -s ours' does not change the tree (along
the first parent), but merges are not "empty" even if they do not change
the tree. Hence, we should be careful not to forbid this case.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
git status shares the same usage information as git commit since it
shows what would be committed if the same options are given. However,
when displaying the usage information for git status it should say it
is for git status not git commit.
Signed-off-by: Shawn Bohrer <shawn.bohrer@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Introduce fmt_name() specifically meant for formatting the name and
email pair, to add signed-off-by value. This reverts parts of
13208572fb (builtin-commit: fix --signoff)
so that an empty datestamp string given to fmt_ident() by mistake will
error out as before.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
These are three types of cleanups here:
1. remove newline from die message (die/report adds it
already)
2. typo: s/merger/merge/
3. the old "* no commit message? aborting commit." is now
prepended with "fatal: ", making the asterisk look a
little funny. Let's just remove it.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Like when it is already specified through -C, -F or -m to git-commit.
Signed-off-by: Alex Riesen <raa.lkml@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
The editor program to let the user edit the log message used to
get GIT_INDEX_FILE environment variable pointing at the right
file, but this was lost when git-commit was rewritten in C.
Signed-off-by: Pierre Habouzit <madcoder@debian.org>
Acked-by: Kristian Høgsberg <krh@redhat.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This fixes the pathspec interactive_add() passes to the underlying
git-add--interactive helper. When the command was run from a
subdirectory, cmd_add() already has gone up to the toplevel of the work
tree, and the helper will be spawned from there. The pathspec given on
the command line from the user needs to be adjusted for this.
This adds "validate_pathspec()" function in the callchain, but it does
not validate yet. The function can be changed to barf if there are
unmatching pathspec given by the user, but that is not strictly
necessary.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This is to use a few functions refactored to use in the built-in
commit series.
* kh/commit: (28 commits)
Add a few more tests for git-commit
builtin-commit: Include the diff in the commit message when verbose.
builtin-commit: fix partial-commit support
Fix add_files_to_cache() to take pathspec, not user specified list of files
Export three helper functions from ls-files
builtin-commit: run commit-msg hook with correct message file
builtin-commit: do not color status output shown in the message template
file_exists(): dangling symlinks do exist
Replace "runstatus" with "status" in the tests
t7501-commit: Add test for git commit <file> with dirty index.
builtin-commit: Clean up an unused variable and a debug fprintf().
Call refresh_cache() when updating the user index for --only commits.
builtin-commit: Add newline when showing which commit was created
builtin-commit: resurrect behavior for multiple -m options
builtin-commit --s: add a newline if the last line was not a S-o-b
builtin-commit: fix --signoff
git status: show relative paths when run in a subdirectory
builtin-commit: Refresh cache after adding files.
builtin-commit: fix reflog message generation
launch_editor(): read the file, even when EDITOR=:
...
run_diff_index() and the entire diff machinery is hard coded to output
to stdout, so just redirect that and restore it when done.
Signed-off-by: Kristian Høgsberg <krh@redhat.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
When making a partial-commit, we need to prepare two index
files, one to be used to write out the tree to be committed
(temporary index) and the other to be used as the index file
after the commit is made.
The temporary index needs to be initialized to HEAD and then all
the named paths on the command line need to be staged on top of
the index. For this, running add_files_to_cache() that compares
what is in the index and the paths given from the command line
is not enough -- the comparison will miss the paths that the
user previously ran "git add" to the index since the HEAD
because the index reset to the HEAD would not know about them.
The index file needs to get the same modification done when
preparing the temporary index as described above.
This implementation mimics the behaviour of the scripted
version of git-commit. It first runs overlay_tree_on_cache(),
which was stolen from ls-files with the earlier change, to get
the list of paths that the user can potentially mean, and then
uses pathspec_match() to find which ones the user meant. This
list of paths is used to update both the temporary and the real
index file.
Additional fixes are:
- read the index file after pre-commit hook returns, as the
hook can modify it to affect the contents of the commit.
- remove the temporary index file .git/next-index-* after
commit is done or aborted.
- run post-commit hook with the real index file to be used
after the commit (previously it gave the temporary commit if
a partial commit was made).
- resurrect the safety mechanism to refuse partial commits
during a merge to match the scripted version.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
We're guaranteeing the user that the index will be stat-clean after
git commit. Thus, we need to call refresh_cache() for the user index too,
in the 'git commit <paths>' case.
Signed-off-by: Kristian Høgsberg <krh@redhat.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
The function log_tree_commit() does not break the line, so we have to
do it ourselves.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
When more than one -m option is given, the message does not replace
the previous, but is appended as a new paragraph.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
The rule is this: if the last line already contains the sign off by the
current committer, do nothing. If it contains another sign off, just
add the sign off of the current committer. If the last line does not
contain a sign off, add a new line before adding the sign off.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
The Signed-off-by: line contained a spurious timestamp. The reason was
a call to git_committer_info(1), which automatically added the
timestamp.
Instead, fmt_ident() was taught to interpret an empty string for the
date (as opposed to NULL, which still triggers the default behavior)
as "do not bother with the timestamp", and builtin-commit.c uses it.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
To show the relative paths, the function formerly called quote_crlf()
(now called quote_path()) takes the prefix as an additional argument.
While at it, the static buffers were replaced by strbufs.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
We have promised our users that after running git-status or
git-commit the index will be refreshed for a long time since
these commands were introduced. Do refresh the index before
writing it out to keep the promise.
Signed-off-by: Kristian Høgsberg <krh@redhat.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Instead of strdup()ing, we can just reuse the buffer in which the
commit message is stored, and which is supposed to hold the reflog
message anyway.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This makes git commit a builtin and moves git-commit.sh to
contrib/examples. This also removes the git-runstatus
helper, which was mostly just a git-status.sh implementation detail.
Signed-off-by: Kristian Høgsberg <krh@redhat.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>