aboutsummaryrefslogtreecommitdiff
path: root/builtin-commit.c
Commit message (Collapse)AuthorAge
* Improve use of lockfile APIBrandon Casey2008-01-16
| | | | | | | Remove remaining double close(2)'s. i.e. close() before commit_locked_index() or commit_lock_file(). Signed-off-by: Junio C Hamano <gitster@pobox.com>
* Make builtin-commit.c more careful about parenthoodLinus Torvalds2008-01-16
| | | | | | | | | | When creating the commit object, be a whole lot more careful about making sure that the parent lines really are valid parent lines. Check things like MERGE_HEAD having proper SHA1 lines in it, and double-check that all the parents exist and are actually commits. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* git-commit: fix double close(2) that can close a wrong file descriptorKristian Høgsberg2008-01-15
| | | | | | | | | | | | | | | | | | | | | | The codepath to prepare index files for the temporary and next index file was closing file descriptor it obtained from the lockfile API by hand, without letting the API know that the fd should not be doubly closed. This is not usually a problem (except it may get EBADFD) but if we opened another fd for an entirely unrelated purpose (say, an fd used to mmap a packfile) between the time we close the fd to the index file and the time we commit or rollback the lockfile (causing it to also try closing the recorded fd), the lockfile API will close an incorrect file descriptor that is still used for an entirely unrelated purpose. There's four close(fd) calls in prepare_index() and they're all incorrect. The open fd's are cleaned up in rollback_index_files() and shouldn't be closed manually. The patch below gets rid of the extra close() calls and should fix the problem. Signed-off-by: Junio C Hamano <gitster@pobox.com>
* Revert "builtin-commit.c: remove useless check added by faulty cut and paste"Junio C Hamano2008-01-14
| | | | | | | | | | | | | | This reverts commit 16335fdd7ace78a8285ba25fd7a81177a48e7c9b. We are calling overlay_tree_on_cache() which does use CE_UPDATE flag to mark duplicated entries, which is the same as the codepath in git-ls-files with its --with-tree option. Because the pathname ce->name is given to path_list_insert() which does not allow duplicates, there is no breakage either way from the correctness point of view in this codepath, unlike the one in ls-files. But avoiding unnecessary processing with a single bit check is certainly better.
* builtin-commit.c: remove useless check added by faulty cut and pasteJunio C Hamano2008-01-13
| | | | | | | | | | | | 2888605c649ccd423232161186d72c0e6c458a48 (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>
* Fix performance regression for partial commitsLinus Torvalds2008-01-13
| | | | | | | | | | | | | 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>
* Allow selection of different cleanup modes for commit messagesAlex Riesen2007-12-22
| | | | | | | | | | | | | | | | | | | 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>
* builtin-commit: avoid double-negation in the code.Junio C Hamano2007-12-22
| | | | | | | | | 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>
* builtin-commit: fix amending of the initial commitJunio C Hamano2007-12-22
| | | | | | | | 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>
* fix git commit --amend -m "new message"Junio C Hamano2007-12-20
| | | | | | | | | | | | | | | | | | | 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; 7168624c3530d8c7ee32f930f8fb2ba302b9801f (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>
* builtin-commit: make summary output consistent with statusJunio C Hamano2007-12-16
| | | | | | | 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>
* builtin-commit: fix summary output.Junio C Hamano2007-12-16
| | | | | | | | 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>
* commit: allow --amend to reuse message from another commitJunio C Hamano2007-12-14
| | | | | | | | | | | | | | | | | 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>
* git-commit: squelch needless message during an empty mergeJunio C Hamano2007-12-12
| | | | | | | | | | | | | | | | | | | | | | | 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>
* commit: do not add extra LF at the end of the summary.Junio C Hamano2007-12-11
| | | | | | | | 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>
* Re-fix "builtin-commit: fix --signoff"Junio C Hamano2007-12-09
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* Fix commit-msg hook to allow editingJunio C Hamano2007-12-09
| | | | | | | | | | | 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>
* Allow --no-verify to bypass commit-msg hookWincent Colaiuta2007-12-09
| | | | | | | | | | 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>
* add status.relativePaths config variableJeff King2007-12-08
| | | | | | | | | 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>
* Merge branch 'wc/add-i'Junio C Hamano2007-12-04
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | * 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
| * add -i: Fix running from a subdirectoryJunio C Hamano2007-11-25
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
| * Merge branch 'kh/commit' into wc/add-iJunio C Hamano2007-11-25
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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=: ...
* | git-commit --allow-emptyJunio C Hamano2007-12-03
| | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* | git-commit: Allow to amend a merge commit that does not change the treeJunio C Hamano2007-12-02
| | | | | | | | | | | | | | | | | | 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>
* | Make git status usage say git status instead of git commitShawn Bohrer2007-12-02
| | | | | | | | | | | | | | | | | | | | 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>
* | Fix --signoff in builtin-commit differently.Junio C Hamano2007-12-02
| | | | | | | | | | | | | | | | | | | | Introduce fmt_name() specifically meant for formatting the name and email pair, to add signed-off-by value. This reverts parts of 13208572fbe8838fd8835548d7502202d1f7b21d (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>
* | git-commit: clean up die messagesJeff King2007-12-01
| | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* | Do not generate full commit log message if it is not going to be usedAlex Riesen2007-11-28
| | | | | | | | | | | | | | 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>
* | Fix off-by-one error when truncating the diff out of the commit message.Kristian Høgsberg2007-11-26
| | | | | | | | | | Signed-off-by: Kristian Høgsberg <krh@redhat.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* | builtin-commit.c: export GIT_INDEX_FILE for launch_editor as well.Pierre Habouzit2007-11-26
|/ | | | | | | | | | 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>
* builtin-commit: Include the diff in the commit message when verbose.Kristian Høgsberg2007-11-22
| | | | | | | | 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>
* builtin-commit: fix partial-commit supportJunio C Hamano2007-11-22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* builtin-commit: run commit-msg hook with correct message fileJunio C Hamano2007-11-22
| | | | | | It should run with $GIT_DIR/COMMIT_EDITMSG, not just COMMIT_EDITMSG. Signed-off-by: Junio C Hamano <gitster@pobox.com>
* builtin-commit: do not color status output shown in the message templateJunio C Hamano2007-11-22
| | | | | | Noticed by Ping Yin on the list. Signed-off-by: Junio C Hamano <gitster@pobox.com>
* builtin-commit: Clean up an unused variable and a debug fprintf().Kristian Høgsberg2007-11-22
| | | | | Signed-off-by: Kristian Høgsberg <krh@redhat.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* Call refresh_cache() when updating the user index for --only commits.Kristian Høgsberg2007-11-22
| | | | | | | | | 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>
* builtin-commit: Add newline when showing which commit was createdJohannes Schindelin2007-11-22
| | | | | | | | 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>
* builtin-commit: resurrect behavior for multiple -m optionsJohannes Schindelin2007-11-22
| | | | | | | | 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>
* builtin-commit --s: add a newline if the last line was not a S-o-bJohannes Schindelin2007-11-22
| | | | | | | | | | 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>
* builtin-commit: fix --signoffJohannes Schindelin2007-11-22
| | | | | | | | | | | | | 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>
* git status: show relative paths when run in a subdirectoryJohannes Schindelin2007-11-22
| | | | | | | | | | 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>
* builtin-commit: Refresh cache after adding files.Kristian Høgsberg2007-11-22
| | | | | | | | | | 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>
* builtin-commit: fix reflog message generationJohannes Schindelin2007-11-22
| | | | | | | | | 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>
* Port git commit to C.Kristian Høgsberg2007-11-22
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>