2007-11-08 16:59:00 +00:00
|
|
|
/*
|
|
|
|
* Builtin "git commit"
|
|
|
|
*
|
|
|
|
* Copyright (c) 2007 Kristian Høgsberg <krh@redhat.com>
|
|
|
|
* Based on git-commit.sh by Junio C Hamano and Linus Torvalds
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "cache.h"
|
2014-10-01 10:28:42 +00:00
|
|
|
#include "lockfile.h"
|
2007-11-08 16:59:00 +00:00
|
|
|
#include "cache-tree.h"
|
2008-02-18 07:26:03 +00:00
|
|
|
#include "color.h"
|
2007-11-18 09:52:55 +00:00
|
|
|
#include "dir.h"
|
2007-11-08 16:59:00 +00:00
|
|
|
#include "builtin.h"
|
|
|
|
#include "diff.h"
|
|
|
|
#include "diffcore.h"
|
|
|
|
#include "commit.h"
|
|
|
|
#include "revision.h"
|
|
|
|
#include "wt-status.h"
|
|
|
|
#include "run-command.h"
|
|
|
|
#include "refs.h"
|
|
|
|
#include "log-tree.h"
|
|
|
|
#include "strbuf.h"
|
|
|
|
#include "utf8.h"
|
|
|
|
#include "parse-options.h"
|
2008-07-21 18:03:49 +00:00
|
|
|
#include "string-list.h"
|
2008-07-09 12:58:57 +00:00
|
|
|
#include "rerere.h"
|
2008-01-13 08:30:56 +00:00
|
|
|
#include "unpack-trees.h"
|
2009-08-08 06:31:57 +00:00
|
|
|
#include "quote.h"
|
2010-08-05 22:40:48 +00:00
|
|
|
#include "submodule.h"
|
commit: teach --gpg-sign option
This uses the gpg-interface.[ch] to allow signing the commit, i.e.
$ git commit --gpg-sign -m foo
You need a passphrase to unlock the secret key for
user: "Junio C Hamano <gitster@pobox.com>"
4096-bit RSA key, ID 96AFE6CB, created 2011-10-03 (main key ID 713660A7)
[master 8457d13] foo
1 files changed, 1 insertions(+), 0 deletions(-)
The lines of GPG detached signature are placed in a new multi-line header
field, instead of tucking the signature block at the end of the commit log
message text (similar to how signed tag is done), for multiple reasons:
- The signature won't clutter output from "git log" and friends if it is
in the extra header. If we place it at the end of the log message, we
would need to teach "git log" and friends to strip the signature block
with an option.
- Teaching new versions of "git log" and "gitk" to optionally verify and
show signatures is cleaner if we structurally know where the signature
block is (instead of scanning in the commit log message).
- The signature needs to be stripped upon various commit rewriting
operations, e.g. rebase, filter-branch, etc. They all already ignore
unknown headers, but if we place signature in the log message, all of
these tools (and third-party tools) also need to learn how a signature
block would look like.
- When we added the optional encoding header, all the tools (both in tree
and third-party) that acts on the raw commit object should have been
fixed to ignore headers they do not understand, so it is not like that
new header would be more likely to break than extra text in the commit.
A commit made with the above sample sequence would look like this:
$ git cat-file commit HEAD
tree 3cd71d90e3db4136e5260ab54599791c4f883b9d
parent b87755351a47b09cb27d6913e6e0e17e6254a4d4
author Junio C Hamano <gitster@pobox.com> 1317862251 -0700
committer Junio C Hamano <gitster@pobox.com> 1317862251 -0700
gpgsig -----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
iQIcBAABAgAGBQJOjPtrAAoJELC16IaWr+bL4TMP/RSe2Y/jYnCkds9unO5JEnfG
...
=dt98
-----END PGP SIGNATURE-----
foo
but "git log" (unless you ask for it with --pretty=raw) output is not
cluttered with the signature information.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-10-06 00:23:20 +00:00
|
|
|
#include "gpg-interface.h"
|
2012-04-13 10:54:39 +00:00
|
|
|
#include "column.h"
|
2012-09-14 06:52:03 +00:00
|
|
|
#include "sequencer.h"
|
2013-06-12 00:13:00 +00:00
|
|
|
#include "notes-utils.h"
|
2013-08-23 13:48:31 +00:00
|
|
|
#include "mailmap.h"
|
2015-11-16 08:05:58 +00:00
|
|
|
#include "sigchain.h"
|
2007-11-08 16:59:00 +00:00
|
|
|
|
|
|
|
static const char * const builtin_commit_usage[] = {
|
2015-01-13 07:44:47 +00:00
|
|
|
N_("git commit [<options>] [--] <pathspec>..."),
|
2007-11-08 16:59:00 +00:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2007-12-03 05:02:09 +00:00
|
|
|
static const char * const builtin_status_usage[] = {
|
2015-01-13 07:44:47 +00:00
|
|
|
N_("git status [<options>] [--] <pathspec>..."),
|
2007-12-03 05:02:09 +00:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2014-07-25 19:11:36 +00:00
|
|
|
static const char implicit_ident_advice_noconfig[] =
|
|
|
|
N_("Your name and email address were configured automatically based\n"
|
|
|
|
"on your username and hostname. Please check that they are accurate.\n"
|
|
|
|
"You can suppress this message by setting them explicitly. Run the\n"
|
|
|
|
"following command and follow the instructions in your editor to edit\n"
|
|
|
|
"your configuration file:\n"
|
|
|
|
"\n"
|
|
|
|
" git config --global --edit\n"
|
|
|
|
"\n"
|
|
|
|
"After doing this, you may fix the identity used for this commit with:\n"
|
|
|
|
"\n"
|
|
|
|
" git commit --amend --reset-author\n");
|
|
|
|
|
|
|
|
static const char implicit_ident_advice_config[] =
|
2011-02-22 23:41:49 +00:00
|
|
|
N_("Your name and email address were configured automatically based\n"
|
commit: show interesting ident information in summary
There are a few cases of user identity information that we consider
interesting:
(1) When the author and committer identities do not match.
(2) When the committer identity was picked automatically from the
username, hostname and GECOS information.
In these cases, we already show the information in the commit
message template. However, users do not always see that template
because they might use "-m" or "-F". With this patch, we show these
interesting cases after the commit, along with the subject and
change summary. The new output looks like:
$ git commit \
-m "federalist papers" \
--author='Publius <alexander@hamilton.com>'
[master 3d226a7] federalist papers
Author: Publius <alexander@hamilton.com>
1 files changed, 1 insertions(+), 0 deletions(-)
for case (1), and:
$ git config --global --unset user.name
$ git config --global --unset user.email
$ git commit -m foo
[master 7c2a927] foo
Committer: Jeff King <peff@c-71-185-130-222.hsd1.va.comcast.net>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly:
git config --global user.name Your Name
git config --global user.email you@example.com
If the identity used for this commit is wrong, you can fix it with:
git commit --amend --author='Your Name <you@example.com>'
1 files changed, 1 insertions(+), 0 deletions(-)
for case (2).
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-01-13 17:39:51 +00:00
|
|
|
"on your username and hostname. Please check that they are accurate.\n"
|
|
|
|
"You can suppress this message by setting them explicitly:\n"
|
|
|
|
"\n"
|
2010-02-24 14:18:25 +00:00
|
|
|
" git config --global user.name \"Your Name\"\n"
|
commit: show interesting ident information in summary
There are a few cases of user identity information that we consider
interesting:
(1) When the author and committer identities do not match.
(2) When the committer identity was picked automatically from the
username, hostname and GECOS information.
In these cases, we already show the information in the commit
message template. However, users do not always see that template
because they might use "-m" or "-F". With this patch, we show these
interesting cases after the commit, along with the subject and
change summary. The new output looks like:
$ git commit \
-m "federalist papers" \
--author='Publius <alexander@hamilton.com>'
[master 3d226a7] federalist papers
Author: Publius <alexander@hamilton.com>
1 files changed, 1 insertions(+), 0 deletions(-)
for case (1), and:
$ git config --global --unset user.name
$ git config --global --unset user.email
$ git commit -m foo
[master 7c2a927] foo
Committer: Jeff King <peff@c-71-185-130-222.hsd1.va.comcast.net>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly:
git config --global user.name Your Name
git config --global user.email you@example.com
If the identity used for this commit is wrong, you can fix it with:
git commit --amend --author='Your Name <you@example.com>'
1 files changed, 1 insertions(+), 0 deletions(-)
for case (2).
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-01-13 17:39:51 +00:00
|
|
|
" git config --global user.email you@example.com\n"
|
|
|
|
"\n"
|
2011-01-12 18:29:14 +00:00
|
|
|
"After doing this, you may fix the identity used for this commit with:\n"
|
commit: show interesting ident information in summary
There are a few cases of user identity information that we consider
interesting:
(1) When the author and committer identities do not match.
(2) When the committer identity was picked automatically from the
username, hostname and GECOS information.
In these cases, we already show the information in the commit
message template. However, users do not always see that template
because they might use "-m" or "-F". With this patch, we show these
interesting cases after the commit, along with the subject and
change summary. The new output looks like:
$ git commit \
-m "federalist papers" \
--author='Publius <alexander@hamilton.com>'
[master 3d226a7] federalist papers
Author: Publius <alexander@hamilton.com>
1 files changed, 1 insertions(+), 0 deletions(-)
for case (1), and:
$ git config --global --unset user.name
$ git config --global --unset user.email
$ git commit -m foo
[master 7c2a927] foo
Committer: Jeff King <peff@c-71-185-130-222.hsd1.va.comcast.net>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly:
git config --global user.name Your Name
git config --global user.email you@example.com
If the identity used for this commit is wrong, you can fix it with:
git commit --amend --author='Your Name <you@example.com>'
1 files changed, 1 insertions(+), 0 deletions(-)
for case (2).
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-01-13 17:39:51 +00:00
|
|
|
"\n"
|
2011-02-22 23:41:49 +00:00
|
|
|
" git commit --amend --reset-author\n");
|
commit: show interesting ident information in summary
There are a few cases of user identity information that we consider
interesting:
(1) When the author and committer identities do not match.
(2) When the committer identity was picked automatically from the
username, hostname and GECOS information.
In these cases, we already show the information in the commit
message template. However, users do not always see that template
because they might use "-m" or "-F". With this patch, we show these
interesting cases after the commit, along with the subject and
change summary. The new output looks like:
$ git commit \
-m "federalist papers" \
--author='Publius <alexander@hamilton.com>'
[master 3d226a7] federalist papers
Author: Publius <alexander@hamilton.com>
1 files changed, 1 insertions(+), 0 deletions(-)
for case (1), and:
$ git config --global --unset user.name
$ git config --global --unset user.email
$ git commit -m foo
[master 7c2a927] foo
Committer: Jeff King <peff@c-71-185-130-222.hsd1.va.comcast.net>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly:
git config --global user.name Your Name
git config --global user.email you@example.com
If the identity used for this commit is wrong, you can fix it with:
git commit --amend --author='Your Name <you@example.com>'
1 files changed, 1 insertions(+), 0 deletions(-)
for case (2).
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-01-13 17:39:51 +00:00
|
|
|
|
2010-06-07 00:41:46 +00:00
|
|
|
static const char empty_amend_advice[] =
|
2011-02-22 23:41:49 +00:00
|
|
|
N_("You asked to amend the most recent commit, but doing so would make\n"
|
2010-06-07 00:41:46 +00:00
|
|
|
"it empty. You can repeat your command with --allow-empty, or you can\n"
|
2011-02-22 23:41:49 +00:00
|
|
|
"remove the commit entirely with \"git reset HEAD^\".\n");
|
2010-06-07 00:41:46 +00:00
|
|
|
|
2011-02-20 04:12:29 +00:00
|
|
|
static const char empty_cherry_pick_advice[] =
|
2011-04-02 00:55:55 +00:00
|
|
|
N_("The previous cherry-pick is now empty, possibly due to conflict resolution.\n"
|
2011-02-20 04:12:29 +00:00
|
|
|
"If you wish to commit it anyway, use:\n"
|
|
|
|
"\n"
|
|
|
|
" git commit --allow-empty\n"
|
commit: tweak empty cherry pick advice for sequencer
When we refuse to make an empty commit, we check whether we
are in a cherry-pick in order to give better advice on how
to proceed. We instruct the user to repeat the commit with
"--allow-empty" to force the commit, or to use "git reset"
to skip it and abort the cherry-pick.
In the case of a single cherry-pick, the distinction between
skipping and aborting is not important, as there is no more
work to be done afterwards. When we are using the sequencer
to cherry pick a series of commits, though, the instruction
is confusing: does it skip this commit, or does it abort the
rest of the cherry-pick?
It does skip, after which the user can continue the
cherry-pick. This is the right thing to be advising the user
to do, but let's make it more clear what will happen, both
by using the word "skip", and by mentioning that the rest of
the sequence can be continued via "cherry-pick --continue"
(whether we skip or take the commit).
Noticed-by: Ramkumar Ramachandra <artagnon@gmail.com>
Helped-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-07-26 23:39:28 +00:00
|
|
|
"\n");
|
|
|
|
|
|
|
|
static const char empty_cherry_pick_advice_single[] =
|
|
|
|
N_("Otherwise, please use 'git reset'\n");
|
|
|
|
|
|
|
|
static const char empty_cherry_pick_advice_multi[] =
|
|
|
|
N_("If you wish to skip this commit, use:\n"
|
2011-02-20 04:12:29 +00:00
|
|
|
"\n"
|
commit: tweak empty cherry pick advice for sequencer
When we refuse to make an empty commit, we check whether we
are in a cherry-pick in order to give better advice on how
to proceed. We instruct the user to repeat the commit with
"--allow-empty" to force the commit, or to use "git reset"
to skip it and abort the cherry-pick.
In the case of a single cherry-pick, the distinction between
skipping and aborting is not important, as there is no more
work to be done afterwards. When we are using the sequencer
to cherry pick a series of commits, though, the instruction
is confusing: does it skip this commit, or does it abort the
rest of the cherry-pick?
It does skip, after which the user can continue the
cherry-pick. This is the right thing to be advising the user
to do, but let's make it more clear what will happen, both
by using the word "skip", and by mentioning that the rest of
the sequence can be continued via "cherry-pick --continue"
(whether we skip or take the commit).
Noticed-by: Ramkumar Ramachandra <artagnon@gmail.com>
Helped-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-07-26 23:39:28 +00:00
|
|
|
" git reset\n"
|
|
|
|
"\n"
|
|
|
|
"Then \"git cherry-pick --continue\" will resume cherry-picking\n"
|
|
|
|
"the remaining commits.\n");
|
2011-02-20 04:12:29 +00:00
|
|
|
|
2016-05-24 19:19:50 +00:00
|
|
|
static GIT_PATH_FUNC(git_path_commit_editmsg, "COMMIT_EDITMSG")
|
|
|
|
|
2011-02-20 04:12:29 +00:00
|
|
|
static const char *use_message_buffer;
|
2007-11-18 09:52:55 +00:00
|
|
|
static struct lock_file index_lock; /* real index */
|
|
|
|
static struct lock_file false_lock; /* used only for partial commits */
|
|
|
|
static enum {
|
|
|
|
COMMIT_AS_IS = 1,
|
|
|
|
COMMIT_NORMAL,
|
2010-05-14 09:31:35 +00:00
|
|
|
COMMIT_PARTIAL
|
2007-11-18 09:52:55 +00:00
|
|
|
} commit_style;
|
2007-11-08 16:59:00 +00:00
|
|
|
|
2008-08-06 18:43:47 +00:00
|
|
|
static const char *logfile, *force_author;
|
2008-07-05 05:24:40 +00:00
|
|
|
static const char *template_file;
|
2011-02-20 04:12:29 +00:00
|
|
|
/*
|
|
|
|
* The _message variables are commit names from which to take
|
|
|
|
* the commit message and/or authorship.
|
|
|
|
*/
|
|
|
|
static const char *author_message, *author_message_buffer;
|
2007-11-08 16:59:00 +00:00
|
|
|
static char *edit_message, *use_message;
|
2010-11-02 19:59:11 +00:00
|
|
|
static char *fixup_message, *squash_message;
|
2011-12-06 21:09:55 +00:00
|
|
|
static int all, also, interactive, patch_interactive, only, amend, signoff;
|
|
|
|
static int edit_flag = -1; /* unspecified */
|
2009-11-04 03:20:11 +00:00
|
|
|
static int quiet, verbose, no_verify, allow_empty, dry_run, renew_authorship;
|
2016-05-05 09:50:02 +00:00
|
|
|
static int config_commit_verbose = -1; /* unspecified */
|
2010-04-06 08:40:35 +00:00
|
|
|
static int no_post_rewrite, allow_empty_message;
|
2010-06-25 14:56:47 +00:00
|
|
|
static char *untracked_files_arg, *force_date, *ignore_submodule_arg;
|
commit: teach --gpg-sign option
This uses the gpg-interface.[ch] to allow signing the commit, i.e.
$ git commit --gpg-sign -m foo
You need a passphrase to unlock the secret key for
user: "Junio C Hamano <gitster@pobox.com>"
4096-bit RSA key, ID 96AFE6CB, created 2011-10-03 (main key ID 713660A7)
[master 8457d13] foo
1 files changed, 1 insertions(+), 0 deletions(-)
The lines of GPG detached signature are placed in a new multi-line header
field, instead of tucking the signature block at the end of the commit log
message text (similar to how signed tag is done), for multiple reasons:
- The signature won't clutter output from "git log" and friends if it is
in the extra header. If we place it at the end of the log message, we
would need to teach "git log" and friends to strip the signature block
with an option.
- Teaching new versions of "git log" and "gitk" to optionally verify and
show signatures is cleaner if we structurally know where the signature
block is (instead of scanning in the commit log message).
- The signature needs to be stripped upon various commit rewriting
operations, e.g. rebase, filter-branch, etc. They all already ignore
unknown headers, but if we place signature in the log message, all of
these tools (and third-party tools) also need to learn how a signature
block would look like.
- When we added the optional encoding header, all the tools (both in tree
and third-party) that acts on the raw commit object should have been
fixed to ignore headers they do not understand, so it is not like that
new header would be more likely to break than extra text in the commit.
A commit made with the above sample sequence would look like this:
$ git cat-file commit HEAD
tree 3cd71d90e3db4136e5260ab54599791c4f883b9d
parent b87755351a47b09cb27d6913e6e0e17e6254a4d4
author Junio C Hamano <gitster@pobox.com> 1317862251 -0700
committer Junio C Hamano <gitster@pobox.com> 1317862251 -0700
gpgsig -----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
iQIcBAABAgAGBQJOjPtrAAoJELC16IaWr+bL4TMP/RSe2Y/jYnCkds9unO5JEnfG
...
=dt98
-----END PGP SIGNATURE-----
foo
but "git log" (unless you ask for it with --pretty=raw) output is not
cluttered with the signature information.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-10-06 00:23:20 +00:00
|
|
|
static char *sign_commit;
|
|
|
|
|
2007-12-22 18:46:24 +00:00
|
|
|
/*
|
|
|
|
* The default commit message cleanup mode will remove the lines
|
|
|
|
* beginning with # (shell comments) and leading and trailing
|
|
|
|
* whitespaces (empty lines or containing only whitespaces)
|
|
|
|
* if editor is used, and only the whitespaces if the message
|
|
|
|
* is specified explicitly.
|
|
|
|
*/
|
|
|
|
static enum {
|
|
|
|
CLEANUP_SPACE,
|
|
|
|
CLEANUP_NONE,
|
2014-02-17 12:15:32 +00:00
|
|
|
CLEANUP_SCISSORS,
|
2010-05-14 09:31:35 +00:00
|
|
|
CLEANUP_ALL
|
2007-12-22 18:46:24 +00:00
|
|
|
} cleanup_mode;
|
2013-01-10 17:45:59 +00:00
|
|
|
static const char *cleanup_arg;
|
2007-11-08 16:59:00 +00:00
|
|
|
|
2011-02-20 04:12:29 +00:00
|
|
|
static enum commit_whence whence;
|
commit: tweak empty cherry pick advice for sequencer
When we refuse to make an empty commit, we check whether we
are in a cherry-pick in order to give better advice on how
to proceed. We instruct the user to repeat the commit with
"--allow-empty" to force the commit, or to use "git reset"
to skip it and abort the cherry-pick.
In the case of a single cherry-pick, the distinction between
skipping and aborting is not important, as there is no more
work to be done afterwards. When we are using the sequencer
to cherry pick a series of commits, though, the instruction
is confusing: does it skip this commit, or does it abort the
rest of the cherry-pick?
It does skip, after which the user can continue the
cherry-pick. This is the right thing to be advising the user
to do, but let's make it more clear what will happen, both
by using the word "skip", and by mentioning that the rest of
the sequence can be continued via "cherry-pick --continue"
(whether we skip or take the commit).
Noticed-by: Ramkumar Ramachandra <artagnon@gmail.com>
Helped-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-07-26 23:39:28 +00:00
|
|
|
static int sequencer_in_use;
|
2011-08-19 18:58:18 +00:00
|
|
|
static int use_editor = 1, include_status = 1;
|
2013-05-25 21:43:34 +00:00
|
|
|
static int show_ignored_in_status, have_option_m;
|
2008-07-22 20:40:41 +00:00
|
|
|
static const char *only_include_assumed;
|
2011-12-18 05:03:22 +00:00
|
|
|
static struct strbuf message = STRBUF_INIT;
|
2007-11-11 17:36:39 +00:00
|
|
|
|
2016-08-05 22:00:27 +00:00
|
|
|
static enum wt_status_format status_format = STATUS_FORMAT_UNSPECIFIED;
|
2013-06-24 18:41:40 +00:00
|
|
|
|
2016-08-05 22:00:28 +00:00
|
|
|
static int opt_parse_porcelain(const struct option *opt, const char *arg, int unset)
|
|
|
|
{
|
|
|
|
enum wt_status_format *value = (enum wt_status_format *)opt->value;
|
|
|
|
if (unset)
|
|
|
|
*value = STATUS_FORMAT_NONE;
|
|
|
|
else if (!arg)
|
|
|
|
*value = STATUS_FORMAT_PORCELAIN;
|
|
|
|
else if (!strcmp(arg, "v1") || !strcmp(arg, "1"))
|
|
|
|
*value = STATUS_FORMAT_PORCELAIN;
|
2016-08-11 14:45:57 +00:00
|
|
|
else if (!strcmp(arg, "v2") || !strcmp(arg, "2"))
|
|
|
|
*value = STATUS_FORMAT_PORCELAIN_V2;
|
2016-08-05 22:00:28 +00:00
|
|
|
else
|
|
|
|
die("unsupported porcelain version '%s'", arg);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2009-09-05 08:59:56 +00:00
|
|
|
|
2007-11-11 17:36:39 +00:00
|
|
|
static int opt_parse_m(const struct option *opt, const char *arg, int unset)
|
|
|
|
{
|
|
|
|
struct strbuf *buf = opt->value;
|
2013-05-25 21:43:34 +00:00
|
|
|
if (unset) {
|
|
|
|
have_option_m = 0;
|
2007-11-11 17:36:39 +00:00
|
|
|
strbuf_setlen(buf, 0);
|
2013-05-25 21:43:34 +00:00
|
|
|
} else {
|
|
|
|
have_option_m = 1;
|
2013-02-19 04:17:06 +00:00
|
|
|
if (buf->len)
|
|
|
|
strbuf_addch(buf, '\n');
|
2007-11-11 17:36:39 +00:00
|
|
|
strbuf_addstr(buf, arg);
|
2013-02-19 04:17:06 +00:00
|
|
|
strbuf_complete_line(buf);
|
2007-11-11 17:36:39 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2007-11-08 16:59:00 +00:00
|
|
|
|
2011-02-20 04:12:29 +00:00
|
|
|
static void determine_whence(struct wt_status *s)
|
|
|
|
{
|
memoize common git-path "constant" files
One of the most common uses of git_path() is to pass a
constant, like git_path("MERGE_MSG"). This has two
drawbacks:
1. The return value is a static buffer, and the lifetime
is dependent on other calls to git_path, etc.
2. There's no compile-time checking of the pathname. This
is OK for a one-off (after all, we have to spell it
correctly at least once), but many of these constant
strings appear throughout the code.
This patch introduces a series of functions to "memoize"
these strings, which are essentially globals for the
lifetime of the program. We compute the value once, take
ownership of the buffer, and return the cached value for
subsequent calls. cache.h provides a helper macro for
defining these functions as one-liners, and defines a few
common ones for global use.
Using a macro is a little bit gross, but it does nicely
document the purpose of the functions. If we need to touch
them all later (e.g., because we learned how to change the
git_dir variable at runtime, and need to invalidate all of
the stored values), it will be much easier to have the
complete list.
Note that the shared-global functions have separate, manual
declarations. We could do something clever with the macros
(e.g., expand it to a declaration in some places, and a
declaration _and_ a definition in path.c). But there aren't
that many, and it's probably better to stay away from
too-magical macros.
Likewise, if we abandon the C preprocessor in favor of
generating these with a script, we could get much fancier.
E.g., normalizing "FOO/BAR-BAZ" into "git_path_foo_bar_baz".
But the small amount of saved typing is probably not worth
the resulting confusion to readers who want to grep for the
function's definition.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-08-10 09:38:57 +00:00
|
|
|
if (file_exists(git_path_merge_head()))
|
2011-02-20 04:12:29 +00:00
|
|
|
whence = FROM_MERGE;
|
memoize common git-path "constant" files
One of the most common uses of git_path() is to pass a
constant, like git_path("MERGE_MSG"). This has two
drawbacks:
1. The return value is a static buffer, and the lifetime
is dependent on other calls to git_path, etc.
2. There's no compile-time checking of the pathname. This
is OK for a one-off (after all, we have to spell it
correctly at least once), but many of these constant
strings appear throughout the code.
This patch introduces a series of functions to "memoize"
these strings, which are essentially globals for the
lifetime of the program. We compute the value once, take
ownership of the buffer, and return the cached value for
subsequent calls. cache.h provides a helper macro for
defining these functions as one-liners, and defines a few
common ones for global use.
Using a macro is a little bit gross, but it does nicely
document the purpose of the functions. If we need to touch
them all later (e.g., because we learned how to change the
git_dir variable at runtime, and need to invalidate all of
the stored values), it will be much easier to have the
complete list.
Note that the shared-global functions have separate, manual
declarations. We could do something clever with the macros
(e.g., expand it to a declaration in some places, and a
declaration _and_ a definition in path.c). But there aren't
that many, and it's probably better to stay away from
too-magical macros.
Likewise, if we abandon the C preprocessor in favor of
generating these with a script, we could get much fancier.
E.g., normalizing "FOO/BAR-BAZ" into "git_path_foo_bar_baz".
But the small amount of saved typing is probably not worth
the resulting confusion to readers who want to grep for the
function's definition.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-08-10 09:38:57 +00:00
|
|
|
else if (file_exists(git_path_cherry_pick_head())) {
|
2011-02-20 04:12:29 +00:00
|
|
|
whence = FROM_CHERRY_PICK;
|
2016-10-14 13:17:12 +00:00
|
|
|
if (file_exists(git_path_seq_dir()))
|
commit: tweak empty cherry pick advice for sequencer
When we refuse to make an empty commit, we check whether we
are in a cherry-pick in order to give better advice on how
to proceed. We instruct the user to repeat the commit with
"--allow-empty" to force the commit, or to use "git reset"
to skip it and abort the cherry-pick.
In the case of a single cherry-pick, the distinction between
skipping and aborting is not important, as there is no more
work to be done afterwards. When we are using the sequencer
to cherry pick a series of commits, though, the instruction
is confusing: does it skip this commit, or does it abort the
rest of the cherry-pick?
It does skip, after which the user can continue the
cherry-pick. This is the right thing to be advising the user
to do, but let's make it more clear what will happen, both
by using the word "skip", and by mentioning that the rest of
the sequence can be continued via "cherry-pick --continue"
(whether we skip or take the commit).
Noticed-by: Ramkumar Ramachandra <artagnon@gmail.com>
Helped-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-07-26 23:39:28 +00:00
|
|
|
sequencer_in_use = 1;
|
|
|
|
}
|
2011-02-20 04:12:29 +00:00
|
|
|
else
|
|
|
|
whence = FROM_COMMIT;
|
|
|
|
if (s)
|
|
|
|
s->whence = whence;
|
|
|
|
}
|
|
|
|
|
2013-09-12 10:50:04 +00:00
|
|
|
static void status_init_config(struct wt_status *s, config_fn_t fn)
|
|
|
|
{
|
|
|
|
wt_status_prepare(s);
|
|
|
|
gitmodules_config();
|
|
|
|
git_config(fn, s);
|
|
|
|
determine_whence(s);
|
2016-02-25 08:59:21 +00:00
|
|
|
init_diff_ui_defaults();
|
2013-09-12 10:50:05 +00:00
|
|
|
s->hints = advice_status_hints; /* must come after git_config() */
|
2013-09-12 10:50:04 +00:00
|
|
|
}
|
|
|
|
|
2007-11-18 09:52:55 +00:00
|
|
|
static void rollback_index_files(void)
|
|
|
|
{
|
|
|
|
switch (commit_style) {
|
|
|
|
case COMMIT_AS_IS:
|
|
|
|
break; /* nothing to do */
|
|
|
|
case COMMIT_NORMAL:
|
|
|
|
rollback_lock_file(&index_lock);
|
|
|
|
break;
|
|
|
|
case COMMIT_PARTIAL:
|
|
|
|
rollback_lock_file(&index_lock);
|
|
|
|
rollback_lock_file(&false_lock);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-23 17:21:22 +00:00
|
|
|
static int commit_index_files(void)
|
2007-11-18 09:52:55 +00:00
|
|
|
{
|
2008-01-23 17:21:22 +00:00
|
|
|
int err = 0;
|
|
|
|
|
2007-11-18 09:52:55 +00:00
|
|
|
switch (commit_style) {
|
|
|
|
case COMMIT_AS_IS:
|
|
|
|
break; /* nothing to do */
|
|
|
|
case COMMIT_NORMAL:
|
2008-01-23 17:21:22 +00:00
|
|
|
err = commit_lock_file(&index_lock);
|
2007-11-18 09:52:55 +00:00
|
|
|
break;
|
|
|
|
case COMMIT_PARTIAL:
|
2008-01-23 17:21:22 +00:00
|
|
|
err = commit_lock_file(&index_lock);
|
2007-11-18 09:52:55 +00:00
|
|
|
rollback_lock_file(&false_lock);
|
|
|
|
break;
|
|
|
|
}
|
2008-01-23 17:21:22 +00:00
|
|
|
|
|
|
|
return err;
|
2007-11-18 09:52:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Take a union of paths in the index and the named tree (typically, "HEAD"),
|
|
|
|
* and return the paths that match the given pattern in list.
|
|
|
|
*/
|
2008-07-21 18:03:49 +00:00
|
|
|
static int list_paths(struct string_list *list, const char *with_tree,
|
2013-07-14 08:35:53 +00:00
|
|
|
const char *prefix, const struct pathspec *pattern)
|
2007-11-18 09:52:55 +00:00
|
|
|
{
|
2015-03-21 00:28:07 +00:00
|
|
|
int i, ret;
|
2007-11-18 09:52:55 +00:00
|
|
|
char *m;
|
|
|
|
|
2013-07-14 08:35:53 +00:00
|
|
|
if (!pattern->nr)
|
commit: fix "--amend --only" with no pathspec
When we do not have any pathspec, we typically disallow an
explicit "--only", because it makes no sense (your commit
would, by definition, be empty). But since 6a74642
(git-commit --amend: two fixes., 2006-04-20), we have
allowed "--amend --only" with the intent that it would amend
the commit, ignoring any contents staged in the index.
However, while that commit allowed the combination, we never
actually implemented the logic to make it work. The current
code notices that we have no pathspec and assumes we want to
do an as-is commit (i.e., the "--only" is ignored).
Instead, we must make sure to follow the partial-commit
code-path. We also need to tweak the list_paths function to
handle a NULL pathspec.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-07-10 20:40:29 +00:00
|
|
|
return 0;
|
|
|
|
|
2013-07-14 08:35:53 +00:00
|
|
|
m = xcalloc(1, pattern->nr);
|
2007-11-18 09:52:55 +00:00
|
|
|
|
2011-07-30 17:13:47 +00:00
|
|
|
if (with_tree) {
|
2011-09-04 10:42:01 +00:00
|
|
|
char *max_prefix = common_prefix(pattern);
|
2011-09-04 10:41:59 +00:00
|
|
|
overlay_tree_on_cache(with_tree, max_prefix ? max_prefix : prefix);
|
|
|
|
free(max_prefix);
|
2011-07-30 17:13:47 +00:00
|
|
|
}
|
2007-11-18 09:52:55 +00:00
|
|
|
|
|
|
|
for (i = 0; i < active_nr; i++) {
|
Convert "struct cache_entry *" to "const ..." wherever possible
I attempted to make index_state->cache[] a "const struct cache_entry **"
to find out how existing entries in index are modified and where. The
question I have is what do we do if we really need to keep track of on-disk
changes in the index. The result is
- diff-lib.c: setting CE_UPTODATE
- name-hash.c: setting CE_HASHED
- preload-index.c, read-cache.c, unpack-trees.c and
builtin/update-index: obvious
- entry.c: write_entry() may refresh the checked out entry via
fill_stat_cache_info(). This causes "non-const struct cache_entry
*" in builtin/apply.c, builtin/checkout-index.c and
builtin/checkout.c
- builtin/ls-files.c: --with-tree changes stagemask and may set
CE_UPDATE
Of these, write_entry() and its call sites are probably most
interesting because it modifies on-disk info. But this is stat info
and can be retrieved via refresh, at least for porcelain
commands. Other just uses ce_flags for local purposes.
So, keeping track of "dirty" entries is just a matter of setting a
flag in index modification functions exposed by read-cache.c. Except
unpack-trees, the rest of the code base does not do anything funny
behind read-cache's back.
The actual patch is less valueable than the summary above. But if
anyone wants to re-identify the above sites. Applying this patch, then
this:
diff --git a/cache.h b/cache.h
index 430d021..1692891 100644
--- a/cache.h
+++ b/cache.h
@@ -267,7 +267,7 @@ static inline unsigned int canon_mode(unsigned int mode)
#define cache_entry_size(len) (offsetof(struct cache_entry,name) + (len) + 1)
struct index_state {
- struct cache_entry **cache;
+ const struct cache_entry **cache;
unsigned int version;
unsigned int cache_nr, cache_alloc, cache_changed;
struct string_list *resolve_undo;
will help quickly identify them without bogus warnings.
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-07-09 15:29:00 +00:00
|
|
|
const struct cache_entry *ce = active_cache[i];
|
2009-12-14 11:43:59 +00:00
|
|
|
struct string_list_item *item;
|
|
|
|
|
2008-01-15 00:03:17 +00:00
|
|
|
if (ce->ce_flags & CE_UPDATE)
|
2008-01-14 21:54:24 +00:00
|
|
|
continue;
|
2014-01-24 13:40:28 +00:00
|
|
|
if (!ce_path_match(ce, pattern, m))
|
2007-11-18 09:52:55 +00:00
|
|
|
continue;
|
2010-06-25 23:41:35 +00:00
|
|
|
item = string_list_insert(list, ce->name);
|
2009-12-14 11:43:59 +00:00
|
|
|
if (ce_skip_worktree(ce))
|
|
|
|
item->util = item; /* better a valid pointer than a fake one */
|
2007-11-18 09:52:55 +00:00
|
|
|
}
|
|
|
|
|
2015-03-21 00:28:07 +00:00
|
|
|
ret = report_path_error(m, pattern, prefix);
|
|
|
|
free(m);
|
|
|
|
return ret;
|
2007-11-18 09:52:55 +00:00
|
|
|
}
|
|
|
|
|
2008-07-21 18:03:49 +00:00
|
|
|
static void add_remove_files(struct string_list *list)
|
2007-11-18 09:52:55 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < list->nr; i++) {
|
2008-05-09 16:11:43 +00:00
|
|
|
struct stat st;
|
2008-07-21 18:03:49 +00:00
|
|
|
struct string_list_item *p = &(list->items[i]);
|
2008-05-09 16:11:43 +00:00
|
|
|
|
2009-12-14 11:43:59 +00:00
|
|
|
/* p->util is skip-worktree */
|
|
|
|
if (p->util)
|
2009-08-20 13:46:58 +00:00
|
|
|
continue;
|
2008-05-09 16:11:43 +00:00
|
|
|
|
2008-07-21 18:03:49 +00:00
|
|
|
if (!lstat(p->string, &st)) {
|
|
|
|
if (add_to_cache(p->string, &st, 0))
|
2011-02-22 23:41:44 +00:00
|
|
|
die(_("updating files failed"));
|
2008-05-12 17:57:45 +00:00
|
|
|
} else
|
2008-07-21 18:03:49 +00:00
|
|
|
remove_file_from_cache(p->string);
|
2007-11-18 09:52:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-19 18:58:18 +00:00
|
|
|
static void create_base_index(const struct commit *current_head)
|
2008-01-13 08:30:56 +00:00
|
|
|
{
|
|
|
|
struct tree *tree;
|
|
|
|
struct unpack_trees_options opts;
|
|
|
|
struct tree_desc t;
|
|
|
|
|
2011-08-19 18:58:18 +00:00
|
|
|
if (!current_head) {
|
2008-01-13 08:30:56 +00:00
|
|
|
discard_cache();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(&opts, 0, sizeof(opts));
|
|
|
|
opts.head_idx = 1;
|
|
|
|
opts.index_only = 1;
|
|
|
|
opts.merge = 1;
|
2008-03-07 02:12:28 +00:00
|
|
|
opts.src_index = &the_index;
|
|
|
|
opts.dst_index = &the_index;
|
2008-01-13 08:30:56 +00:00
|
|
|
|
|
|
|
opts.fn = oneway_merge;
|
2015-11-10 02:22:29 +00:00
|
|
|
tree = parse_tree_indirect(current_head->object.oid.hash);
|
2008-01-13 08:30:56 +00:00
|
|
|
if (!tree)
|
2011-02-22 23:41:44 +00:00
|
|
|
die(_("failed to unpack HEAD tree object"));
|
2008-01-13 08:30:56 +00:00
|
|
|
parse_tree(tree);
|
|
|
|
init_tree_desc(&t, tree->buffer, tree->size);
|
2008-02-07 16:39:48 +00:00
|
|
|
if (unpack_trees(1, &t, &opts))
|
|
|
|
exit(128); /* We've already reported the error, finish dying */
|
2008-01-13 08:30:56 +00:00
|
|
|
}
|
|
|
|
|
Be more user-friendly when refusing to do something because of conflict.
Various commands refuse to run in the presence of conflicts (commit,
merge, pull, cherry-pick/revert). They all used to provide rough, and
inconsistant error messages.
A new variable advice.resolveconflict is introduced, and allows more
verbose messages, pointing the user to the appropriate solution.
For commit, the error message used to look like this:
$ git commit
foo.txt: needs merge
foo.txt: unmerged (c34a92682e0394bc0d6f4d4a67a8e2d32395c169)
foo.txt: unmerged (3afcd75de8de0bb5076942fcb17446be50451030)
foo.txt: unmerged (c9785d77b76dfe4fb038bf927ee518f6ae45ede4)
error: Error building trees
The "need merge" line is given by refresh_cache. We add the IN_PORCELAIN
option to make the output more consistant with the other porcelain
commands, and catch the error in return, to stop with a clean error
message. The next lines were displayed by a call to cache_tree_update(),
which is not reached anymore if we noticed the conflict.
The new output looks like:
U foo.txt
fatal: 'commit' is not possible because you have unmerged files.
Please, fix them up in the work tree, and then use 'git add/rm <file>' as
appropriate to mark resolution and make a commit, or use 'git commit -a'.
Pull is slightly modified to abort immediately if $GIT_DIR/MERGE_HEAD
exists instead of waiting for merge to complain.
The behavior of merge and the test-case are slightly modified to reflect
the usual flow: start with conflicts, fix them, and afterwards get rid of
MERGE_HEAD, with different error messages at each stage.
Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-01-12 09:54:44 +00:00
|
|
|
static void refresh_cache_or_die(int refresh_flags)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* refresh_flags contains REFRESH_QUIET, so the only errors
|
|
|
|
* are for unmerged entries.
|
|
|
|
*/
|
|
|
|
if (refresh_cache(refresh_flags | REFRESH_IN_PORCELAIN))
|
|
|
|
die_resolve_conflict("commit");
|
|
|
|
}
|
|
|
|
|
2014-10-01 10:28:17 +00:00
|
|
|
static const char *prepare_index(int argc, const char **argv, const char *prefix,
|
|
|
|
const struct commit *current_head, int is_status)
|
2007-11-08 16:59:00 +00:00
|
|
|
{
|
2008-07-21 18:03:49 +00:00
|
|
|
struct string_list partial;
|
2013-07-14 08:35:38 +00:00
|
|
|
struct pathspec pathspec;
|
2009-08-05 06:49:33 +00:00
|
|
|
int refresh_flags = REFRESH_QUIET;
|
2015-08-10 09:47:39 +00:00
|
|
|
const char *ret;
|
2007-11-08 16:59:00 +00:00
|
|
|
|
2009-08-05 06:49:33 +00:00
|
|
|
if (is_status)
|
|
|
|
refresh_flags |= REFRESH_UNMERGED;
|
2013-07-14 08:35:38 +00:00
|
|
|
parse_pathspec(&pathspec, 0,
|
|
|
|
PATHSPEC_PREFER_FULL,
|
|
|
|
prefix, argv);
|
2007-11-08 16:59:00 +00:00
|
|
|
|
2013-07-14 08:35:49 +00:00
|
|
|
if (read_cache_preload(&pathspec) < 0)
|
2011-02-22 23:41:44 +00:00
|
|
|
die(_("index file corrupt"));
|
2008-11-14 00:36:30 +00:00
|
|
|
|
2011-05-07 05:59:59 +00:00
|
|
|
if (interactive) {
|
2014-01-30 15:15:56 +00:00
|
|
|
char *old_index_env = NULL;
|
2016-12-07 18:33:54 +00:00
|
|
|
hold_locked_index(&index_lock, LOCK_DIE_ON_ERROR);
|
2011-05-07 05:59:59 +00:00
|
|
|
|
|
|
|
refresh_cache_or_die(refresh_flags);
|
|
|
|
|
2014-06-13 12:19:23 +00:00
|
|
|
if (write_locked_index(&the_index, &index_lock, CLOSE_LOCK))
|
2011-05-07 05:59:59 +00:00
|
|
|
die(_("unable to create temporary index"));
|
|
|
|
|
|
|
|
old_index_env = getenv(INDEX_ENVIRONMENT);
|
2015-08-10 09:47:39 +00:00
|
|
|
setenv(INDEX_ENVIRONMENT, get_lock_file_path(&index_lock), 1);
|
2011-05-07 05:59:59 +00:00
|
|
|
|
2011-05-07 17:58:07 +00:00
|
|
|
if (interactive_add(argc, argv, prefix, patch_interactive) != 0)
|
2011-05-07 05:59:59 +00:00
|
|
|
die(_("interactive add failed"));
|
|
|
|
|
|
|
|
if (old_index_env && *old_index_env)
|
|
|
|
setenv(INDEX_ENVIRONMENT, old_index_env, 1);
|
|
|
|
else
|
|
|
|
unsetenv(INDEX_ENVIRONMENT);
|
|
|
|
|
|
|
|
discard_cache();
|
2015-08-10 09:47:39 +00:00
|
|
|
read_cache_from(get_lock_file_path(&index_lock));
|
2014-07-13 20:28:19 +00:00
|
|
|
if (update_main_cache_tree(WRITE_TREE_SILENT) == 0) {
|
2014-09-11 17:33:32 +00:00
|
|
|
if (reopen_lock_file(&index_lock) < 0)
|
2014-07-13 20:28:19 +00:00
|
|
|
die(_("unable to write index file"));
|
2014-09-11 17:33:32 +00:00
|
|
|
if (write_locked_index(&the_index, &index_lock, CLOSE_LOCK))
|
|
|
|
die(_("unable to update temporary index"));
|
2014-07-13 20:28:19 +00:00
|
|
|
} else
|
|
|
|
warning(_("Failed to update main cache tree"));
|
2011-05-07 05:59:59 +00:00
|
|
|
|
|
|
|
commit_style = COMMIT_NORMAL;
|
2015-08-10 09:47:39 +00:00
|
|
|
return get_lock_file_path(&index_lock);
|
2011-05-07 05:59:59 +00:00
|
|
|
}
|
|
|
|
|
2007-11-18 09:52:55 +00:00
|
|
|
/*
|
|
|
|
* Non partial, non as-is commit.
|
|
|
|
*
|
|
|
|
* (1) get the real index;
|
|
|
|
* (2) update the_index as necessary;
|
|
|
|
* (3) write the_index out to the real index (still locked);
|
|
|
|
* (4) return the name of the locked index file.
|
|
|
|
*
|
|
|
|
* The caller should run hooks on the locked real index, and
|
|
|
|
* (A) if all goes well, commit the real index;
|
|
|
|
* (B) on failure, rollback the real index.
|
|
|
|
*/
|
2013-07-14 08:35:38 +00:00
|
|
|
if (all || (also && pathspec.nr)) {
|
2016-12-07 18:33:54 +00:00
|
|
|
hold_locked_index(&index_lock, LOCK_DIE_ON_ERROR);
|
2016-09-14 21:07:47 +00:00
|
|
|
add_files_to_cache(also ? prefix : NULL, &pathspec, 0);
|
Be more user-friendly when refusing to do something because of conflict.
Various commands refuse to run in the presence of conflicts (commit,
merge, pull, cherry-pick/revert). They all used to provide rough, and
inconsistant error messages.
A new variable advice.resolveconflict is introduced, and allows more
verbose messages, pointing the user to the appropriate solution.
For commit, the error message used to look like this:
$ git commit
foo.txt: needs merge
foo.txt: unmerged (c34a92682e0394bc0d6f4d4a67a8e2d32395c169)
foo.txt: unmerged (3afcd75de8de0bb5076942fcb17446be50451030)
foo.txt: unmerged (c9785d77b76dfe4fb038bf927ee518f6ae45ede4)
error: Error building trees
The "need merge" line is given by refresh_cache. We add the IN_PORCELAIN
option to make the output more consistant with the other porcelain
commands, and catch the error in return, to stop with a clean error
message. The next lines were displayed by a call to cache_tree_update(),
which is not reached anymore if we noticed the conflict.
The new output looks like:
U foo.txt
fatal: 'commit' is not possible because you have unmerged files.
Please, fix them up in the work tree, and then use 'git add/rm <file>' as
appropriate to mark resolution and make a commit, or use 'git commit -a'.
Pull is slightly modified to abort immediately if $GIT_DIR/MERGE_HEAD
exists instead of waiting for merge to complain.
The behavior of merge and the test-case are slightly modified to reflect
the usual flow: start with conflicts, fix them, and afterwards get rid of
MERGE_HEAD, with different error messages at each stage.
Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-01-12 09:54:44 +00:00
|
|
|
refresh_cache_or_die(refresh_flags);
|
2012-01-16 02:36:46 +00:00
|
|
|
update_main_cache_tree(WRITE_TREE_SILENT);
|
2014-06-13 12:19:23 +00:00
|
|
|
if (write_locked_index(&the_index, &index_lock, CLOSE_LOCK))
|
2011-02-22 23:41:44 +00:00
|
|
|
die(_("unable to write new_index file"));
|
2007-11-18 09:52:55 +00:00
|
|
|
commit_style = COMMIT_NORMAL;
|
2015-08-10 09:47:39 +00:00
|
|
|
return get_lock_file_path(&index_lock);
|
2007-11-08 16:59:00 +00:00
|
|
|
}
|
|
|
|
|
2007-11-18 09:52:55 +00:00
|
|
|
/*
|
|
|
|
* As-is commit.
|
|
|
|
*
|
|
|
|
* (1) return the name of the real index file.
|
|
|
|
*
|
2010-04-02 12:27:18 +00:00
|
|
|
* The caller should run hooks on the real index,
|
|
|
|
* and create commit from the_index.
|
2007-11-18 09:52:55 +00:00
|
|
|
* We still need to refresh the index here.
|
|
|
|
*/
|
2013-07-14 08:35:38 +00:00
|
|
|
if (!only && !pathspec.nr) {
|
2016-12-07 18:33:54 +00:00
|
|
|
hold_locked_index(&index_lock, LOCK_DIE_ON_ERROR);
|
Be more user-friendly when refusing to do something because of conflict.
Various commands refuse to run in the presence of conflicts (commit,
merge, pull, cherry-pick/revert). They all used to provide rough, and
inconsistant error messages.
A new variable advice.resolveconflict is introduced, and allows more
verbose messages, pointing the user to the appropriate solution.
For commit, the error message used to look like this:
$ git commit
foo.txt: needs merge
foo.txt: unmerged (c34a92682e0394bc0d6f4d4a67a8e2d32395c169)
foo.txt: unmerged (3afcd75de8de0bb5076942fcb17446be50451030)
foo.txt: unmerged (c9785d77b76dfe4fb038bf927ee518f6ae45ede4)
error: Error building trees
The "need merge" line is given by refresh_cache. We add the IN_PORCELAIN
option to make the output more consistant with the other porcelain
commands, and catch the error in return, to stop with a clean error
message. The next lines were displayed by a call to cache_tree_update(),
which is not reached anymore if we noticed the conflict.
The new output looks like:
U foo.txt
fatal: 'commit' is not possible because you have unmerged files.
Please, fix them up in the work tree, and then use 'git add/rm <file>' as
appropriate to mark resolution and make a commit, or use 'git commit -a'.
Pull is slightly modified to abort immediately if $GIT_DIR/MERGE_HEAD
exists instead of waiting for merge to complain.
The behavior of merge and the test-case are slightly modified to reflect
the usual flow: start with conflicts, fix them, and afterwards get rid of
MERGE_HEAD, with different error messages at each stage.
Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-01-12 09:54:44 +00:00
|
|
|
refresh_cache_or_die(refresh_flags);
|
2014-07-13 20:28:19 +00:00
|
|
|
if (active_cache_changed
|
2015-08-27 17:07:54 +00:00
|
|
|
|| !cache_tree_fully_valid(active_cache_tree))
|
2012-01-16 02:36:46 +00:00
|
|
|
update_main_cache_tree(WRITE_TREE_SILENT);
|
2014-07-13 20:28:19 +00:00
|
|
|
if (active_cache_changed) {
|
2014-06-13 12:19:23 +00:00
|
|
|
if (write_locked_index(&the_index, &index_lock,
|
|
|
|
COMMIT_LOCK))
|
2011-02-22 23:41:44 +00:00
|
|
|
die(_("unable to write new_index file"));
|
2010-07-07 04:53:11 +00:00
|
|
|
} else {
|
|
|
|
rollback_lock_file(&index_lock);
|
|
|
|
}
|
2007-11-18 09:52:55 +00:00
|
|
|
commit_style = COMMIT_AS_IS;
|
2007-11-08 16:59:00 +00:00
|
|
|
return get_index_file();
|
|
|
|
}
|
|
|
|
|
2007-11-18 09:52:55 +00:00
|
|
|
/*
|
|
|
|
* A partial commit.
|
|
|
|
*
|
|
|
|
* (0) find the set of affected paths;
|
|
|
|
* (1) get lock on the real index file;
|
|
|
|
* (2) update the_index with the given paths;
|
|
|
|
* (3) write the_index out to the real index (still locked);
|
|
|
|
* (4) get lock on the false index file;
|
|
|
|
* (5) reset the_index from HEAD;
|
|
|
|
* (6) update the_index the same way as (2);
|
|
|
|
* (7) write the_index out to the false index file;
|
|
|
|
* (8) return the name of the false index file (still locked);
|
|
|
|
*
|
|
|
|
* The caller should run hooks on the locked false index, and
|
|
|
|
* create commit from it. Then
|
|
|
|
* (A) if all goes well, commit the real index;
|
|
|
|
* (B) on failure, rollback the real index;
|
|
|
|
* In either case, rollback the false index.
|
|
|
|
*/
|
|
|
|
commit_style = COMMIT_PARTIAL;
|
|
|
|
|
2012-04-30 15:33:13 +00:00
|
|
|
if (whence != FROM_COMMIT) {
|
|
|
|
if (whence == FROM_MERGE)
|
|
|
|
die(_("cannot do a partial commit during a merge."));
|
|
|
|
else if (whence == FROM_CHERRY_PICK)
|
|
|
|
die(_("cannot do a partial commit during a cherry-pick."));
|
|
|
|
}
|
2007-11-18 09:52:55 +00:00
|
|
|
|
2014-07-18 09:19:00 +00:00
|
|
|
string_list_init(&partial, 1);
|
2013-07-14 08:35:53 +00:00
|
|
|
if (list_paths(&partial, !current_head ? NULL : "HEAD", prefix, &pathspec))
|
2007-11-18 09:52:55 +00:00
|
|
|
exit(1);
|
|
|
|
|
|
|
|
discard_cache();
|
|
|
|
if (read_cache() < 0)
|
2011-02-22 23:41:44 +00:00
|
|
|
die(_("cannot read the index"));
|
2007-11-18 09:52:55 +00:00
|
|
|
|
2016-12-07 18:33:54 +00:00
|
|
|
hold_locked_index(&index_lock, LOCK_DIE_ON_ERROR);
|
2007-11-18 09:52:55 +00:00
|
|
|
add_remove_files(&partial);
|
2007-11-12 20:48:22 +00:00
|
|
|
refresh_cache(REFRESH_QUIET);
|
2014-07-13 20:28:19 +00:00
|
|
|
update_main_cache_tree(WRITE_TREE_SILENT);
|
2014-06-13 12:19:23 +00:00
|
|
|
if (write_locked_index(&the_index, &index_lock, CLOSE_LOCK))
|
2011-02-22 23:41:44 +00:00
|
|
|
die(_("unable to write new_index file"));
|
2007-11-08 16:59:00 +00:00
|
|
|
|
2014-06-13 12:19:23 +00:00
|
|
|
hold_lock_file_for_update(&false_lock,
|
|
|
|
git_path("next-index-%"PRIuMAX,
|
|
|
|
(uintmax_t) getpid()),
|
|
|
|
LOCK_DIE_ON_ERROR);
|
2008-01-13 08:30:56 +00:00
|
|
|
|
2011-08-19 18:58:18 +00:00
|
|
|
create_base_index(current_head);
|
2007-11-18 09:52:55 +00:00
|
|
|
add_remove_files(&partial);
|
2007-11-09 16:40:27 +00:00
|
|
|
refresh_cache(REFRESH_QUIET);
|
2007-11-08 16:59:00 +00:00
|
|
|
|
2014-06-13 12:19:23 +00:00
|
|
|
if (write_locked_index(&the_index, &false_lock, CLOSE_LOCK))
|
2011-02-22 23:41:44 +00:00
|
|
|
die(_("unable to write temporary index file"));
|
2008-02-14 17:18:23 +00:00
|
|
|
|
|
|
|
discard_cache();
|
2015-08-10 09:47:39 +00:00
|
|
|
ret = get_lock_file_path(&false_lock);
|
|
|
|
read_cache_from(ret);
|
|
|
|
return ret;
|
2007-11-08 16:59:00 +00:00
|
|
|
}
|
|
|
|
|
2009-08-10 04:59:30 +00:00
|
|
|
static int run_status(FILE *fp, const char *index_file, const char *prefix, int nowarn,
|
|
|
|
struct wt_status *s)
|
2007-11-08 16:59:00 +00:00
|
|
|
{
|
2017-02-20 00:10:14 +00:00
|
|
|
struct object_id oid;
|
2009-08-08 06:31:57 +00:00
|
|
|
|
2009-08-10 04:59:30 +00:00
|
|
|
if (s->relative_paths)
|
|
|
|
s->prefix = prefix;
|
2007-11-08 16:59:00 +00:00
|
|
|
|
|
|
|
if (amend) {
|
2009-08-10 04:59:30 +00:00
|
|
|
s->amend = 1;
|
|
|
|
s->reference = "HEAD^1";
|
2007-11-08 16:59:00 +00:00
|
|
|
}
|
2009-08-10 04:59:30 +00:00
|
|
|
s->verbose = verbose;
|
|
|
|
s->index_file = index_file;
|
|
|
|
s->fp = fp;
|
|
|
|
s->nowarn = nowarn;
|
2017-02-20 00:10:14 +00:00
|
|
|
s->is_initial = get_sha1(s->reference, oid.hash) ? 1 : 0;
|
2016-08-11 14:45:59 +00:00
|
|
|
if (!s->is_initial)
|
2017-02-20 00:10:14 +00:00
|
|
|
hashcpy(s->sha1_commit, oid.hash);
|
2016-08-05 22:00:27 +00:00
|
|
|
s->status_format = status_format;
|
|
|
|
s->ignore_submodule_arg = ignore_submodule_arg;
|
2007-11-08 16:59:00 +00:00
|
|
|
|
2009-08-08 06:31:57 +00:00
|
|
|
wt_status_collect(s);
|
2016-08-05 22:00:27 +00:00
|
|
|
wt_status_print(s);
|
2007-11-08 16:59:00 +00:00
|
|
|
|
2009-08-10 04:59:30 +00:00
|
|
|
return s->commitable;
|
2007-11-08 16:59:00 +00:00
|
|
|
}
|
|
|
|
|
2011-08-19 18:58:18 +00:00
|
|
|
static int is_a_merge(const struct commit *current_head)
|
2008-02-05 10:01:46 +00:00
|
|
|
{
|
2011-08-19 18:58:18 +00:00
|
|
|
return !!(current_head->parents && current_head->parents->next);
|
2008-02-05 10:01:46 +00:00
|
|
|
}
|
|
|
|
|
commit: loosen ident checks when generating template
When we generate the commit-message template, we try to
report an author or committer ident that will be of interest
to the user: an author that does not match the committer, or
a committer that was auto-configured.
When doing so, if we encounter what we consider to be a
bogus ident, we immediately die. This is a bad idea, because
our use of the idents here is purely informational. Any
ident rules should be enforced elsewhere, because commits
that do not invoke the editor will not even hit this code
path (e.g., "git commit -mfoo" would work, but "git commit"
would not). So at best, we are redundant with other checks,
and at worse, we actively prevent commits that should
otherwise be allowed.
We should therefore do the minimal parsing we can to get a
value and not do any validation (i.e., drop the call to
sane_ident_split()).
In theory we could notice when even our minimal parsing
fails to work, and do the sane thing for each check (e.g.,
if we have an author but can't parse the committer, assume
they are different and print the author). But we can
actually simplify this even further.
We know that the author and committer strings we are parsing
have been generated by us earlier in the program, and
therefore they must be parseable. We could just call
split_ident_line without even checking its return value,
knowing that it will put _something_ in the name/mail
fields. Of course, to protect ourselves against future
changes to the code, it makes sense to turn this into an
assert, so we are not surprised if our assumption fails.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2014-12-10 15:42:10 +00:00
|
|
|
static void assert_split_ident(struct ident_split *id, const struct strbuf *buf)
|
|
|
|
{
|
commit: always populate GIT_AUTHOR_* variables
To figure out the author ident for a commit, we call
determine_author_info(). This function collects information
from the environment, other commits (in the case of
"--amend" or "-c/-C"), and the "--author" option. It then
uses fmt_ident to generate the final ident string that goes
into the commit object. fmt_ident is therefore responsible
for any quality or validation checks on what is allowed to
go into a commit.
Before returning, though, we call split_ident_line on the
result, and feed the individual components to hooks via the
GIT_AUTHOR_* variables. Furthermore, we do extra validation
by feeding the split to sane_ident_split(), which is pickier
than fmt_ident (in particular, it will complain about an empty
email field). If this parsing or validation fails, we skip
updating the environment variables.
This is bad, because it means that hooks may silently see a
different ident than what we are putting into the commit. We
should drop the extra sane_ident_split checks entirely, and
take whatever fmt_ident has fed us (and what will go into
the commit object).
If parsing fails, we should actually abort here rather than
continuing (and feeding the hooks bogus data). However,
split_ident_line should never fail here. The ident was just
generated by fmt_ident, so we know that it's sane. We can
use assert_split_ident to double-check this.
Note that we also teach that assertion to check that we
found a date (it always should, but until now, no caller
cared whether we found a date or not). Checking the return
value of sane_ident_split is enough to ensure we have the
name/email pointers set, and checking date_begin is enough
to know that all of the date/tz variables are set.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2014-12-10 15:43:42 +00:00
|
|
|
if (split_ident_line(id, buf->buf, buf->len) || !id->date_begin)
|
commit: loosen ident checks when generating template
When we generate the commit-message template, we try to
report an author or committer ident that will be of interest
to the user: an author that does not match the committer, or
a committer that was auto-configured.
When doing so, if we encounter what we consider to be a
bogus ident, we immediately die. This is a bad idea, because
our use of the idents here is purely informational. Any
ident rules should be enforced elsewhere, because commits
that do not invoke the editor will not even hit this code
path (e.g., "git commit -mfoo" would work, but "git commit"
would not). So at best, we are redundant with other checks,
and at worse, we actively prevent commits that should
otherwise be allowed.
We should therefore do the minimal parsing we can to get a
value and not do any validation (i.e., drop the call to
sane_ident_split()).
In theory we could notice when even our minimal parsing
fails to work, and do the sane thing for each check (e.g.,
if we have an author but can't parse the committer, assume
they are different and print the author). But we can
actually simplify this even further.
We know that the author and committer strings we are parsing
have been generated by us earlier in the program, and
therefore they must be parseable. We could just call
split_ident_line without even checking its return value,
knowing that it will put _something_ in the name/mail
fields. Of course, to protect ourselves against future
changes to the code, it makes sense to turn this into an
assert, so we are not surprised if our assumption fails.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2014-12-10 15:42:10 +00:00
|
|
|
die("BUG: unable to parse our own ident: %s", buf->buf);
|
|
|
|
}
|
|
|
|
|
2012-03-11 10:12:10 +00:00
|
|
|
static void export_one(const char *var, const char *s, const char *e, int hack)
|
|
|
|
{
|
|
|
|
struct strbuf buf = STRBUF_INIT;
|
|
|
|
if (hack)
|
|
|
|
strbuf_addch(&buf, hack);
|
|
|
|
strbuf_addf(&buf, "%.*s", (int)(e - s), s);
|
|
|
|
setenv(var, buf.buf, 1);
|
|
|
|
strbuf_release(&buf);
|
|
|
|
}
|
|
|
|
|
2014-08-27 07:57:08 +00:00
|
|
|
static int parse_force_date(const char *in, struct strbuf *out)
|
2014-05-02 01:12:42 +00:00
|
|
|
{
|
2014-08-27 07:57:08 +00:00
|
|
|
strbuf_addch(out, '@');
|
2014-05-02 01:12:42 +00:00
|
|
|
|
2014-08-27 07:57:08 +00:00
|
|
|
if (parse_date(in, out) < 0) {
|
2014-05-02 01:12:42 +00:00
|
|
|
int errors = 0;
|
|
|
|
unsigned long t = approxidate_careful(in, &errors);
|
|
|
|
if (errors)
|
|
|
|
return -1;
|
2014-08-27 07:57:08 +00:00
|
|
|
strbuf_addf(out, "%lu", t);
|
2014-05-02 01:12:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-08-27 07:57:56 +00:00
|
|
|
static void set_ident_var(char **buf, char *val)
|
|
|
|
{
|
|
|
|
free(*buf);
|
|
|
|
*buf = val;
|
|
|
|
}
|
|
|
|
|
2010-12-21 01:00:36 +00:00
|
|
|
static void determine_author_info(struct strbuf *author_ident)
|
2008-05-04 16:04:49 +00:00
|
|
|
{
|
|
|
|
char *name, *email, *date;
|
2012-03-11 10:12:10 +00:00
|
|
|
struct ident_split author;
|
2008-05-04 16:04:49 +00:00
|
|
|
|
2015-01-13 01:58:33 +00:00
|
|
|
name = xstrdup_or_null(getenv("GIT_AUTHOR_NAME"));
|
|
|
|
email = xstrdup_or_null(getenv("GIT_AUTHOR_EMAIL"));
|
|
|
|
date = xstrdup_or_null(getenv("GIT_AUTHOR_DATE"));
|
2008-05-04 16:04:49 +00:00
|
|
|
|
2011-02-20 04:12:29 +00:00
|
|
|
if (author_message) {
|
2014-08-27 07:57:28 +00:00
|
|
|
struct ident_split ident;
|
2012-02-02 21:41:43 +00:00
|
|
|
size_t len;
|
2014-08-27 07:57:28 +00:00
|
|
|
const char *a;
|
2008-05-04 16:04:49 +00:00
|
|
|
|
2014-08-27 07:57:28 +00:00
|
|
|
a = find_commit_header(author_message_buffer, "author", &len);
|
2008-05-04 16:04:49 +00:00
|
|
|
if (!a)
|
2014-08-27 07:57:28 +00:00
|
|
|
die(_("commit '%s' lacks author header"), author_message);
|
|
|
|
if (split_ident_line(&ident, a, len) < 0)
|
|
|
|
die(_("commit '%s' has malformed author line"), author_message);
|
|
|
|
|
2014-08-27 07:57:56 +00:00
|
|
|
set_ident_var(&name, xmemdupz(ident.name_begin, ident.name_end - ident.name_begin));
|
|
|
|
set_ident_var(&email, xmemdupz(ident.mail_begin, ident.mail_end - ident.mail_begin));
|
|
|
|
|
2014-08-27 07:57:28 +00:00
|
|
|
if (ident.date_begin) {
|
2014-08-27 07:57:56 +00:00
|
|
|
struct strbuf date_buf = STRBUF_INIT;
|
2014-08-27 07:57:28 +00:00
|
|
|
strbuf_addch(&date_buf, '@');
|
|
|
|
strbuf_add(&date_buf, ident.date_begin, ident.date_end - ident.date_begin);
|
|
|
|
strbuf_addch(&date_buf, ' ');
|
|
|
|
strbuf_add(&date_buf, ident.tz_begin, ident.tz_end - ident.tz_begin);
|
2014-08-27 07:57:56 +00:00
|
|
|
set_ident_var(&date, strbuf_detach(&date_buf, NULL));
|
2014-08-27 07:57:28 +00:00
|
|
|
}
|
2008-05-04 16:04:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (force_author) {
|
2014-08-27 07:57:28 +00:00
|
|
|
struct ident_split ident;
|
2008-05-04 16:04:49 +00:00
|
|
|
|
2014-08-27 07:57:28 +00:00
|
|
|
if (split_ident_line(&ident, force_author, strlen(force_author)) < 0)
|
2011-02-22 23:41:44 +00:00
|
|
|
die(_("malformed --author parameter"));
|
2014-08-27 07:57:56 +00:00
|
|
|
set_ident_var(&name, xmemdupz(ident.name_begin, ident.name_end - ident.name_begin));
|
|
|
|
set_ident_var(&email, xmemdupz(ident.mail_begin, ident.mail_end - ident.mail_begin));
|
2008-05-04 16:04:49 +00:00
|
|
|
}
|
|
|
|
|
2014-05-02 01:12:42 +00:00
|
|
|
if (force_date) {
|
2014-08-27 07:57:56 +00:00
|
|
|
struct strbuf date_buf = STRBUF_INIT;
|
2014-08-27 07:57:08 +00:00
|
|
|
if (parse_force_date(force_date, &date_buf))
|
2014-05-02 01:12:42 +00:00
|
|
|
die(_("invalid date format: %s"), force_date);
|
2014-08-27 07:57:56 +00:00
|
|
|
set_ident_var(&date, strbuf_detach(&date_buf, NULL));
|
2014-05-02 01:12:42 +00:00
|
|
|
}
|
|
|
|
|
2012-05-24 23:28:40 +00:00
|
|
|
strbuf_addstr(author_ident, fmt_ident(name, email, date, IDENT_STRICT));
|
commit: always populate GIT_AUTHOR_* variables
To figure out the author ident for a commit, we call
determine_author_info(). This function collects information
from the environment, other commits (in the case of
"--amend" or "-c/-C"), and the "--author" option. It then
uses fmt_ident to generate the final ident string that goes
into the commit object. fmt_ident is therefore responsible
for any quality or validation checks on what is allowed to
go into a commit.
Before returning, though, we call split_ident_line on the
result, and feed the individual components to hooks via the
GIT_AUTHOR_* variables. Furthermore, we do extra validation
by feeding the split to sane_ident_split(), which is pickier
than fmt_ident (in particular, it will complain about an empty
email field). If this parsing or validation fails, we skip
updating the environment variables.
This is bad, because it means that hooks may silently see a
different ident than what we are putting into the commit. We
should drop the extra sane_ident_split checks entirely, and
take whatever fmt_ident has fed us (and what will go into
the commit object).
If parsing fails, we should actually abort here rather than
continuing (and feeding the hooks bogus data). However,
split_ident_line should never fail here. The ident was just
generated by fmt_ident, so we know that it's sane. We can
use assert_split_ident to double-check this.
Note that we also teach that assertion to check that we
found a date (it always should, but until now, no caller
cared whether we found a date or not). Checking the return
value of sane_ident_split is enough to ensure we have the
name/email pointers set, and checking date_begin is enough
to know that all of the date/tz variables are set.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2014-12-10 15:43:42 +00:00
|
|
|
assert_split_ident(&author, author_ident);
|
|
|
|
export_one("GIT_AUTHOR_NAME", author.name_begin, author.name_end, 0);
|
|
|
|
export_one("GIT_AUTHOR_EMAIL", author.mail_begin, author.mail_end, 0);
|
|
|
|
export_one("GIT_AUTHOR_DATE", author.date_begin, author.tz_end, '@');
|
2014-08-27 07:57:56 +00:00
|
|
|
free(name);
|
|
|
|
free(email);
|
|
|
|
free(date);
|
2008-05-04 16:04:49 +00:00
|
|
|
}
|
|
|
|
|
2014-05-02 01:10:01 +00:00
|
|
|
static int author_date_is_interesting(void)
|
|
|
|
{
|
|
|
|
return author_message || force_date;
|
2010-12-21 01:00:36 +00:00
|
|
|
}
|
|
|
|
|
2014-05-17 01:52:23 +00:00
|
|
|
static void adjust_comment_line_char(const struct strbuf *sb)
|
|
|
|
{
|
|
|
|
char candidates[] = "#;@!$%^&|:";
|
|
|
|
char *candidate;
|
|
|
|
const char *p;
|
|
|
|
|
|
|
|
comment_line_char = candidates[0];
|
|
|
|
if (!memchr(sb->buf, comment_line_char, sb->len))
|
|
|
|
return;
|
|
|
|
|
|
|
|
p = sb->buf;
|
|
|
|
candidate = strchr(candidates, *p);
|
|
|
|
if (candidate)
|
|
|
|
*candidate = ' ';
|
|
|
|
for (p = sb->buf; *p; p++) {
|
|
|
|
if ((p[0] == '\n' || p[0] == '\r') && p[1]) {
|
|
|
|
candidate = strchr(candidates, p[1]);
|
|
|
|
if (candidate)
|
|
|
|
*candidate = ' ';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (p = candidates; *p == ' '; p++)
|
|
|
|
;
|
|
|
|
if (!*p)
|
|
|
|
die(_("unable to select a comment character that is not used\n"
|
|
|
|
"in the current commit message"));
|
|
|
|
comment_line_char = *p;
|
|
|
|
}
|
|
|
|
|
2009-08-10 04:59:30 +00:00
|
|
|
static int prepare_to_commit(const char *index_file, const char *prefix,
|
2011-08-19 18:58:18 +00:00
|
|
|
struct commit *current_head,
|
2010-12-21 01:00:36 +00:00
|
|
|
struct wt_status *s,
|
|
|
|
struct strbuf *author_ident)
|
2007-11-08 16:59:00 +00:00
|
|
|
{
|
|
|
|
struct stat statbuf;
|
2010-12-21 01:00:36 +00:00
|
|
|
struct strbuf committer_ident = STRBUF_INIT;
|
2014-01-30 15:15:56 +00:00
|
|
|
int commitable;
|
2008-10-09 19:12:12 +00:00
|
|
|
struct strbuf sb = STRBUF_INIT;
|
2008-02-05 07:04:18 +00:00
|
|
|
const char *hook_arg1 = NULL;
|
|
|
|
const char *hook_arg2 = NULL;
|
2011-05-08 10:31:02 +00:00
|
|
|
int clean_message_contents = (cleanup_mode != CLEANUP_NONE);
|
2013-09-06 17:43:07 +00:00
|
|
|
int old_display_comment_prefix;
|
2007-11-08 16:59:00 +00:00
|
|
|
|
2012-03-11 10:12:10 +00:00
|
|
|
/* This checks and barfs if author is badly specified */
|
|
|
|
determine_author_info(author_ident);
|
|
|
|
|
2014-03-18 10:00:53 +00:00
|
|
|
if (!no_verify && run_commit_hook(use_editor, index_file, "pre-commit", NULL))
|
2008-02-05 10:01:46 +00:00
|
|
|
return 0;
|
2007-11-08 16:59:00 +00:00
|
|
|
|
2010-11-02 19:59:11 +00:00
|
|
|
if (squash_message) {
|
|
|
|
/*
|
|
|
|
* Insert the proper subject line before other commit
|
|
|
|
* message options add their content.
|
|
|
|
*/
|
|
|
|
if (use_message && !strcmp(use_message, squash_message))
|
|
|
|
strbuf_addstr(&sb, "squash! ");
|
|
|
|
else {
|
|
|
|
struct pretty_print_context ctx = {0};
|
|
|
|
struct commit *c;
|
|
|
|
c = lookup_commit_reference_by_name(squash_message);
|
|
|
|
if (!c)
|
2011-02-22 23:41:44 +00:00
|
|
|
die(_("could not lookup commit %s"), squash_message);
|
2010-11-02 19:59:11 +00:00
|
|
|
ctx.output_encoding = get_commit_output_encoding();
|
|
|
|
format_commit_message(c, "squash! %s\n\n", &sb,
|
|
|
|
&ctx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
commit: do not ignore an empty message given by -m ''
When f9568530 (builtin-commit: resurrect behavior for multiple -m
options, 2007-11-11) converted a "char *message" to "struct strbuf
message" to hold the messages given with the "-m" option, it
incorrectly changed the checks "did we get a message with the -m
option?" to "is message.len 0?". Later, we noticed one breakage
from this change and corrected it with 25206778 (commit: don't start
editor if empty message is given with -m, 2013-05-25).
However, "we got a message with -m, even though an empty one, so we
shouldn't be launching an editor" was not the only breakage.
* "git commit --amend -m '' --allow-empty", even though it looks
strange, is a valid request to amend the commit to have no
message at all. Due to the misdetection of the presence of -m on
the command line, we ended up keeping the log messsage from the
original commit.
* "git commit -m "$msg" -F file" should be rejected whether $msg is
an empty string or not, but due to the same bug, was not rejected
when $msg is empty.
* "git -c template=file -m "$msg"" should ignore the template even
when $msg is empty, but it didn't and instead used the contents
from the template file.
Correct these by checking have_option_m, which the earlier 25206778
introduced to fix the same bug.
Reported-by: Adam Dinwoodie <adam@dinwoodie.org>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2016-04-07 19:56:26 +00:00
|
|
|
if (have_option_m) {
|
2007-11-11 17:36:39 +00:00
|
|
|
strbuf_addbuf(&sb, &message);
|
2008-02-05 07:04:18 +00:00
|
|
|
hook_arg1 = "message";
|
2007-11-08 16:59:00 +00:00
|
|
|
} else if (logfile && !strcmp(logfile, "-")) {
|
|
|
|
if (isatty(0))
|
2011-02-22 23:41:44 +00:00
|
|
|
fprintf(stderr, _("(reading log message from standard input)\n"));
|
2007-11-08 16:59:00 +00:00
|
|
|
if (strbuf_read(&sb, 0, 0) < 0)
|
2011-02-22 23:41:44 +00:00
|
|
|
die_errno(_("could not read log from standard input"));
|
2008-02-05 07:04:18 +00:00
|
|
|
hook_arg1 = "message";
|
2007-11-08 16:59:00 +00:00
|
|
|
} else if (logfile) {
|
|
|
|
if (strbuf_read_file(&sb, logfile, 0) < 0)
|
2011-02-22 23:41:44 +00:00
|
|
|
die_errno(_("could not read log file '%s'"),
|
2009-06-27 15:58:46 +00:00
|
|
|
logfile);
|
2008-02-05 07:04:18 +00:00
|
|
|
hook_arg1 = "message";
|
2007-11-08 16:59:00 +00:00
|
|
|
} else if (use_message) {
|
2014-01-30 15:15:56 +00:00
|
|
|
char *buffer;
|
2007-11-08 16:59:00 +00:00
|
|
|
buffer = strstr(use_message_buffer, "\n\n");
|
commit: do not complain of empty messages from -C
When we pick another commit's message, we die() immediately
if we find that it's empty and we are not going to run an
editor (i.e., when running "-C" instead of "-c"). However,
this check is redundant and harmful.
It's redundant because we will already notice the empty
message later, after we would have run the editor, and die
there (just as we would for a regular, not "-C" case, where
the user provided an empty message in the editor).
It's harmful for a few reasons:
1. It does not respect --allow-empty-message. As a result,
a "git rebase -i" cannot "pick" such a commit. So you
cannot even go back in time to fix it with a "reword"
or "edit" instruction.
2. It does not take into account other ways besides the
editor to modify the message. For example, "git commit
-C empty-commit -m foo" could take the author
information from empty-commit, but add a message to it.
There's more to do to make that work correctly (and
right now we explicitly forbid "-C with -m"), but this
removes one roadblock.
3. The existing check is not enough to prevent segfaults.
We try to find the "\n\n" header/body boundary in the
commit. If it is at the end of the string (i.e., no
body), _or_ if we cannot find it at all (i.e., a
truncated commit object), we consider the message
empty. With "-C", that's OK; we die in either case. But
with "-c", we continue on, and in the case of a
truncated commit may end up dereferencing NULL+2.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2014-04-25 23:11:15 +00:00
|
|
|
if (buffer)
|
2016-06-29 14:14:42 +00:00
|
|
|
strbuf_addstr(&sb, skip_blank_lines(buffer + 2));
|
2008-02-05 07:04:18 +00:00
|
|
|
hook_arg1 = "commit";
|
|
|
|
hook_arg2 = use_message;
|
2010-11-02 19:59:09 +00:00
|
|
|
} else if (fixup_message) {
|
|
|
|
struct pretty_print_context ctx = {0};
|
|
|
|
struct commit *commit;
|
|
|
|
commit = lookup_commit_reference_by_name(fixup_message);
|
|
|
|
if (!commit)
|
2011-02-22 23:41:44 +00:00
|
|
|
die(_("could not lookup commit %s"), fixup_message);
|
2010-11-02 19:59:09 +00:00
|
|
|
ctx.output_encoding = get_commit_output_encoding();
|
|
|
|
format_commit_message(commit, "fixup! %s\n\n",
|
|
|
|
&sb, &ctx);
|
|
|
|
hook_arg1 = "message";
|
memoize common git-path "constant" files
One of the most common uses of git_path() is to pass a
constant, like git_path("MERGE_MSG"). This has two
drawbacks:
1. The return value is a static buffer, and the lifetime
is dependent on other calls to git_path, etc.
2. There's no compile-time checking of the pathname. This
is OK for a one-off (after all, we have to spell it
correctly at least once), but many of these constant
strings appear throughout the code.
This patch introduces a series of functions to "memoize"
these strings, which are essentially globals for the
lifetime of the program. We compute the value once, take
ownership of the buffer, and return the cached value for
subsequent calls. cache.h provides a helper macro for
defining these functions as one-liners, and defines a few
common ones for global use.
Using a macro is a little bit gross, but it does nicely
document the purpose of the functions. If we need to touch
them all later (e.g., because we learned how to change the
git_dir variable at runtime, and need to invalidate all of
the stored values), it will be much easier to have the
complete list.
Note that the shared-global functions have separate, manual
declarations. We could do something clever with the macros
(e.g., expand it to a declaration in some places, and a
declaration _and_ a definition in path.c). But there aren't
that many, and it's probably better to stay away from
too-magical macros.
Likewise, if we abandon the C preprocessor in favor of
generating these with a script, we could get much fancier.
E.g., normalizing "FOO/BAR-BAZ" into "git_path_foo_bar_baz".
But the small amount of saved typing is probably not worth
the resulting confusion to readers who want to grep for the
function's definition.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-08-10 09:38:57 +00:00
|
|
|
} else if (!stat(git_path_merge_msg(), &statbuf)) {
|
2016-03-21 22:29:40 +00:00
|
|
|
/*
|
|
|
|
* prepend SQUASH_MSG here if it exists and a
|
|
|
|
* "merge --squash" was originally performed
|
|
|
|
*/
|
|
|
|
if (!stat(git_path_squash_msg(), &statbuf)) {
|
|
|
|
if (strbuf_read_file(&sb, git_path_squash_msg(), 0) < 0)
|
|
|
|
die_errno(_("could not read SQUASH_MSG"));
|
|
|
|
hook_arg1 = "squash";
|
|
|
|
} else
|
|
|
|
hook_arg1 = "merge";
|
memoize common git-path "constant" files
One of the most common uses of git_path() is to pass a
constant, like git_path("MERGE_MSG"). This has two
drawbacks:
1. The return value is a static buffer, and the lifetime
is dependent on other calls to git_path, etc.
2. There's no compile-time checking of the pathname. This
is OK for a one-off (after all, we have to spell it
correctly at least once), but many of these constant
strings appear throughout the code.
This patch introduces a series of functions to "memoize"
these strings, which are essentially globals for the
lifetime of the program. We compute the value once, take
ownership of the buffer, and return the cached value for
subsequent calls. cache.h provides a helper macro for
defining these functions as one-liners, and defines a few
common ones for global use.
Using a macro is a little bit gross, but it does nicely
document the purpose of the functions. If we need to touch
them all later (e.g., because we learned how to change the
git_dir variable at runtime, and need to invalidate all of
the stored values), it will be much easier to have the
complete list.
Note that the shared-global functions have separate, manual
declarations. We could do something clever with the macros
(e.g., expand it to a declaration in some places, and a
declaration _and_ a definition in path.c). But there aren't
that many, and it's probably better to stay away from
too-magical macros.
Likewise, if we abandon the C preprocessor in favor of
generating these with a script, we could get much fancier.
E.g., normalizing "FOO/BAR-BAZ" into "git_path_foo_bar_baz".
But the small amount of saved typing is probably not worth
the resulting confusion to readers who want to grep for the
function's definition.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-08-10 09:38:57 +00:00
|
|
|
if (strbuf_read_file(&sb, git_path_merge_msg(), 0) < 0)
|
2011-02-22 23:41:44 +00:00
|
|
|
die_errno(_("could not read MERGE_MSG"));
|
memoize common git-path "constant" files
One of the most common uses of git_path() is to pass a
constant, like git_path("MERGE_MSG"). This has two
drawbacks:
1. The return value is a static buffer, and the lifetime
is dependent on other calls to git_path, etc.
2. There's no compile-time checking of the pathname. This
is OK for a one-off (after all, we have to spell it
correctly at least once), but many of these constant
strings appear throughout the code.
This patch introduces a series of functions to "memoize"
these strings, which are essentially globals for the
lifetime of the program. We compute the value once, take
ownership of the buffer, and return the cached value for
subsequent calls. cache.h provides a helper macro for
defining these functions as one-liners, and defines a few
common ones for global use.
Using a macro is a little bit gross, but it does nicely
document the purpose of the functions. If we need to touch
them all later (e.g., because we learned how to change the
git_dir variable at runtime, and need to invalidate all of
the stored values), it will be much easier to have the
complete list.
Note that the shared-global functions have separate, manual
declarations. We could do something clever with the macros
(e.g., expand it to a declaration in some places, and a
declaration _and_ a definition in path.c). But there aren't
that many, and it's probably better to stay away from
too-magical macros.
Likewise, if we abandon the C preprocessor in favor of
generating these with a script, we could get much fancier.
E.g., normalizing "FOO/BAR-BAZ" into "git_path_foo_bar_baz".
But the small amount of saved typing is probably not worth
the resulting confusion to readers who want to grep for the
function's definition.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-08-10 09:38:57 +00:00
|
|
|
} else if (!stat(git_path_squash_msg(), &statbuf)) {
|
|
|
|
if (strbuf_read_file(&sb, git_path_squash_msg(), 0) < 0)
|
2011-02-22 23:41:44 +00:00
|
|
|
die_errno(_("could not read SQUASH_MSG"));
|
2008-02-05 07:04:18 +00:00
|
|
|
hook_arg1 = "squash";
|
2011-02-25 09:07:57 +00:00
|
|
|
} else if (template_file) {
|
2007-11-08 16:59:00 +00:00
|
|
|
if (strbuf_read_file(&sb, template_file, 0) < 0)
|
2011-02-22 23:41:44 +00:00
|
|
|
die_errno(_("could not read '%s'"), template_file);
|
2008-02-05 07:04:18 +00:00
|
|
|
hook_arg1 = "template";
|
2011-05-08 10:31:02 +00:00
|
|
|
clean_message_contents = 0;
|
2007-11-08 16:59:00 +00:00
|
|
|
}
|
|
|
|
|
2008-02-05 07:04:18 +00:00
|
|
|
/*
|
2011-02-20 04:12:29 +00:00
|
|
|
* The remaining cases don't modify the template message, but
|
|
|
|
* just set the argument(s) to the prepare-commit-msg hook.
|
2008-02-05 07:04:18 +00:00
|
|
|
*/
|
2011-02-20 04:12:29 +00:00
|
|
|
else if (whence == FROM_MERGE)
|
2008-02-05 07:04:18 +00:00
|
|
|
hook_arg1 = "merge";
|
2011-02-20 04:12:29 +00:00
|
|
|
else if (whence == FROM_CHERRY_PICK) {
|
|
|
|
hook_arg1 = "commit";
|
|
|
|
hook_arg2 = "CHERRY_PICK_HEAD";
|
|
|
|
}
|
2008-02-05 07:04:18 +00:00
|
|
|
|
2010-11-02 19:59:11 +00:00
|
|
|
if (squash_message) {
|
|
|
|
/*
|
|
|
|
* If squash_commit was used for the commit subject,
|
|
|
|
* then we're possibly hijacking other commit log options.
|
|
|
|
* Reset the hook args to tell the real story.
|
|
|
|
*/
|
|
|
|
hook_arg1 = "message";
|
|
|
|
hook_arg2 = "";
|
|
|
|
}
|
|
|
|
|
2016-05-24 19:19:50 +00:00
|
|
|
s->fp = fopen_for_writing(git_path_commit_editmsg());
|
2011-02-26 05:10:49 +00:00
|
|
|
if (s->fp == NULL)
|
2016-05-24 19:19:50 +00:00
|
|
|
die_errno(_("could not open '%s'"), git_path_commit_editmsg());
|
2007-11-08 16:59:00 +00:00
|
|
|
|
2013-09-06 17:43:07 +00:00
|
|
|
/* Ignore status.displayCommentPrefix: we do need comments in COMMIT_EDITMSG. */
|
|
|
|
old_display_comment_prefix = s->display_comment_prefix;
|
|
|
|
s->display_comment_prefix = 1;
|
|
|
|
|
2013-09-12 10:50:06 +00:00
|
|
|
/*
|
|
|
|
* Most hints are counter-productive when the commit has
|
|
|
|
* already started.
|
|
|
|
*/
|
|
|
|
s->hints = 0;
|
|
|
|
|
2011-05-08 10:31:02 +00:00
|
|
|
if (clean_message_contents)
|
2015-10-16 15:16:42 +00:00
|
|
|
strbuf_stripspace(&sb, 0);
|
2007-11-08 16:59:00 +00:00
|
|
|
|
2014-10-28 19:44:09 +00:00
|
|
|
if (signoff)
|
2016-11-02 17:29:17 +00:00
|
|
|
append_signoff(&sb, ignore_non_trailer(sb.buf, sb.len), 0);
|
2007-11-08 16:59:00 +00:00
|
|
|
|
2011-02-26 05:10:49 +00:00
|
|
|
if (fwrite(sb.buf, 1, sb.len, s->fp) < sb.len)
|
2011-02-22 23:41:44 +00:00
|
|
|
die_errno(_("could not write commit template"));
|
2007-11-11 17:35:58 +00:00
|
|
|
|
2014-05-17 01:52:23 +00:00
|
|
|
if (auto_comment_line_char)
|
|
|
|
adjust_comment_line_char(&sb);
|
2007-11-08 16:59:00 +00:00
|
|
|
strbuf_release(&sb);
|
|
|
|
|
2008-05-04 16:04:51 +00:00
|
|
|
/* This checks if committer ident is explicitly given */
|
commit: check committer identity more strictly
The identity of the committer will ultimately be pulled from
the ident code by commit_tree(). However, we make an attempt
to check the author and committer identity early, before the
user has done any manual work like inputting a commit
message. That lets us abort without them having to worry
about salvaging the work from .git/COMMIT_EDITMSG.
The early check for committer ident does not use the
IDENT_STRICT flag, meaning that it would not find an empty
name field. The motivation was presumably because we did not
want to be too restrictive, as later calls might be more lax
(for example, when we create the reflog entry, we do not
care too much about a real name). However, because
commit_tree will always get a strict identity to put in the
commit object itself, there is no point in being lax only to
die later (and in fact it is harmful, because the user will
have wasted time typing their commit message).
Incidentally, this bug was masked prior to 060d4bb, as the
initial loose call would taint the later strict call. So the
commit would succeed (albeit with a bogus committer line in
the commit object), and nobody noticed that our early check
did not match the later one.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-07-23 18:50:35 +00:00
|
|
|
strbuf_addstr(&committer_ident, git_committer_info(IDENT_STRICT));
|
2009-12-07 22:45:27 +00:00
|
|
|
if (use_editor && include_status) {
|
2014-01-30 15:15:56 +00:00
|
|
|
int ident_shown = 0;
|
|
|
|
int saved_color_setting;
|
2014-05-02 01:06:57 +00:00
|
|
|
struct ident_split ci, ai;
|
|
|
|
|
2014-02-17 12:15:32 +00:00
|
|
|
if (whence != FROM_COMMIT) {
|
|
|
|
if (cleanup_mode == CLEANUP_SCISSORS)
|
|
|
|
wt_status_add_cut_line(s->fp);
|
2011-02-26 05:11:37 +00:00
|
|
|
status_printf_ln(s, GIT_COLOR_NORMAL,
|
2012-04-30 15:33:13 +00:00
|
|
|
whence == FROM_MERGE
|
|
|
|
? _("\n"
|
|
|
|
"It looks like you may be committing a merge.\n"
|
|
|
|
"If this is not correct, please remove the file\n"
|
|
|
|
" %s\n"
|
|
|
|
"and try again.\n")
|
|
|
|
: _("\n"
|
|
|
|
"It looks like you may be committing a cherry-pick.\n"
|
|
|
|
"If this is not correct, please remove the file\n"
|
|
|
|
" %s\n"
|
|
|
|
"and try again.\n"),
|
2017-04-20 21:08:54 +00:00
|
|
|
whence == FROM_MERGE ?
|
|
|
|
git_path_merge_head() :
|
|
|
|
git_path_cherry_pick_head());
|
2014-02-17 12:15:32 +00:00
|
|
|
}
|
2008-02-05 10:01:46 +00:00
|
|
|
|
2011-02-26 05:11:37 +00:00
|
|
|
fprintf(s->fp, "\n");
|
2008-02-05 10:01:46 +00:00
|
|
|
if (cleanup_mode == CLEANUP_ALL)
|
2012-04-30 15:33:14 +00:00
|
|
|
status_printf(s, GIT_COLOR_NORMAL,
|
|
|
|
_("Please enter the commit message for your changes."
|
2013-01-16 19:18:48 +00:00
|
|
|
" Lines starting\nwith '%c' will be ignored, and an empty"
|
|
|
|
" message aborts the commit.\n"), comment_line_char);
|
2014-02-17 12:15:32 +00:00
|
|
|
else if (cleanup_mode == CLEANUP_SCISSORS && whence == FROM_COMMIT)
|
|
|
|
wt_status_add_cut_line(s->fp);
|
2008-02-05 10:01:46 +00:00
|
|
|
else /* CLEANUP_SPACE, that is. */
|
2012-04-30 15:33:14 +00:00
|
|
|
status_printf(s, GIT_COLOR_NORMAL,
|
|
|
|
_("Please enter the commit message for your changes."
|
2013-01-16 19:18:48 +00:00
|
|
|
" Lines starting\n"
|
|
|
|
"with '%c' will be kept; you may remove them"
|
|
|
|
" yourself if you want to.\n"
|
|
|
|
"An empty message aborts the commit.\n"), comment_line_char);
|
2008-02-05 10:01:46 +00:00
|
|
|
if (only_include_assumed)
|
2011-02-26 05:11:37 +00:00
|
|
|
status_printf_ln(s, GIT_COLOR_NORMAL,
|
|
|
|
"%s", only_include_assumed);
|
2008-02-05 10:01:46 +00:00
|
|
|
|
commit: loosen ident checks when generating template
When we generate the commit-message template, we try to
report an author or committer ident that will be of interest
to the user: an author that does not match the committer, or
a committer that was auto-configured.
When doing so, if we encounter what we consider to be a
bogus ident, we immediately die. This is a bad idea, because
our use of the idents here is purely informational. Any
ident rules should be enforced elsewhere, because commits
that do not invoke the editor will not even hit this code
path (e.g., "git commit -mfoo" would work, but "git commit"
would not). So at best, we are redundant with other checks,
and at worse, we actively prevent commits that should
otherwise be allowed.
We should therefore do the minimal parsing we can to get a
value and not do any validation (i.e., drop the call to
sane_ident_split()).
In theory we could notice when even our minimal parsing
fails to work, and do the sane thing for each check (e.g.,
if we have an author but can't parse the committer, assume
they are different and print the author). But we can
actually simplify this even further.
We know that the author and committer strings we are parsing
have been generated by us earlier in the program, and
therefore they must be parseable. We could just call
split_ident_line without even checking its return value,
knowing that it will put _something_ in the name/mail
fields. Of course, to protect ourselves against future
changes to the code, it makes sense to turn this into an
assert, so we are not surprised if our assumption fails.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2014-12-10 15:42:10 +00:00
|
|
|
/*
|
|
|
|
* These should never fail because they come from our own
|
|
|
|
* fmt_ident. They may fail the sane_ident test, but we know
|
|
|
|
* that the name and mail pointers will at least be valid,
|
|
|
|
* which is enough for our tests and printing here.
|
|
|
|
*/
|
|
|
|
assert_split_ident(&ai, author_ident);
|
|
|
|
assert_split_ident(&ci, &committer_ident);
|
2014-05-02 01:06:57 +00:00
|
|
|
|
|
|
|
if (ident_cmp(&ai, &ci))
|
2011-02-26 05:11:37 +00:00
|
|
|
status_printf_ln(s, GIT_COLOR_NORMAL,
|
2011-02-22 23:41:46 +00:00
|
|
|
_("%s"
|
2014-05-02 01:06:57 +00:00
|
|
|
"Author: %.*s <%.*s>"),
|
2011-02-26 05:11:37 +00:00
|
|
|
ident_shown++ ? "" : "\n",
|
2014-05-02 01:06:57 +00:00
|
|
|
(int)(ai.name_end - ai.name_begin), ai.name_begin,
|
|
|
|
(int)(ai.mail_end - ai.mail_begin), ai.mail_begin);
|
2008-05-04 16:04:50 +00:00
|
|
|
|
2014-05-02 01:10:01 +00:00
|
|
|
if (author_date_is_interesting())
|
|
|
|
status_printf_ln(s, GIT_COLOR_NORMAL,
|
|
|
|
_("%s"
|
|
|
|
"Date: %s"),
|
|
|
|
ident_shown++ ? "" : "\n",
|
convert "enum date_mode" into a struct
In preparation for adding date modes that may carry extra
information beyond the mode itself, this patch converts the
date_mode enum into a struct.
Most of the conversion is fairly straightforward; we pass
the struct as a pointer and dereference the type field where
necessary. Locations that declare a date_mode can use a "{}"
constructor. However, the tricky case is where we use the
enum labels as constants, like:
show_date(t, tz, DATE_NORMAL);
Ideally we could say:
show_date(t, tz, &{ DATE_NORMAL });
but of course C does not allow that. Likewise, we cannot
cast the constant to a struct, because we need to pass an
actual address. Our options are basically:
1. Manually add a "struct date_mode d = { DATE_NORMAL }"
definition to each caller, and pass "&d". This makes
the callers uglier, because they sometimes do not even
have their own scope (e.g., they are inside a switch
statement).
2. Provide a pre-made global "date_normal" struct that can
be passed by address. We'd also need "date_rfc2822",
"date_iso8601", and so forth. But at least the ugliness
is defined in one place.
3. Provide a wrapper that generates the correct struct on
the fly. The big downside is that we end up pointing to
a single global, which makes our wrapper non-reentrant.
But show_date is already not reentrant, so it does not
matter.
This patch implements 3, along with a minor macro to keep
the size of the callers sane.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-06-25 16:55:02 +00:00
|
|
|
show_ident_date(&ai, DATE_MODE(NORMAL)));
|
2008-05-04 16:04:50 +00:00
|
|
|
|
ident: keep separate "explicit" flags for author and committer
We keep track of whether the user ident was given to us
explicitly, or if we guessed at it from system parameters
like username and hostname. However, we kept only a single
variable. This covers the common cases (because the author
and committer will usually come from the same explicit
source), but can miss two cases:
1. GIT_COMMITTER_* is set explicitly, but we fallback for
GIT_AUTHOR. We claim the ident is explicit, even though
the author is not.
2. GIT_AUTHOR_* is set and we ask for author ident, but
not committer ident. We will claim the ident is
implicit, even though it is explicit.
This patch uses two variables instead of one, updates both
when we set the "fallback" values, and updates them
individually when we read from the environment.
Rather than keep user_ident_sufficiently_given as a
compatibility wrapper, we update the only two callers to
check the committer_ident, which matches their intent and
what was happening already.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-11-15 00:34:13 +00:00
|
|
|
if (!committer_ident_sufficiently_given())
|
2011-02-26 05:11:37 +00:00
|
|
|
status_printf_ln(s, GIT_COLOR_NORMAL,
|
2011-02-22 23:41:46 +00:00
|
|
|
_("%s"
|
2014-05-02 01:06:57 +00:00
|
|
|
"Committer: %.*s <%.*s>"),
|
2011-02-26 05:11:37 +00:00
|
|
|
ident_shown++ ? "" : "\n",
|
2014-05-02 01:06:57 +00:00
|
|
|
(int)(ci.name_end - ci.name_begin), ci.name_begin,
|
|
|
|
(int)(ci.mail_end - ci.mail_begin), ci.mail_begin);
|
2008-05-04 16:04:51 +00:00
|
|
|
|
|
|
|
if (ident_shown)
|
2014-05-04 06:12:55 +00:00
|
|
|
status_printf_ln(s, GIT_COLOR_NORMAL, "%s", "");
|
2008-05-04 16:04:51 +00:00
|
|
|
|
2009-08-10 04:59:30 +00:00
|
|
|
saved_color_setting = s->use_color;
|
|
|
|
s->use_color = 0;
|
2011-02-26 05:10:49 +00:00
|
|
|
commitable = run_status(s->fp, index_file, prefix, 1, s);
|
2009-08-10 04:59:30 +00:00
|
|
|
s->use_color = saved_color_setting;
|
2008-02-05 10:01:46 +00:00
|
|
|
} else {
|
2017-02-20 00:10:14 +00:00
|
|
|
struct object_id oid;
|
2007-12-20 03:23:03 +00:00
|
|
|
const char *parent = "HEAD";
|
2007-11-28 21:13:08 +00:00
|
|
|
|
|
|
|
if (!active_nr && read_cache() < 0)
|
2011-02-22 23:41:44 +00:00
|
|
|
die(_("Cannot read index"));
|
2007-11-28 21:13:08 +00:00
|
|
|
|
2007-12-20 03:23:03 +00:00
|
|
|
if (amend)
|
|
|
|
parent = "HEAD^1";
|
|
|
|
|
2017-02-20 00:10:14 +00:00
|
|
|
if (get_sha1(parent, oid.hash)) {
|
2016-10-24 10:42:22 +00:00
|
|
|
int i, ita_nr = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < active_nr; i++)
|
|
|
|
if (ce_intent_to_add(active_cache[i]))
|
|
|
|
ita_nr++;
|
|
|
|
commitable = active_nr - ita_nr > 0;
|
|
|
|
} else {
|
2014-04-05 16:59:36 +00:00
|
|
|
/*
|
|
|
|
* Unless the user did explicitly request a submodule
|
|
|
|
* ignore mode by passing a command line option we do
|
|
|
|
* not ignore any changed submodule SHA-1s when
|
|
|
|
* comparing index and parent, no matter what is
|
|
|
|
* configured. Otherwise we won't commit any
|
|
|
|
* submodules which were manually staged, which would
|
|
|
|
* be really confusing.
|
|
|
|
*/
|
|
|
|
int diff_flags = DIFF_OPT_OVERRIDE_SUBMODULE_CONFIG;
|
|
|
|
if (ignore_submodule_arg &&
|
|
|
|
!strcmp(ignore_submodule_arg, "all"))
|
|
|
|
diff_flags |= DIFF_OPT_IGNORE_SUBMODULES;
|
2016-10-24 10:42:21 +00:00
|
|
|
commitable = index_differs_from(parent, diff_flags, 1);
|
2014-04-05 16:59:36 +00:00
|
|
|
}
|
2008-02-05 10:01:46 +00:00
|
|
|
}
|
2010-12-21 01:00:36 +00:00
|
|
|
strbuf_release(&committer_ident);
|
2007-12-23 03:22:29 +00:00
|
|
|
|
2011-02-26 05:10:49 +00:00
|
|
|
fclose(s->fp);
|
2007-11-28 21:13:08 +00:00
|
|
|
|
2011-02-20 04:12:29 +00:00
|
|
|
/*
|
|
|
|
* Reject an attempt to record a non-merge empty commit without
|
|
|
|
* explicit --allow-empty. In the cherry-pick case, it may be
|
|
|
|
* empty due to conflict resolution, which the user should okay.
|
|
|
|
*/
|
|
|
|
if (!commitable && whence != FROM_MERGE && !allow_empty &&
|
2011-08-19 18:58:18 +00:00
|
|
|
!(amend && is_a_merge(current_head))) {
|
2013-09-06 17:43:07 +00:00
|
|
|
s->display_comment_prefix = old_display_comment_prefix;
|
2009-08-10 04:59:30 +00:00
|
|
|
run_status(stdout, index_file, prefix, 0, s);
|
2010-06-07 00:41:46 +00:00
|
|
|
if (amend)
|
2011-02-22 23:41:49 +00:00
|
|
|
fputs(_(empty_amend_advice), stderr);
|
commit: tweak empty cherry pick advice for sequencer
When we refuse to make an empty commit, we check whether we
are in a cherry-pick in order to give better advice on how
to proceed. We instruct the user to repeat the commit with
"--allow-empty" to force the commit, or to use "git reset"
to skip it and abort the cherry-pick.
In the case of a single cherry-pick, the distinction between
skipping and aborting is not important, as there is no more
work to be done afterwards. When we are using the sequencer
to cherry pick a series of commits, though, the instruction
is confusing: does it skip this commit, or does it abort the
rest of the cherry-pick?
It does skip, after which the user can continue the
cherry-pick. This is the right thing to be advising the user
to do, but let's make it more clear what will happen, both
by using the word "skip", and by mentioning that the rest of
the sequence can be continued via "cherry-pick --continue"
(whether we skip or take the commit).
Noticed-by: Ramkumar Ramachandra <artagnon@gmail.com>
Helped-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-07-26 23:39:28 +00:00
|
|
|
else if (whence == FROM_CHERRY_PICK) {
|
2011-04-02 00:55:55 +00:00
|
|
|
fputs(_(empty_cherry_pick_advice), stderr);
|
commit: tweak empty cherry pick advice for sequencer
When we refuse to make an empty commit, we check whether we
are in a cherry-pick in order to give better advice on how
to proceed. We instruct the user to repeat the commit with
"--allow-empty" to force the commit, or to use "git reset"
to skip it and abort the cherry-pick.
In the case of a single cherry-pick, the distinction between
skipping and aborting is not important, as there is no more
work to be done afterwards. When we are using the sequencer
to cherry pick a series of commits, though, the instruction
is confusing: does it skip this commit, or does it abort the
rest of the cherry-pick?
It does skip, after which the user can continue the
cherry-pick. This is the right thing to be advising the user
to do, but let's make it more clear what will happen, both
by using the word "skip", and by mentioning that the rest of
the sequence can be continued via "cherry-pick --continue"
(whether we skip or take the commit).
Noticed-by: Ramkumar Ramachandra <artagnon@gmail.com>
Helped-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-07-26 23:39:28 +00:00
|
|
|
if (!sequencer_in_use)
|
|
|
|
fputs(_(empty_cherry_pick_advice_single), stderr);
|
|
|
|
else
|
|
|
|
fputs(_(empty_cherry_pick_advice_multi), stderr);
|
|
|
|
}
|
2008-02-05 10:01:46 +00:00
|
|
|
return 0;
|
2007-11-28 21:13:08 +00:00
|
|
|
}
|
|
|
|
|
2008-02-05 10:01:46 +00:00
|
|
|
/*
|
|
|
|
* Re-read the index as pre-commit hook could have updated it,
|
|
|
|
* and write it out as a tree. We must do this before we invoke
|
|
|
|
* the editor and after we invoke run_status above.
|
|
|
|
*/
|
|
|
|
discard_cache();
|
|
|
|
read_cache_from(index_file);
|
2011-12-06 17:43:37 +00:00
|
|
|
if (update_main_cache_tree(0)) {
|
2011-02-22 23:41:44 +00:00
|
|
|
error(_("Error building trees"));
|
2008-02-05 10:01:46 +00:00
|
|
|
return 0;
|
2007-11-28 21:13:08 +00:00
|
|
|
}
|
2007-11-08 16:59:00 +00:00
|
|
|
|
2014-03-18 10:00:53 +00:00
|
|
|
if (run_commit_hook(use_editor, index_file, "prepare-commit-msg",
|
2016-05-24 19:19:50 +00:00
|
|
|
git_path_commit_editmsg(), hook_arg1, hook_arg2, NULL))
|
2008-02-05 07:04:18 +00:00
|
|
|
return 0;
|
2007-11-08 16:59:00 +00:00
|
|
|
|
2008-02-05 10:01:46 +00:00
|
|
|
if (use_editor) {
|
2017-01-13 17:58:00 +00:00
|
|
|
struct argv_array env = ARGV_ARRAY_INIT;
|
|
|
|
|
|
|
|
argv_array_pushf(&env, "GIT_INDEX_FILE=%s", index_file);
|
|
|
|
if (launch_editor(git_path_commit_editmsg(), NULL, env.argv)) {
|
2008-07-25 16:28:42 +00:00
|
|
|
fprintf(stderr,
|
2011-02-22 23:41:44 +00:00
|
|
|
_("Please supply the message using either -m or -F option.\n"));
|
2008-07-25 16:28:42 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
2017-01-13 17:58:00 +00:00
|
|
|
argv_array_clear(&env);
|
2008-02-05 10:01:46 +00:00
|
|
|
}
|
2007-11-08 16:59:00 +00:00
|
|
|
|
2008-02-05 10:01:46 +00:00
|
|
|
if (!no_verify &&
|
2016-05-24 19:19:50 +00:00
|
|
|
run_commit_hook(use_editor, index_file, "commit-msg", git_path_commit_editmsg(), NULL)) {
|
2008-02-05 10:01:46 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2007-11-08 16:59:00 +00:00
|
|
|
|
2008-02-05 10:01:46 +00:00
|
|
|
return 1;
|
2007-11-08 16:59:00 +00:00
|
|
|
}
|
|
|
|
|
2012-03-30 19:14:33 +00:00
|
|
|
static int rest_is_empty(struct strbuf *sb, int start)
|
2007-11-08 16:59:00 +00:00
|
|
|
{
|
2012-03-30 19:14:33 +00:00
|
|
|
int i, eol;
|
2007-11-08 16:59:00 +00:00
|
|
|
const char *nl;
|
|
|
|
|
|
|
|
/* Check if the rest is just whitespace and Signed-of-by's. */
|
|
|
|
for (i = start; i < sb->len; i++) {
|
|
|
|
nl = memchr(sb->buf + i, '\n', sb->len - i);
|
|
|
|
if (nl)
|
|
|
|
eol = nl - sb->buf;
|
|
|
|
else
|
|
|
|
eol = sb->len;
|
|
|
|
|
|
|
|
if (strlen(sign_off_header) <= eol - i &&
|
2013-11-30 20:55:40 +00:00
|
|
|
starts_with(sb->buf + i, sign_off_header)) {
|
2007-11-08 16:59:00 +00:00
|
|
|
i = eol;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
while (i < eol)
|
|
|
|
if (!isspace(sb->buf[i++]))
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2012-03-30 19:14:33 +00:00
|
|
|
/*
|
|
|
|
* Find out if the message in the strbuf contains only whitespace and
|
|
|
|
* Signed-off-by lines.
|
|
|
|
*/
|
|
|
|
static int message_is_empty(struct strbuf *sb)
|
|
|
|
{
|
|
|
|
if (cleanup_mode == CLEANUP_NONE && sb->len)
|
|
|
|
return 0;
|
|
|
|
return rest_is_empty(sb, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* See if the user edited the message in the editor or left what
|
|
|
|
* was in the template intact
|
|
|
|
*/
|
|
|
|
static int template_untouched(struct strbuf *sb)
|
|
|
|
{
|
|
|
|
struct strbuf tmpl = STRBUF_INIT;
|
refactor skip_prefix to return a boolean
The skip_prefix() function returns a pointer to the content
past the prefix, or NULL if the prefix was not found. While
this is nice and simple, in practice it makes it hard to use
for two reasons:
1. When you want to conditionally skip or keep the string
as-is, you have to introduce a temporary variable.
For example:
tmp = skip_prefix(buf, "foo");
if (tmp)
buf = tmp;
2. It is verbose to check the outcome in a conditional, as
you need extra parentheses to silence compiler
warnings. For example:
if ((cp = skip_prefix(buf, "foo"))
/* do something with cp */
Both of these make it harder to use for long if-chains, and
we tend to use starts_with() instead. However, the first line
of "do something" is often to then skip forward in buf past
the prefix, either using a magic constant or with an extra
strlen(3) (which is generally computed at compile time, but
means we are repeating ourselves).
This patch refactors skip_prefix() to return a simple boolean,
and to provide the pointer value as an out-parameter. If the
prefix is not found, the out-parameter is untouched. This
lets you write:
if (skip_prefix(arg, "foo ", &arg))
do_foo(arg);
else if (skip_prefix(arg, "bar ", &arg))
do_bar(arg);
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2014-06-18 19:44:19 +00:00
|
|
|
const char *start;
|
2012-03-30 19:14:33 +00:00
|
|
|
|
|
|
|
if (cleanup_mode == CLEANUP_NONE && sb->len)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (!template_file || strbuf_read_file(&tmpl, template_file, 0) <= 0)
|
|
|
|
return 0;
|
|
|
|
|
2015-10-16 15:16:42 +00:00
|
|
|
strbuf_stripspace(&tmpl, cleanup_mode == CLEANUP_ALL);
|
refactor skip_prefix to return a boolean
The skip_prefix() function returns a pointer to the content
past the prefix, or NULL if the prefix was not found. While
this is nice and simple, in practice it makes it hard to use
for two reasons:
1. When you want to conditionally skip or keep the string
as-is, you have to introduce a temporary variable.
For example:
tmp = skip_prefix(buf, "foo");
if (tmp)
buf = tmp;
2. It is verbose to check the outcome in a conditional, as
you need extra parentheses to silence compiler
warnings. For example:
if ((cp = skip_prefix(buf, "foo"))
/* do something with cp */
Both of these make it harder to use for long if-chains, and
we tend to use starts_with() instead. However, the first line
of "do something" is often to then skip forward in buf past
the prefix, either using a magic constant or with an extra
strlen(3) (which is generally computed at compile time, but
means we are repeating ourselves).
This patch refactors skip_prefix() to return a simple boolean,
and to provide the pointer value as an out-parameter. If the
prefix is not found, the out-parameter is untouched. This
lets you write:
if (skip_prefix(arg, "foo ", &arg))
do_foo(arg);
else if (skip_prefix(arg, "bar ", &arg))
do_bar(arg);
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2014-06-18 19:44:19 +00:00
|
|
|
if (!skip_prefix(sb->buf, tmpl.buf, &start))
|
2012-03-30 19:14:33 +00:00
|
|
|
start = sb->buf;
|
|
|
|
strbuf_release(&tmpl);
|
|
|
|
return rest_is_empty(sb, start - sb->buf);
|
|
|
|
}
|
|
|
|
|
2008-08-27 06:13:13 +00:00
|
|
|
static const char *find_author_by_nickname(const char *name)
|
|
|
|
{
|
|
|
|
struct rev_info revs;
|
|
|
|
struct commit *commit;
|
|
|
|
struct strbuf buf = STRBUF_INIT;
|
2013-08-23 13:48:31 +00:00
|
|
|
struct string_list mailmap = STRING_LIST_INIT_NODUP;
|
2008-08-27 06:13:13 +00:00
|
|
|
const char *av[20];
|
|
|
|
int ac = 0;
|
|
|
|
|
|
|
|
init_revisions(&revs, NULL);
|
|
|
|
strbuf_addf(&buf, "--author=%s", name);
|
|
|
|
av[++ac] = "--all";
|
|
|
|
av[++ac] = "-i";
|
|
|
|
av[++ac] = buf.buf;
|
|
|
|
av[++ac] = NULL;
|
|
|
|
setup_revisions(ac, av, &revs, NULL);
|
2013-08-23 13:48:31 +00:00
|
|
|
revs.mailmap = &mailmap;
|
|
|
|
read_mailmap(revs.mailmap, NULL);
|
|
|
|
|
2014-08-10 21:33:26 +00:00
|
|
|
if (prepare_revision_walk(&revs))
|
|
|
|
die(_("revision walk setup failed"));
|
2008-08-27 06:13:13 +00:00
|
|
|
commit = get_revision(&revs);
|
|
|
|
if (commit) {
|
2009-10-19 15:48:08 +00:00
|
|
|
struct pretty_print_context ctx = {0};
|
convert "enum date_mode" into a struct
In preparation for adding date modes that may carry extra
information beyond the mode itself, this patch converts the
date_mode enum into a struct.
Most of the conversion is fairly straightforward; we pass
the struct as a pointer and dereference the type field where
necessary. Locations that declare a date_mode can use a "{}"
constructor. However, the tricky case is where we use the
enum labels as constants, like:
show_date(t, tz, DATE_NORMAL);
Ideally we could say:
show_date(t, tz, &{ DATE_NORMAL });
but of course C does not allow that. Likewise, we cannot
cast the constant to a struct, because we need to pass an
actual address. Our options are basically:
1. Manually add a "struct date_mode d = { DATE_NORMAL }"
definition to each caller, and pass "&d". This makes
the callers uglier, because they sometimes do not even
have their own scope (e.g., they are inside a switch
statement).
2. Provide a pre-made global "date_normal" struct that can
be passed by address. We'd also need "date_rfc2822",
"date_iso8601", and so forth. But at least the ugliness
is defined in one place.
3. Provide a wrapper that generates the correct struct on
the fly. The big downside is that we end up pointing to
a single global, which makes our wrapper non-reentrant.
But show_date is already not reentrant, so it does not
matter.
This patch implements 3, along with a minor macro to keep
the size of the callers sane.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-06-25 16:55:02 +00:00
|
|
|
ctx.date_mode.type = DATE_NORMAL;
|
2008-08-27 06:13:13 +00:00
|
|
|
strbuf_release(&buf);
|
2013-08-23 13:48:31 +00:00
|
|
|
format_commit_message(commit, "%aN <%aE>", &buf, &ctx);
|
|
|
|
clear_mailmap(&mailmap);
|
2008-08-27 06:13:13 +00:00
|
|
|
return strbuf_detach(&buf, NULL);
|
|
|
|
}
|
2015-01-26 15:48:33 +00:00
|
|
|
die(_("--author '%s' is not 'Name <email>' and matches no existing author"), name);
|
2008-08-27 06:13:13 +00:00
|
|
|
}
|
|
|
|
|
2009-08-08 06:31:57 +00:00
|
|
|
|
|
|
|
static void handle_untracked_files_arg(struct wt_status *s)
|
|
|
|
{
|
|
|
|
if (!untracked_files_arg)
|
|
|
|
; /* default already initialized */
|
|
|
|
else if (!strcmp(untracked_files_arg, "no"))
|
|
|
|
s->show_untracked_files = SHOW_NO_UNTRACKED_FILES;
|
|
|
|
else if (!strcmp(untracked_files_arg, "normal"))
|
|
|
|
s->show_untracked_files = SHOW_NORMAL_UNTRACKED_FILES;
|
|
|
|
else if (!strcmp(untracked_files_arg, "all"))
|
|
|
|
s->show_untracked_files = SHOW_ALL_UNTRACKED_FILES;
|
|
|
|
else
|
2011-02-22 23:41:44 +00:00
|
|
|
die(_("Invalid untracked files mode '%s'"), untracked_files_arg);
|
2009-08-08 06:31:57 +00:00
|
|
|
}
|
|
|
|
|
2011-02-20 04:12:29 +00:00
|
|
|
static const char *read_commit_message(const char *name)
|
|
|
|
{
|
2013-01-26 09:44:06 +00:00
|
|
|
const char *out_enc;
|
2011-02-20 04:12:29 +00:00
|
|
|
struct commit *commit;
|
|
|
|
|
|
|
|
commit = lookup_commit_reference_by_name(name);
|
|
|
|
if (!commit)
|
2011-04-02 00:55:55 +00:00
|
|
|
die(_("could not lookup commit %s"), name);
|
2011-02-20 04:12:29 +00:00
|
|
|
out_enc = get_commit_output_encoding();
|
2013-04-18 23:08:40 +00:00
|
|
|
return logmsg_reencode(commit, NULL, out_enc);
|
2011-02-20 04:12:29 +00:00
|
|
|
}
|
|
|
|
|
2013-06-24 18:41:40 +00:00
|
|
|
/*
|
|
|
|
* Enumerate what needs to be propagated when --porcelain
|
|
|
|
* is not in effect here.
|
|
|
|
*/
|
|
|
|
static struct status_deferred_config {
|
2016-08-05 22:00:27 +00:00
|
|
|
enum wt_status_format status_format;
|
2013-06-24 18:41:40 +00:00
|
|
|
int show_branch;
|
|
|
|
} status_deferred_config = {
|
|
|
|
STATUS_FORMAT_UNSPECIFIED,
|
|
|
|
-1 /* unspecified */
|
|
|
|
};
|
|
|
|
|
|
|
|
static void finalize_deferred_config(struct wt_status *s)
|
|
|
|
{
|
|
|
|
int use_deferred_config = (status_format != STATUS_FORMAT_PORCELAIN &&
|
2016-08-11 14:45:57 +00:00
|
|
|
status_format != STATUS_FORMAT_PORCELAIN_V2 &&
|
2013-06-24 18:41:40 +00:00
|
|
|
!s->null_termination);
|
|
|
|
|
|
|
|
if (s->null_termination) {
|
|
|
|
if (status_format == STATUS_FORMAT_NONE ||
|
|
|
|
status_format == STATUS_FORMAT_UNSPECIFIED)
|
|
|
|
status_format = STATUS_FORMAT_PORCELAIN;
|
|
|
|
else if (status_format == STATUS_FORMAT_LONG)
|
|
|
|
die(_("--long and -z are incompatible"));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (use_deferred_config && status_format == STATUS_FORMAT_UNSPECIFIED)
|
|
|
|
status_format = status_deferred_config.status_format;
|
|
|
|
if (status_format == STATUS_FORMAT_UNSPECIFIED)
|
|
|
|
status_format = STATUS_FORMAT_NONE;
|
|
|
|
|
|
|
|
if (use_deferred_config && s->show_branch < 0)
|
|
|
|
s->show_branch = status_deferred_config.show_branch;
|
|
|
|
if (s->show_branch < 0)
|
|
|
|
s->show_branch = 0;
|
|
|
|
}
|
|
|
|
|
2007-12-03 05:02:09 +00:00
|
|
|
static int parse_and_validate_options(int argc, const char *argv[],
|
2012-05-07 19:18:26 +00:00
|
|
|
const struct option *options,
|
2008-08-06 18:43:47 +00:00
|
|
|
const char * const usage[],
|
2009-08-10 04:59:30 +00:00
|
|
|
const char *prefix,
|
2011-08-19 18:58:18 +00:00
|
|
|
struct commit *current_head,
|
2009-08-10 04:59:30 +00:00
|
|
|
struct wt_status *s)
|
2007-11-08 16:59:00 +00:00
|
|
|
{
|
|
|
|
int f = 0;
|
|
|
|
|
2012-05-07 19:18:26 +00:00
|
|
|
argc = parse_options(argc, argv, prefix, options, usage, 0);
|
2013-06-24 18:41:40 +00:00
|
|
|
finalize_deferred_config(s);
|
2007-11-08 16:59:00 +00:00
|
|
|
|
2008-08-27 06:13:13 +00:00
|
|
|
if (force_author && !strchr(force_author, '>'))
|
|
|
|
force_author = find_author_by_nickname(force_author);
|
|
|
|
|
2009-11-04 03:20:11 +00:00
|
|
|
if (force_author && renew_authorship)
|
2011-02-22 23:41:44 +00:00
|
|
|
die(_("Using both --reset-author and --author does not make sense"));
|
2009-11-04 03:20:11 +00:00
|
|
|
|
2013-05-25 21:43:34 +00:00
|
|
|
if (logfile || have_option_m || use_message || fixup_message)
|
2007-12-23 03:25:37 +00:00
|
|
|
use_editor = 0;
|
2011-12-06 21:09:55 +00:00
|
|
|
if (0 <= edit_flag)
|
|
|
|
use_editor = edit_flag;
|
2007-11-08 16:59:00 +00:00
|
|
|
|
|
|
|
/* Sanity check options */
|
2011-08-19 18:58:18 +00:00
|
|
|
if (amend && !current_head)
|
2011-02-22 23:41:44 +00:00
|
|
|
die(_("You have nothing to amend."));
|
2012-04-30 15:33:13 +00:00
|
|
|
if (amend && whence != FROM_COMMIT) {
|
|
|
|
if (whence == FROM_MERGE)
|
|
|
|
die(_("You are in the middle of a merge -- cannot amend."));
|
|
|
|
else if (whence == FROM_CHERRY_PICK)
|
|
|
|
die(_("You are in the middle of a cherry-pick -- cannot amend."));
|
|
|
|
}
|
2010-11-02 19:59:11 +00:00
|
|
|
if (fixup_message && squash_message)
|
2011-02-22 23:41:45 +00:00
|
|
|
die(_("Options --squash and --fixup cannot be used together"));
|
2007-11-08 16:59:00 +00:00
|
|
|
if (use_message)
|
|
|
|
f++;
|
|
|
|
if (edit_message)
|
|
|
|
f++;
|
2010-11-02 19:59:09 +00:00
|
|
|
if (fixup_message)
|
|
|
|
f++;
|
2007-11-08 16:59:00 +00:00
|
|
|
if (logfile)
|
|
|
|
f++;
|
|
|
|
if (f > 1)
|
2011-02-22 23:41:44 +00:00
|
|
|
die(_("Only one of -c/-C/-F/--fixup can be used."));
|
commit: do not ignore an empty message given by -m ''
When f9568530 (builtin-commit: resurrect behavior for multiple -m
options, 2007-11-11) converted a "char *message" to "struct strbuf
message" to hold the messages given with the "-m" option, it
incorrectly changed the checks "did we get a message with the -m
option?" to "is message.len 0?". Later, we noticed one breakage
from this change and corrected it with 25206778 (commit: don't start
editor if empty message is given with -m, 2013-05-25).
However, "we got a message with -m, even though an empty one, so we
shouldn't be launching an editor" was not the only breakage.
* "git commit --amend -m '' --allow-empty", even though it looks
strange, is a valid request to amend the commit to have no
message at all. Due to the misdetection of the presence of -m on
the command line, we ended up keeping the log messsage from the
original commit.
* "git commit -m "$msg" -F file" should be rejected whether $msg is
an empty string or not, but due to the same bug, was not rejected
when $msg is empty.
* "git -c template=file -m "$msg"" should ignore the template even
when $msg is empty, but it didn't and instead used the contents
from the template file.
Correct these by checking have_option_m, which the earlier 25206778
introduced to fix the same bug.
Reported-by: Adam Dinwoodie <adam@dinwoodie.org>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2016-04-07 19:56:26 +00:00
|
|
|
if (have_option_m && f > 0)
|
2011-02-22 23:41:44 +00:00
|
|
|
die((_("Option -m cannot be combined with -c/-C/-F/--fixup.")));
|
commit: do not ignore an empty message given by -m ''
When f9568530 (builtin-commit: resurrect behavior for multiple -m
options, 2007-11-11) converted a "char *message" to "struct strbuf
message" to hold the messages given with the "-m" option, it
incorrectly changed the checks "did we get a message with the -m
option?" to "is message.len 0?". Later, we noticed one breakage
from this change and corrected it with 25206778 (commit: don't start
editor if empty message is given with -m, 2013-05-25).
However, "we got a message with -m, even though an empty one, so we
shouldn't be launching an editor" was not the only breakage.
* "git commit --amend -m '' --allow-empty", even though it looks
strange, is a valid request to amend the commit to have no
message at all. Due to the misdetection of the presence of -m on
the command line, we ended up keeping the log messsage from the
original commit.
* "git commit -m "$msg" -F file" should be rejected whether $msg is
an empty string or not, but due to the same bug, was not rejected
when $msg is empty.
* "git -c template=file -m "$msg"" should ignore the template even
when $msg is empty, but it didn't and instead used the contents
from the template file.
Correct these by checking have_option_m, which the earlier 25206778
introduced to fix the same bug.
Reported-by: Adam Dinwoodie <adam@dinwoodie.org>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2016-04-07 19:56:26 +00:00
|
|
|
if (f || have_option_m)
|
2012-03-30 18:30:59 +00:00
|
|
|
template_file = NULL;
|
2007-11-08 16:59:00 +00:00
|
|
|
if (edit_message)
|
|
|
|
use_message = edit_message;
|
2010-11-02 19:59:09 +00:00
|
|
|
if (amend && !use_message && !fixup_message)
|
2007-11-08 16:59:00 +00:00
|
|
|
use_message = "HEAD";
|
2011-02-20 04:12:29 +00:00
|
|
|
if (!use_message && whence != FROM_CHERRY_PICK && renew_authorship)
|
2011-02-22 23:41:44 +00:00
|
|
|
die(_("--reset-author can be used only with -C, -c or --amend."));
|
2007-11-08 16:59:00 +00:00
|
|
|
if (use_message) {
|
2011-02-20 04:12:29 +00:00
|
|
|
use_message_buffer = read_commit_message(use_message);
|
|
|
|
if (!renew_authorship) {
|
|
|
|
author_message = use_message;
|
|
|
|
author_message_buffer = use_message_buffer;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (whence == FROM_CHERRY_PICK && !renew_authorship) {
|
|
|
|
author_message = "CHERRY_PICK_HEAD";
|
|
|
|
author_message_buffer = read_commit_message(author_message);
|
2007-11-08 16:59:00 +00:00
|
|
|
}
|
|
|
|
|
2011-05-07 17:58:07 +00:00
|
|
|
if (patch_interactive)
|
|
|
|
interactive = 1;
|
|
|
|
|
2013-08-07 07:32:25 +00:00
|
|
|
if (also + only + all + interactive > 1)
|
2011-05-07 17:58:07 +00:00
|
|
|
die(_("Only one of --include/--only/--all/--interactive/--patch can be used."));
|
2016-12-02 22:15:13 +00:00
|
|
|
if (argc == 0 && (also || (only && !amend && !allow_empty)))
|
2011-02-22 23:41:44 +00:00
|
|
|
die(_("No paths with --include/--only does not make sense."));
|
2008-04-10 11:33:08 +00:00
|
|
|
if (argc > 0 && !also && !only)
|
2014-03-31 22:11:47 +00:00
|
|
|
only_include_assumed = _("Explicit paths specified without -i or -o; assuming --only paths...");
|
2007-12-22 18:46:24 +00:00
|
|
|
if (!cleanup_arg || !strcmp(cleanup_arg, "default"))
|
|
|
|
cleanup_mode = use_editor ? CLEANUP_ALL : CLEANUP_SPACE;
|
|
|
|
else if (!strcmp(cleanup_arg, "verbatim"))
|
|
|
|
cleanup_mode = CLEANUP_NONE;
|
|
|
|
else if (!strcmp(cleanup_arg, "whitespace"))
|
|
|
|
cleanup_mode = CLEANUP_SPACE;
|
|
|
|
else if (!strcmp(cleanup_arg, "strip"))
|
|
|
|
cleanup_mode = CLEANUP_ALL;
|
2014-02-17 12:15:32 +00:00
|
|
|
else if (!strcmp(cleanup_arg, "scissors"))
|
|
|
|
cleanup_mode = use_editor ? CLEANUP_SCISSORS : CLEANUP_SPACE;
|
2007-12-22 18:46:24 +00:00
|
|
|
else
|
2011-02-22 23:41:44 +00:00
|
|
|
die(_("Invalid cleanup mode %s"), cleanup_arg);
|
2007-11-08 16:59:00 +00:00
|
|
|
|
2009-08-08 06:31:57 +00:00
|
|
|
handle_untracked_files_arg(s);
|
2008-06-05 08:31:19 +00:00
|
|
|
|
2007-11-08 16:59:00 +00:00
|
|
|
if (all && argc > 0)
|
2011-02-22 23:41:44 +00:00
|
|
|
die(_("Paths with -a does not make sense."));
|
2007-11-08 16:59:00 +00:00
|
|
|
|
2012-10-18 14:15:50 +00:00
|
|
|
if (status_format != STATUS_FORMAT_NONE)
|
2009-09-05 08:59:56 +00:00
|
|
|
dry_run = 1;
|
|
|
|
|
2007-11-08 16:59:00 +00:00
|
|
|
return argc;
|
|
|
|
}
|
|
|
|
|
2009-08-10 04:59:30 +00:00
|
|
|
static int dry_run_commit(int argc, const char **argv, const char *prefix,
|
2011-08-19 18:58:18 +00:00
|
|
|
const struct commit *current_head, struct wt_status *s)
|
2007-11-08 16:59:00 +00:00
|
|
|
{
|
|
|
|
int commitable;
|
2009-08-08 06:03:36 +00:00
|
|
|
const char *index_file;
|
2007-11-08 16:59:00 +00:00
|
|
|
|
2011-08-19 18:58:18 +00:00
|
|
|
index_file = prepare_index(argc, argv, prefix, current_head, 1);
|
2009-08-10 04:59:30 +00:00
|
|
|
commitable = run_status(stdout, index_file, prefix, 0, s);
|
2009-08-08 06:03:36 +00:00
|
|
|
rollback_index_files();
|
2007-11-08 16:59:00 +00:00
|
|
|
|
2009-08-08 06:03:36 +00:00
|
|
|
return commitable ? 0 : 1;
|
|
|
|
}
|
|
|
|
|
2014-10-07 19:16:57 +00:00
|
|
|
static int parse_status_slot(const char *slot)
|
2009-08-10 06:12:19 +00:00
|
|
|
{
|
2014-10-07 19:16:57 +00:00
|
|
|
if (!strcasecmp(slot, "header"))
|
2009-08-10 06:12:19 +00:00
|
|
|
return WT_STATUS_HEADER;
|
2014-10-07 19:16:57 +00:00
|
|
|
if (!strcasecmp(slot, "branch"))
|
2010-11-17 23:40:05 +00:00
|
|
|
return WT_STATUS_ONBRANCH;
|
2014-10-07 19:16:57 +00:00
|
|
|
if (!strcasecmp(slot, "updated") || !strcasecmp(slot, "added"))
|
2009-08-10 06:12:19 +00:00
|
|
|
return WT_STATUS_UPDATED;
|
2014-10-07 19:16:57 +00:00
|
|
|
if (!strcasecmp(slot, "changed"))
|
2009-08-10 06:12:19 +00:00
|
|
|
return WT_STATUS_CHANGED;
|
2014-10-07 19:16:57 +00:00
|
|
|
if (!strcasecmp(slot, "untracked"))
|
2009-08-10 06:12:19 +00:00
|
|
|
return WT_STATUS_UNTRACKED;
|
2014-10-07 19:16:57 +00:00
|
|
|
if (!strcasecmp(slot, "nobranch"))
|
2009-08-10 06:12:19 +00:00
|
|
|
return WT_STATUS_NOBRANCH;
|
2014-10-07 19:16:57 +00:00
|
|
|
if (!strcasecmp(slot, "unmerged"))
|
2009-08-10 06:12:19 +00:00
|
|
|
return WT_STATUS_UNMERGED;
|
ignore unknown color configuration
When parsing the config file, if there is a value that is
syntactically correct but unused, we generally ignore it.
This lets non-core porcelains store arbitrary information in
the config file, and it means that configuration files can
be shared between new and old versions of git (the old
versions might simply ignore certain configuration).
The one exception to this is color configuration; if we
encounter a color.{diff,branch,status}.$slot variable, we
die if it is not one of the recognized slots (presumably as
a safety valve for user misconfiguration). This behavior
has existed since 801235c (diff --color: use
$GIT_DIR/config, 2006-06-24), but hasn't yet caused a
problem. No porcelain has wanted to store extra colors, and
we once a color area (like color.diff) has been introduced,
we've never changed the set of color slots.
However, that changed recently with the addition of
color.diff.func. Now a user with color.diff.func in their
config can no longer freely switch between v1.6.6 and older
versions; the old versions will complain about the existence
of the variable.
This patch loosens the check to match the rest of
git-config; unknown color slots are simply ignored. This
doesn't fix this particular problem, as the older version
(without this patch) is the problem, but it at least
prevents it from happening again in the future.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-12-12 12:25:24 +00:00
|
|
|
return -1;
|
2009-08-10 06:12:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int git_status_config(const char *k, const char *v, void *cb)
|
|
|
|
{
|
|
|
|
struct wt_status *s = cb;
|
2014-10-04 18:54:50 +00:00
|
|
|
const char *slot_name;
|
2009-08-10 06:12:19 +00:00
|
|
|
|
2013-11-30 20:55:40 +00:00
|
|
|
if (starts_with(k, "column."))
|
2012-05-07 19:35:03 +00:00
|
|
|
return git_column_config(k, v, "status", &s->colopts);
|
2009-08-10 06:12:19 +00:00
|
|
|
if (!strcmp(k, "status.submodulesummary")) {
|
|
|
|
int is_bool;
|
|
|
|
s->submodule_summary = git_config_bool_or_int(k, v, &is_bool);
|
|
|
|
if (is_bool && s->submodule_summary)
|
|
|
|
s->submodule_summary = -1;
|
|
|
|
return 0;
|
|
|
|
}
|
2013-06-11 13:34:04 +00:00
|
|
|
if (!strcmp(k, "status.short")) {
|
|
|
|
if (git_config_bool(k, v))
|
2013-06-24 18:41:40 +00:00
|
|
|
status_deferred_config.status_format = STATUS_FORMAT_SHORT;
|
2013-06-11 13:34:04 +00:00
|
|
|
else
|
2013-06-24 18:41:40 +00:00
|
|
|
status_deferred_config.status_format = STATUS_FORMAT_NONE;
|
2013-06-11 13:34:04 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2013-06-11 13:34:05 +00:00
|
|
|
if (!strcmp(k, "status.branch")) {
|
2013-06-24 18:41:40 +00:00
|
|
|
status_deferred_config.show_branch = git_config_bool(k, v);
|
2013-06-11 13:34:05 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2009-08-10 06:12:19 +00:00
|
|
|
if (!strcmp(k, "status.color") || !strcmp(k, "color.status")) {
|
2011-08-18 05:03:48 +00:00
|
|
|
s->use_color = git_config_colorbool(k, v);
|
2009-08-10 06:12:19 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2013-09-06 17:43:07 +00:00
|
|
|
if (!strcmp(k, "status.displaycommentprefix")) {
|
|
|
|
s->display_comment_prefix = git_config_bool(k, v);
|
|
|
|
return 0;
|
|
|
|
}
|
2014-10-04 18:54:50 +00:00
|
|
|
if (skip_prefix(k, "status.color.", &slot_name) ||
|
|
|
|
skip_prefix(k, "color.status.", &slot_name)) {
|
2014-10-20 19:23:48 +00:00
|
|
|
int slot = parse_status_slot(slot_name);
|
ignore unknown color configuration
When parsing the config file, if there is a value that is
syntactically correct but unused, we generally ignore it.
This lets non-core porcelains store arbitrary information in
the config file, and it means that configuration files can
be shared between new and old versions of git (the old
versions might simply ignore certain configuration).
The one exception to this is color configuration; if we
encounter a color.{diff,branch,status}.$slot variable, we
die if it is not one of the recognized slots (presumably as
a safety valve for user misconfiguration). This behavior
has existed since 801235c (diff --color: use
$GIT_DIR/config, 2006-06-24), but hasn't yet caused a
problem. No porcelain has wanted to store extra colors, and
we once a color area (like color.diff) has been introduced,
we've never changed the set of color slots.
However, that changed recently with the addition of
color.diff.func. Now a user with color.diff.func in their
config can no longer freely switch between v1.6.6 and older
versions; the old versions will complain about the existence
of the variable.
This patch loosens the check to match the rest of
git-config; unknown color slots are simply ignored. This
doesn't fix this particular problem, as the older version
(without this patch) is the problem, but it at least
prevents it from happening again in the future.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-12-12 12:25:24 +00:00
|
|
|
if (slot < 0)
|
|
|
|
return 0;
|
2009-08-10 06:12:19 +00:00
|
|
|
if (!v)
|
|
|
|
return config_error_nonbool(k);
|
2014-10-07 19:33:09 +00:00
|
|
|
return color_parse(v, s->color_palette[slot]);
|
2009-08-10 06:12:19 +00:00
|
|
|
}
|
|
|
|
if (!strcmp(k, "status.relativepaths")) {
|
|
|
|
s->relative_paths = git_config_bool(k, v);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (!strcmp(k, "status.showuntrackedfiles")) {
|
|
|
|
if (!v)
|
|
|
|
return config_error_nonbool(k);
|
|
|
|
else if (!strcmp(v, "no"))
|
|
|
|
s->show_untracked_files = SHOW_NO_UNTRACKED_FILES;
|
|
|
|
else if (!strcmp(v, "normal"))
|
|
|
|
s->show_untracked_files = SHOW_NORMAL_UNTRACKED_FILES;
|
|
|
|
else if (!strcmp(v, "all"))
|
|
|
|
s->show_untracked_files = SHOW_ALL_UNTRACKED_FILES;
|
|
|
|
else
|
2011-02-22 23:41:44 +00:00
|
|
|
return error(_("Invalid untracked files mode '%s'"), v);
|
2009-08-10 06:12:19 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return git_diff_ui_config(k, v, NULL);
|
|
|
|
}
|
|
|
|
|
2009-08-08 06:03:36 +00:00
|
|
|
int cmd_status(int argc, const char **argv, const char *prefix)
|
|
|
|
{
|
2012-05-07 19:18:26 +00:00
|
|
|
static struct wt_status s;
|
2010-04-02 21:44:21 +00:00
|
|
|
int fd;
|
2017-02-20 00:10:14 +00:00
|
|
|
struct object_id oid;
|
2009-08-15 09:27:39 +00:00
|
|
|
static struct option builtin_status_options[] = {
|
2012-08-20 12:32:37 +00:00
|
|
|
OPT__VERBOSE(&verbose, N_("be verbose")),
|
2009-09-05 08:54:14 +00:00
|
|
|
OPT_SET_INT('s', "short", &status_format,
|
2012-08-20 12:32:37 +00:00
|
|
|
N_("show status concisely"), STATUS_FORMAT_SHORT),
|
2013-06-24 18:41:40 +00:00
|
|
|
OPT_BOOL('b', "branch", &s.show_branch,
|
|
|
|
N_("show branch information")),
|
2016-08-05 22:00:28 +00:00
|
|
|
{ OPTION_CALLBACK, 0, "porcelain", &status_format,
|
|
|
|
N_("version"), N_("machine-readable output"),
|
|
|
|
PARSE_OPT_OPTARG, opt_parse_porcelain },
|
2012-10-18 14:15:50 +00:00
|
|
|
OPT_SET_INT(0, "long", &status_format,
|
|
|
|
N_("show status in long format (default)"),
|
|
|
|
STATUS_FORMAT_LONG),
|
2013-08-03 11:51:19 +00:00
|
|
|
OPT_BOOL('z', "null", &s.null_termination,
|
|
|
|
N_("terminate entries with NUL")),
|
2009-08-08 06:31:57 +00:00
|
|
|
{ OPTION_STRING, 'u', "untracked-files", &untracked_files_arg,
|
2012-08-20 12:32:37 +00:00
|
|
|
N_("mode"),
|
|
|
|
N_("show untracked files, optional modes: all, normal, no. (Default: all)"),
|
2009-08-08 06:31:57 +00:00
|
|
|
PARSE_OPT_OPTARG, NULL, (intptr_t)"all" },
|
2013-08-03 11:51:19 +00:00
|
|
|
OPT_BOOL(0, "ignored", &show_ignored_in_status,
|
|
|
|
N_("show ignored files")),
|
2012-08-20 12:32:37 +00:00
|
|
|
{ OPTION_STRING, 0, "ignore-submodules", &ignore_submodule_arg, N_("when"),
|
|
|
|
N_("ignore changes to submodules, optional when: all, dirty, untracked. (Default: all)"),
|
2010-06-25 14:56:47 +00:00
|
|
|
PARSE_OPT_OPTARG, NULL, (intptr_t)"all" },
|
2012-08-20 12:32:04 +00:00
|
|
|
OPT_COLUMN(0, "column", &s.colopts, N_("list untracked files in columns")),
|
2009-08-08 06:31:57 +00:00
|
|
|
OPT_END(),
|
|
|
|
};
|
|
|
|
|
2010-10-22 06:45:47 +00:00
|
|
|
if (argc == 2 && !strcmp(argv[1], "-h"))
|
|
|
|
usage_with_options(builtin_status_usage, builtin_status_options);
|
|
|
|
|
2013-09-12 10:50:04 +00:00
|
|
|
status_init_config(&s, git_status_config);
|
2009-08-08 06:31:57 +00:00
|
|
|
argc = parse_options(argc, argv, prefix,
|
2009-08-15 09:27:39 +00:00
|
|
|
builtin_status_options,
|
|
|
|
builtin_status_usage, 0);
|
2012-05-07 19:35:03 +00:00
|
|
|
finalize_colopts(&s.colopts, -1);
|
2013-06-24 18:41:40 +00:00
|
|
|
finalize_deferred_config(&s);
|
2011-05-26 20:43:21 +00:00
|
|
|
|
2009-08-08 06:31:57 +00:00
|
|
|
handle_untracked_files_arg(&s);
|
2010-04-10 07:33:17 +00:00
|
|
|
if (show_ignored_in_status)
|
|
|
|
s.show_ignored_files = 1;
|
2013-07-14 08:35:39 +00:00
|
|
|
parse_pathspec(&s.pathspec, 0,
|
|
|
|
PATHSPEC_PREFER_FULL,
|
|
|
|
prefix, argv);
|
2009-08-08 06:31:57 +00:00
|
|
|
|
2013-07-14 08:35:49 +00:00
|
|
|
read_cache_preload(&s.pathspec);
|
2013-07-14 08:35:54 +00:00
|
|
|
refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED, &s.pathspec, NULL, NULL);
|
2010-04-02 21:44:21 +00:00
|
|
|
|
|
|
|
fd = hold_locked_index(&index_lock, 0);
|
|
|
|
|
2017-02-20 00:10:14 +00:00
|
|
|
s.is_initial = get_sha1(s.reference, oid.hash) ? 1 : 0;
|
2016-08-11 14:45:59 +00:00
|
|
|
if (!s.is_initial)
|
2017-02-20 00:10:14 +00:00
|
|
|
hashcpy(s.sha1_commit, oid.hash);
|
2016-08-11 14:45:59 +00:00
|
|
|
|
2010-06-25 14:56:47 +00:00
|
|
|
s.ignore_submodule_arg = ignore_submodule_arg;
|
2016-08-05 22:00:27 +00:00
|
|
|
s.status_format = status_format;
|
|
|
|
s.verbose = verbose;
|
|
|
|
|
2009-08-08 06:31:57 +00:00
|
|
|
wt_status_collect(&s);
|
|
|
|
|
2015-03-08 10:12:41 +00:00
|
|
|
if (0 <= fd)
|
|
|
|
update_index_if_able(&the_index, &index_lock);
|
|
|
|
|
2009-12-07 05:26:25 +00:00
|
|
|
if (s.relative_paths)
|
|
|
|
s.prefix = prefix;
|
2009-01-08 18:53:05 +00:00
|
|
|
|
2016-08-05 22:00:27 +00:00
|
|
|
wt_status_print(&s);
|
2009-08-08 06:31:57 +00:00
|
|
|
return 0;
|
2007-11-08 16:59:00 +00:00
|
|
|
}
|
|
|
|
|
2014-07-25 19:11:36 +00:00
|
|
|
static const char *implicit_ident_advice(void)
|
|
|
|
{
|
2017-04-05 10:24:38 +00:00
|
|
|
char *user_config = expand_user_path("~/.gitconfig", 0);
|
2015-05-06 08:01:02 +00:00
|
|
|
char *xdg_config = xdg_config_home("config");
|
|
|
|
int config_exists = file_exists(user_config) || file_exists(xdg_config);
|
2014-07-25 19:11:36 +00:00
|
|
|
|
|
|
|
free(user_config);
|
|
|
|
free(xdg_config);
|
|
|
|
|
|
|
|
if (config_exists)
|
|
|
|
return _(implicit_ident_advice_config);
|
|
|
|
else
|
|
|
|
return _(implicit_ident_advice_noconfig);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-02-20 00:10:14 +00:00
|
|
|
static void print_summary(const char *prefix, const struct object_id *oid,
|
2011-08-19 18:58:18 +00:00
|
|
|
int initial_commit)
|
2007-11-08 16:59:00 +00:00
|
|
|
{
|
|
|
|
struct rev_info rev;
|
|
|
|
struct commit *commit;
|
commit: show interesting ident information in summary
There are a few cases of user identity information that we consider
interesting:
(1) When the author and committer identities do not match.
(2) When the committer identity was picked automatically from the
username, hostname and GECOS information.
In these cases, we already show the information in the commit
message template. However, users do not always see that template
because they might use "-m" or "-F". With this patch, we show these
interesting cases after the commit, along with the subject and
change summary. The new output looks like:
$ git commit \
-m "federalist papers" \
--author='Publius <alexander@hamilton.com>'
[master 3d226a7] federalist papers
Author: Publius <alexander@hamilton.com>
1 files changed, 1 insertions(+), 0 deletions(-)
for case (1), and:
$ git config --global --unset user.name
$ git config --global --unset user.email
$ git commit -m foo
[master 7c2a927] foo
Committer: Jeff King <peff@c-71-185-130-222.hsd1.va.comcast.net>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly:
git config --global user.name Your Name
git config --global user.email you@example.com
If the identity used for this commit is wrong, you can fix it with:
git commit --amend --author='Your Name <you@example.com>'
1 files changed, 1 insertions(+), 0 deletions(-)
for case (2).
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-01-13 17:39:51 +00:00
|
|
|
struct strbuf format = STRBUF_INIT;
|
2017-02-20 00:10:14 +00:00
|
|
|
struct object_id junk_oid;
|
2011-11-13 10:22:15 +00:00
|
|
|
const char *head;
|
commit: show interesting ident information in summary
There are a few cases of user identity information that we consider
interesting:
(1) When the author and committer identities do not match.
(2) When the committer identity was picked automatically from the
username, hostname and GECOS information.
In these cases, we already show the information in the commit
message template. However, users do not always see that template
because they might use "-m" or "-F". With this patch, we show these
interesting cases after the commit, along with the subject and
change summary. The new output looks like:
$ git commit \
-m "federalist papers" \
--author='Publius <alexander@hamilton.com>'
[master 3d226a7] federalist papers
Author: Publius <alexander@hamilton.com>
1 files changed, 1 insertions(+), 0 deletions(-)
for case (1), and:
$ git config --global --unset user.name
$ git config --global --unset user.email
$ git commit -m foo
[master 7c2a927] foo
Committer: Jeff King <peff@c-71-185-130-222.hsd1.va.comcast.net>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly:
git config --global user.name Your Name
git config --global user.email you@example.com
If the identity used for this commit is wrong, you can fix it with:
git commit --amend --author='Your Name <you@example.com>'
1 files changed, 1 insertions(+), 0 deletions(-)
for case (2).
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-01-13 17:39:51 +00:00
|
|
|
struct pretty_print_context pctx = {0};
|
|
|
|
struct strbuf author_ident = STRBUF_INIT;
|
|
|
|
struct strbuf committer_ident = STRBUF_INIT;
|
2007-11-08 16:59:00 +00:00
|
|
|
|
2017-02-20 00:10:14 +00:00
|
|
|
commit = lookup_commit(oid->hash);
|
2007-11-08 16:59:00 +00:00
|
|
|
if (!commit)
|
2011-02-22 23:41:44 +00:00
|
|
|
die(_("couldn't look up newly created commit"));
|
2013-10-24 08:53:19 +00:00
|
|
|
if (parse_commit(commit))
|
2011-02-22 23:41:44 +00:00
|
|
|
die(_("could not parse newly created commit"));
|
2007-11-08 16:59:00 +00:00
|
|
|
|
commit: show interesting ident information in summary
There are a few cases of user identity information that we consider
interesting:
(1) When the author and committer identities do not match.
(2) When the committer identity was picked automatically from the
username, hostname and GECOS information.
In these cases, we already show the information in the commit
message template. However, users do not always see that template
because they might use "-m" or "-F". With this patch, we show these
interesting cases after the commit, along with the subject and
change summary. The new output looks like:
$ git commit \
-m "federalist papers" \
--author='Publius <alexander@hamilton.com>'
[master 3d226a7] federalist papers
Author: Publius <alexander@hamilton.com>
1 files changed, 1 insertions(+), 0 deletions(-)
for case (1), and:
$ git config --global --unset user.name
$ git config --global --unset user.email
$ git commit -m foo
[master 7c2a927] foo
Committer: Jeff King <peff@c-71-185-130-222.hsd1.va.comcast.net>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly:
git config --global user.name Your Name
git config --global user.email you@example.com
If the identity used for this commit is wrong, you can fix it with:
git commit --amend --author='Your Name <you@example.com>'
1 files changed, 1 insertions(+), 0 deletions(-)
for case (2).
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-01-13 17:39:51 +00:00
|
|
|
strbuf_addstr(&format, "format:%h] %s");
|
|
|
|
|
|
|
|
format_commit_message(commit, "%an <%ae>", &author_ident, &pctx);
|
|
|
|
format_commit_message(commit, "%cn <%ce>", &committer_ident, &pctx);
|
|
|
|
if (strbuf_cmp(&author_ident, &committer_ident)) {
|
|
|
|
strbuf_addstr(&format, "\n Author: ");
|
|
|
|
strbuf_addbuf_percentquote(&format, &author_ident);
|
|
|
|
}
|
2014-05-02 01:10:01 +00:00
|
|
|
if (author_date_is_interesting()) {
|
|
|
|
struct strbuf date = STRBUF_INIT;
|
|
|
|
format_commit_message(commit, "%ad", &date, &pctx);
|
|
|
|
strbuf_addstr(&format, "\n Date: ");
|
|
|
|
strbuf_addbuf_percentquote(&format, &date);
|
|
|
|
strbuf_release(&date);
|
|
|
|
}
|
ident: keep separate "explicit" flags for author and committer
We keep track of whether the user ident was given to us
explicitly, or if we guessed at it from system parameters
like username and hostname. However, we kept only a single
variable. This covers the common cases (because the author
and committer will usually come from the same explicit
source), but can miss two cases:
1. GIT_COMMITTER_* is set explicitly, but we fallback for
GIT_AUTHOR. We claim the ident is explicit, even though
the author is not.
2. GIT_AUTHOR_* is set and we ask for author ident, but
not committer ident. We will claim the ident is
implicit, even though it is explicit.
This patch uses two variables instead of one, updates both
when we set the "fallback" values, and updates them
individually when we read from the environment.
Rather than keep user_ident_sufficiently_given as a
compatibility wrapper, we update the only two callers to
check the committer_ident, which matches their intent and
what was happening already.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-11-15 00:34:13 +00:00
|
|
|
if (!committer_ident_sufficiently_given()) {
|
commit: show interesting ident information in summary
There are a few cases of user identity information that we consider
interesting:
(1) When the author and committer identities do not match.
(2) When the committer identity was picked automatically from the
username, hostname and GECOS information.
In these cases, we already show the information in the commit
message template. However, users do not always see that template
because they might use "-m" or "-F". With this patch, we show these
interesting cases after the commit, along with the subject and
change summary. The new output looks like:
$ git commit \
-m "federalist papers" \
--author='Publius <alexander@hamilton.com>'
[master 3d226a7] federalist papers
Author: Publius <alexander@hamilton.com>
1 files changed, 1 insertions(+), 0 deletions(-)
for case (1), and:
$ git config --global --unset user.name
$ git config --global --unset user.email
$ git commit -m foo
[master 7c2a927] foo
Committer: Jeff King <peff@c-71-185-130-222.hsd1.va.comcast.net>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly:
git config --global user.name Your Name
git config --global user.email you@example.com
If the identity used for this commit is wrong, you can fix it with:
git commit --amend --author='Your Name <you@example.com>'
1 files changed, 1 insertions(+), 0 deletions(-)
for case (2).
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-01-13 17:39:51 +00:00
|
|
|
strbuf_addstr(&format, "\n Committer: ");
|
|
|
|
strbuf_addbuf_percentquote(&format, &committer_ident);
|
2010-01-13 20:17:08 +00:00
|
|
|
if (advice_implicit_identity) {
|
|
|
|
strbuf_addch(&format, '\n');
|
2014-07-25 19:11:36 +00:00
|
|
|
strbuf_addstr(&format, implicit_ident_advice());
|
2010-01-13 20:17:08 +00:00
|
|
|
}
|
commit: show interesting ident information in summary
There are a few cases of user identity information that we consider
interesting:
(1) When the author and committer identities do not match.
(2) When the committer identity was picked automatically from the
username, hostname and GECOS information.
In these cases, we already show the information in the commit
message template. However, users do not always see that template
because they might use "-m" or "-F". With this patch, we show these
interesting cases after the commit, along with the subject and
change summary. The new output looks like:
$ git commit \
-m "federalist papers" \
--author='Publius <alexander@hamilton.com>'
[master 3d226a7] federalist papers
Author: Publius <alexander@hamilton.com>
1 files changed, 1 insertions(+), 0 deletions(-)
for case (1), and:
$ git config --global --unset user.name
$ git config --global --unset user.email
$ git commit -m foo
[master 7c2a927] foo
Committer: Jeff King <peff@c-71-185-130-222.hsd1.va.comcast.net>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly:
git config --global user.name Your Name
git config --global user.email you@example.com
If the identity used for this commit is wrong, you can fix it with:
git commit --amend --author='Your Name <you@example.com>'
1 files changed, 1 insertions(+), 0 deletions(-)
for case (2).
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-01-13 17:39:51 +00:00
|
|
|
}
|
|
|
|
strbuf_release(&author_ident);
|
|
|
|
strbuf_release(&committer_ident);
|
|
|
|
|
2007-11-08 16:59:00 +00:00
|
|
|
init_revisions(&rev, prefix);
|
|
|
|
setup_revisions(0, NULL, &rev, NULL);
|
|
|
|
|
|
|
|
rev.diff = 1;
|
|
|
|
rev.diffopt.output_format =
|
|
|
|
DIFF_FORMAT_SHORTSTAT | DIFF_FORMAT_SUMMARY;
|
|
|
|
|
|
|
|
rev.verbose_header = 1;
|
|
|
|
rev.show_root_diff = 1;
|
commit: show interesting ident information in summary
There are a few cases of user identity information that we consider
interesting:
(1) When the author and committer identities do not match.
(2) When the committer identity was picked automatically from the
username, hostname and GECOS information.
In these cases, we already show the information in the commit
message template. However, users do not always see that template
because they might use "-m" or "-F". With this patch, we show these
interesting cases after the commit, along with the subject and
change summary. The new output looks like:
$ git commit \
-m "federalist papers" \
--author='Publius <alexander@hamilton.com>'
[master 3d226a7] federalist papers
Author: Publius <alexander@hamilton.com>
1 files changed, 1 insertions(+), 0 deletions(-)
for case (1), and:
$ git config --global --unset user.name
$ git config --global --unset user.email
$ git commit -m foo
[master 7c2a927] foo
Committer: Jeff King <peff@c-71-185-130-222.hsd1.va.comcast.net>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly:
git config --global user.name Your Name
git config --global user.email you@example.com
If the identity used for this commit is wrong, you can fix it with:
git commit --amend --author='Your Name <you@example.com>'
1 files changed, 1 insertions(+), 0 deletions(-)
for case (2).
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-01-13 17:39:51 +00:00
|
|
|
get_commit_format(format.buf, &rev);
|
2007-12-11 05:02:26 +00:00
|
|
|
rev.always_show_header = 0;
|
2007-12-16 23:05:39 +00:00
|
|
|
rev.diffopt.detect_rename = 1;
|
|
|
|
rev.diffopt.break_opt = 0;
|
2007-12-16 23:03:58 +00:00
|
|
|
diff_setup_done(&rev.diffopt);
|
2007-11-08 16:59:00 +00:00
|
|
|
|
2017-02-20 00:10:14 +00:00
|
|
|
head = resolve_ref_unsafe("HEAD", 0, junk_oid.hash, NULL);
|
2014-10-04 18:54:50 +00:00
|
|
|
if (!strcmp(head, "HEAD"))
|
|
|
|
head = _("detached HEAD");
|
|
|
|
else
|
|
|
|
skip_prefix(head, "refs/heads/", &head);
|
|
|
|
printf("[%s%s ", head, initial_commit ? _(" (root-commit)") : "");
|
2007-11-08 16:59:00 +00:00
|
|
|
|
2007-12-11 05:02:26 +00:00
|
|
|
if (!log_tree_commit(&rev, commit)) {
|
commit::print_summary(): don't use format_commit_message()
This attempts to fix a regression in git-commit, where non-abbreviated
SHA-1s were printed in the summary.
One possible fix would be to set ctx.abbrev to DEFAULT_ABBREV in the
`if` block, where format_commit_message() is used.
Instead, we do away with the format_commit_message() codeblock
altogether, replacing it with a re-run of log_tree_commit().
We re-run log_tree_commit() with rev.always_show_header set, to force
the invocation of show_log(). The effect of this flag can be seen from
this excerpt from log-tree.c:560, the only area that
rev.always_show_header is checked:
shown = log_tree_diff(opt, commit, &log);
if (!shown && opt->loginfo && opt->always_show_header) {
log.parent = NULL;
show_log(opt);
shown = 1;
}
We also set rev.use_terminator, so that a newline is appended at the end
of the log message. Note that callers in builtin/log.c that also set
rev.always_show_header don't have to set rev.use_terminator, but still
get a newline, because they are wrapped in a pager.
Signed-off-by: Tay Ray Chuan <rctay89@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-06-12 14:15:39 +00:00
|
|
|
rev.always_show_header = 1;
|
|
|
|
rev.use_terminator = 1;
|
|
|
|
log_tree_commit(&rev, commit);
|
2007-12-11 05:02:26 +00:00
|
|
|
}
|
commit::print_summary(): don't use format_commit_message()
This attempts to fix a regression in git-commit, where non-abbreviated
SHA-1s were printed in the summary.
One possible fix would be to set ctx.abbrev to DEFAULT_ABBREV in the
`if` block, where format_commit_message() is used.
Instead, we do away with the format_commit_message() codeblock
altogether, replacing it with a re-run of log_tree_commit().
We re-run log_tree_commit() with rev.always_show_header set, to force
the invocation of show_log(). The effect of this flag can be seen from
this excerpt from log-tree.c:560, the only area that
rev.always_show_header is checked:
shown = log_tree_diff(opt, commit, &log);
if (!shown && opt->loginfo && opt->always_show_header) {
log.parent = NULL;
show_log(opt);
shown = 1;
}
We also set rev.use_terminator, so that a newline is appended at the end
of the log message. Note that callers in builtin/log.c that also set
rev.always_show_header don't have to set rev.use_terminator, but still
get a newline, because they are wrapped in a pager.
Signed-off-by: Tay Ray Chuan <rctay89@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-06-12 14:15:39 +00:00
|
|
|
|
2010-01-17 08:57:51 +00:00
|
|
|
strbuf_release(&format);
|
2007-11-08 16:59:00 +00:00
|
|
|
}
|
|
|
|
|
2008-07-23 23:09:35 +00:00
|
|
|
static int git_commit_config(const char *k, const char *v, void *cb)
|
2007-11-08 16:59:00 +00:00
|
|
|
{
|
2009-08-10 04:59:30 +00:00
|
|
|
struct wt_status *s = cb;
|
commit: teach --gpg-sign option
This uses the gpg-interface.[ch] to allow signing the commit, i.e.
$ git commit --gpg-sign -m foo
You need a passphrase to unlock the secret key for
user: "Junio C Hamano <gitster@pobox.com>"
4096-bit RSA key, ID 96AFE6CB, created 2011-10-03 (main key ID 713660A7)
[master 8457d13] foo
1 files changed, 1 insertions(+), 0 deletions(-)
The lines of GPG detached signature are placed in a new multi-line header
field, instead of tucking the signature block at the end of the commit log
message text (similar to how signed tag is done), for multiple reasons:
- The signature won't clutter output from "git log" and friends if it is
in the extra header. If we place it at the end of the log message, we
would need to teach "git log" and friends to strip the signature block
with an option.
- Teaching new versions of "git log" and "gitk" to optionally verify and
show signatures is cleaner if we structurally know where the signature
block is (instead of scanning in the commit log message).
- The signature needs to be stripped upon various commit rewriting
operations, e.g. rebase, filter-branch, etc. They all already ignore
unknown headers, but if we place signature in the log message, all of
these tools (and third-party tools) also need to learn how a signature
block would look like.
- When we added the optional encoding header, all the tools (both in tree
and third-party) that acts on the raw commit object should have been
fixed to ignore headers they do not understand, so it is not like that
new header would be more likely to break than extra text in the commit.
A commit made with the above sample sequence would look like this:
$ git cat-file commit HEAD
tree 3cd71d90e3db4136e5260ab54599791c4f883b9d
parent b87755351a47b09cb27d6913e6e0e17e6254a4d4
author Junio C Hamano <gitster@pobox.com> 1317862251 -0700
committer Junio C Hamano <gitster@pobox.com> 1317862251 -0700
gpgsig -----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
iQIcBAABAgAGBQJOjPtrAAoJELC16IaWr+bL4TMP/RSe2Y/jYnCkds9unO5JEnfG
...
=dt98
-----END PGP SIGNATURE-----
foo
but "git log" (unless you ask for it with --pretty=raw) output is not
cluttered with the signature information.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-10-06 00:23:20 +00:00
|
|
|
int status;
|
2009-08-10 04:59:30 +00:00
|
|
|
|
2008-07-05 05:24:40 +00:00
|
|
|
if (!strcmp(k, "commit.template"))
|
2009-11-17 17:24:25 +00:00
|
|
|
return git_config_pathname(&template_file, k, v);
|
2009-12-07 22:45:27 +00:00
|
|
|
if (!strcmp(k, "commit.status")) {
|
|
|
|
include_status = git_config_bool(k, v);
|
|
|
|
return 0;
|
|
|
|
}
|
2013-01-10 17:45:59 +00:00
|
|
|
if (!strcmp(k, "commit.cleanup"))
|
|
|
|
return git_config_string(&cleanup_arg, k, v);
|
2013-11-04 23:14:41 +00:00
|
|
|
if (!strcmp(k, "commit.gpgsign")) {
|
|
|
|
sign_commit = git_config_bool(k, v) ? "" : NULL;
|
|
|
|
return 0;
|
|
|
|
}
|
2016-05-05 09:50:02 +00:00
|
|
|
if (!strcmp(k, "commit.verbose")) {
|
|
|
|
int is_bool;
|
|
|
|
config_commit_verbose = git_config_bool_or_int(k, v, &is_bool);
|
|
|
|
return 0;
|
|
|
|
}
|
2007-11-08 16:59:00 +00:00
|
|
|
|
commit: teach --gpg-sign option
This uses the gpg-interface.[ch] to allow signing the commit, i.e.
$ git commit --gpg-sign -m foo
You need a passphrase to unlock the secret key for
user: "Junio C Hamano <gitster@pobox.com>"
4096-bit RSA key, ID 96AFE6CB, created 2011-10-03 (main key ID 713660A7)
[master 8457d13] foo
1 files changed, 1 insertions(+), 0 deletions(-)
The lines of GPG detached signature are placed in a new multi-line header
field, instead of tucking the signature block at the end of the commit log
message text (similar to how signed tag is done), for multiple reasons:
- The signature won't clutter output from "git log" and friends if it is
in the extra header. If we place it at the end of the log message, we
would need to teach "git log" and friends to strip the signature block
with an option.
- Teaching new versions of "git log" and "gitk" to optionally verify and
show signatures is cleaner if we structurally know where the signature
block is (instead of scanning in the commit log message).
- The signature needs to be stripped upon various commit rewriting
operations, e.g. rebase, filter-branch, etc. They all already ignore
unknown headers, but if we place signature in the log message, all of
these tools (and third-party tools) also need to learn how a signature
block would look like.
- When we added the optional encoding header, all the tools (both in tree
and third-party) that acts on the raw commit object should have been
fixed to ignore headers they do not understand, so it is not like that
new header would be more likely to break than extra text in the commit.
A commit made with the above sample sequence would look like this:
$ git cat-file commit HEAD
tree 3cd71d90e3db4136e5260ab54599791c4f883b9d
parent b87755351a47b09cb27d6913e6e0e17e6254a4d4
author Junio C Hamano <gitster@pobox.com> 1317862251 -0700
committer Junio C Hamano <gitster@pobox.com> 1317862251 -0700
gpgsig -----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
iQIcBAABAgAGBQJOjPtrAAoJELC16IaWr+bL4TMP/RSe2Y/jYnCkds9unO5JEnfG
...
=dt98
-----END PGP SIGNATURE-----
foo
but "git log" (unless you ask for it with --pretty=raw) output is not
cluttered with the signature information.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-10-06 00:23:20 +00:00
|
|
|
status = git_gpg_config(k, v, NULL);
|
|
|
|
if (status)
|
|
|
|
return status;
|
2009-08-10 04:59:30 +00:00
|
|
|
return git_status_config(k, v, s);
|
2007-11-08 16:59:00 +00:00
|
|
|
}
|
|
|
|
|
2017-02-20 00:10:14 +00:00
|
|
|
static int run_rewrite_hook(const struct object_id *oldoid,
|
|
|
|
const struct object_id *newoid)
|
2010-03-12 17:04:28 +00:00
|
|
|
{
|
2014-08-19 19:09:35 +00:00
|
|
|
struct child_process proc = CHILD_PROCESS_INIT;
|
2010-03-12 17:04:28 +00:00
|
|
|
const char *argv[3];
|
|
|
|
int code;
|
2017-01-31 13:45:35 +00:00
|
|
|
struct strbuf sb = STRBUF_INIT;
|
2010-03-12 17:04:28 +00:00
|
|
|
|
2013-01-13 05:17:02 +00:00
|
|
|
argv[0] = find_hook("post-rewrite");
|
|
|
|
if (!argv[0])
|
2010-03-12 17:04:28 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
argv[1] = "amend";
|
|
|
|
argv[2] = NULL;
|
|
|
|
|
|
|
|
proc.argv = argv;
|
|
|
|
proc.in = -1;
|
|
|
|
proc.stdout_to_stderr = 1;
|
|
|
|
|
|
|
|
code = start_command(&proc);
|
|
|
|
if (code)
|
|
|
|
return code;
|
2017-02-20 00:10:14 +00:00
|
|
|
strbuf_addf(&sb, "%s %s\n", oid_to_hex(oldoid), oid_to_hex(newoid));
|
2015-11-16 08:05:58 +00:00
|
|
|
sigchain_push(SIGPIPE, SIG_IGN);
|
2017-01-31 13:45:35 +00:00
|
|
|
write_in_full(proc.in, sb.buf, sb.len);
|
2010-03-12 17:04:28 +00:00
|
|
|
close(proc.in);
|
2017-01-31 13:45:35 +00:00
|
|
|
strbuf_release(&sb);
|
2015-11-16 08:05:58 +00:00
|
|
|
sigchain_pop(SIGPIPE);
|
2010-03-12 17:04:28 +00:00
|
|
|
return finish_command(&proc);
|
|
|
|
}
|
|
|
|
|
2014-03-18 10:00:53 +00:00
|
|
|
int run_commit_hook(int editor_is_used, const char *index_file, const char *name, ...)
|
|
|
|
{
|
2017-01-13 17:58:00 +00:00
|
|
|
struct argv_array hook_env = ARGV_ARRAY_INIT;
|
2014-03-18 10:00:53 +00:00
|
|
|
va_list args;
|
|
|
|
int ret;
|
|
|
|
|
2017-01-13 17:58:00 +00:00
|
|
|
argv_array_pushf(&hook_env, "GIT_INDEX_FILE=%s", index_file);
|
2014-03-18 10:00:53 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Let the hook know that no editor will be launched.
|
|
|
|
*/
|
|
|
|
if (!editor_is_used)
|
2017-01-13 17:58:00 +00:00
|
|
|
argv_array_push(&hook_env, "GIT_EDITOR=:");
|
2014-03-18 10:00:53 +00:00
|
|
|
|
|
|
|
va_start(args, name);
|
2017-01-13 17:58:00 +00:00
|
|
|
ret = run_hook_ve(hook_env.argv,name, args);
|
2014-03-18 10:00:53 +00:00
|
|
|
va_end(args);
|
2017-01-13 17:58:00 +00:00
|
|
|
argv_array_clear(&hook_env);
|
2014-03-18 10:00:53 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-11-08 16:59:00 +00:00
|
|
|
int cmd_commit(int argc, const char **argv, const char *prefix)
|
|
|
|
{
|
2012-05-07 19:18:26 +00:00
|
|
|
static struct wt_status s;
|
|
|
|
static struct option builtin_commit_options[] = {
|
2012-08-20 12:32:04 +00:00
|
|
|
OPT__QUIET(&quiet, N_("suppress summary after successful commit")),
|
|
|
|
OPT__VERBOSE(&verbose, N_("show diff in commit message template")),
|
|
|
|
|
|
|
|
OPT_GROUP(N_("Commit message options")),
|
|
|
|
OPT_FILENAME('F', "file", &logfile, N_("read message from file")),
|
|
|
|
OPT_STRING(0, "author", &force_author, N_("author"), N_("override author for commit")),
|
|
|
|
OPT_STRING(0, "date", &force_date, N_("date"), N_("override date for commit")),
|
|
|
|
OPT_CALLBACK('m', "message", &message, N_("message"), N_("commit message"), opt_parse_m),
|
|
|
|
OPT_STRING('c', "reedit-message", &edit_message, N_("commit"), N_("reuse and edit message from specified commit")),
|
|
|
|
OPT_STRING('C', "reuse-message", &use_message, N_("commit"), N_("reuse message from specified commit")),
|
|
|
|
OPT_STRING(0, "fixup", &fixup_message, N_("commit"), N_("use autosquash formatted message to fixup specified commit")),
|
|
|
|
OPT_STRING(0, "squash", &squash_message, N_("commit"), N_("use autosquash formatted message to squash specified commit")),
|
2013-08-03 11:51:19 +00:00
|
|
|
OPT_BOOL(0, "reset-author", &renew_authorship, N_("the commit is authored by me now (used with -C/-c/--amend)")),
|
|
|
|
OPT_BOOL('s', "signoff", &signoff, N_("add Signed-off-by:")),
|
2012-08-20 12:32:04 +00:00
|
|
|
OPT_FILENAME('t', "template", &template_file, N_("use specified template file")),
|
|
|
|
OPT_BOOL('e', "edit", &edit_flag, N_("force edit of commit")),
|
|
|
|
OPT_STRING(0, "cleanup", &cleanup_arg, N_("default"), N_("how to strip spaces and #comments from message")),
|
2013-08-03 11:51:19 +00:00
|
|
|
OPT_BOOL(0, "status", &include_status, N_("include status in commit message template")),
|
2014-03-23 22:58:12 +00:00
|
|
|
{ OPTION_STRING, 'S', "gpg-sign", &sign_commit, N_("key-id"),
|
2012-08-20 12:32:04 +00:00
|
|
|
N_("GPG sign commit"), PARSE_OPT_OPTARG, NULL, (intptr_t) "" },
|
2012-05-07 19:18:26 +00:00
|
|
|
/* end commit message options */
|
|
|
|
|
2012-08-20 12:32:04 +00:00
|
|
|
OPT_GROUP(N_("Commit contents options")),
|
2013-08-03 11:51:19 +00:00
|
|
|
OPT_BOOL('a', "all", &all, N_("commit all changed files")),
|
|
|
|
OPT_BOOL('i', "include", &also, N_("add specified files to index for commit")),
|
|
|
|
OPT_BOOL(0, "interactive", &interactive, N_("interactively add files")),
|
|
|
|
OPT_BOOL('p', "patch", &patch_interactive, N_("interactively add changes")),
|
|
|
|
OPT_BOOL('o', "only", &only, N_("commit only specified files")),
|
2016-07-26 14:00:15 +00:00
|
|
|
OPT_BOOL('n', "no-verify", &no_verify, N_("bypass pre-commit and commit-msg hooks")),
|
2013-08-03 11:51:19 +00:00
|
|
|
OPT_BOOL(0, "dry-run", &dry_run, N_("show what would be committed")),
|
2012-08-20 12:32:04 +00:00
|
|
|
OPT_SET_INT(0, "short", &status_format, N_("show status concisely"),
|
2012-05-07 19:18:26 +00:00
|
|
|
STATUS_FORMAT_SHORT),
|
2013-06-24 18:41:40 +00:00
|
|
|
OPT_BOOL(0, "branch", &s.show_branch, N_("show branch information")),
|
2012-05-07 19:18:26 +00:00
|
|
|
OPT_SET_INT(0, "porcelain", &status_format,
|
2012-08-20 12:32:04 +00:00
|
|
|
N_("machine-readable output"), STATUS_FORMAT_PORCELAIN),
|
2012-10-18 14:15:50 +00:00
|
|
|
OPT_SET_INT(0, "long", &status_format,
|
|
|
|
N_("show status in long format (default)"),
|
|
|
|
STATUS_FORMAT_LONG),
|
2013-08-03 11:51:19 +00:00
|
|
|
OPT_BOOL('z', "null", &s.null_termination,
|
|
|
|
N_("terminate entries with NUL")),
|
|
|
|
OPT_BOOL(0, "amend", &amend, N_("amend previous commit")),
|
|
|
|
OPT_BOOL(0, "no-post-rewrite", &no_post_rewrite, N_("bypass post-rewrite hook")),
|
2012-08-20 12:32:04 +00:00
|
|
|
{ OPTION_STRING, 'u', "untracked-files", &untracked_files_arg, N_("mode"), N_("show untracked files, optional modes: all, normal, no. (Default: all)"), PARSE_OPT_OPTARG, NULL, (intptr_t)"all" },
|
2012-05-07 19:18:26 +00:00
|
|
|
/* end commit contents options */
|
|
|
|
|
2013-08-03 11:51:18 +00:00
|
|
|
OPT_HIDDEN_BOOL(0, "allow-empty", &allow_empty,
|
|
|
|
N_("ok to record an empty change")),
|
|
|
|
OPT_HIDDEN_BOOL(0, "allow-empty-message", &allow_empty_message,
|
|
|
|
N_("ok to record a change with an empty message")),
|
2012-05-07 19:18:26 +00:00
|
|
|
|
|
|
|
OPT_END()
|
|
|
|
};
|
|
|
|
|
2008-10-09 19:12:12 +00:00
|
|
|
struct strbuf sb = STRBUF_INIT;
|
2010-12-21 01:00:36 +00:00
|
|
|
struct strbuf author_ident = STRBUF_INIT;
|
2007-11-08 16:59:00 +00:00
|
|
|
const char *index_file, *reflog_msg;
|
2013-12-05 19:44:14 +00:00
|
|
|
char *nl;
|
2017-02-20 00:10:14 +00:00
|
|
|
struct object_id oid;
|
2016-10-29 12:55:36 +00:00
|
|
|
struct commit_list *parents = NULL;
|
builtin-commit: use reduce_heads() only when appropriate
Since commit 6bb6b034 (builtin-commit: use commit_tree(), 2008-09-10),
builtin-commit performs a reduce_heads() unconditionally. However,
it's not always needed, and in some cases even harmful.
reduce_heads() is not needed for the initial commit or for an
"ordinary" commit, because they don't have any or have only one
parent, respectively.
reduce_heads() must be avoided when 'git commit' is run after a 'git
merge --no-ff --no-commit', otherwise it will turn the
non-fast-forward merge into fast-forward. For the same reason,
reduce_heads() must be avoided when amending such a merge commit.
To resolve this issue, 'git merge' will write info about whether
fast-forward is allowed or not to $GIT_DIR/MERGE_MODE. Based on this
info, 'git commit' will only perform reduce_heads() when it's
committing a merge and fast-forward is enabled.
Also add test cases to ensure that non-fast-forward merges are
committed and amended properly.
Signed-off-by: Miklos Vajna <vmiklos@frugalware.org>
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2008-10-03 12:04:47 +00:00
|
|
|
struct stat statbuf;
|
2011-08-19 18:58:18 +00:00
|
|
|
struct commit *current_head = NULL;
|
2011-11-08 23:38:07 +00:00
|
|
|
struct commit_extra_header *extra = NULL;
|
2014-04-16 22:34:19 +00:00
|
|
|
struct ref_transaction *transaction;
|
|
|
|
struct strbuf err = STRBUF_INIT;
|
2007-11-08 16:59:00 +00:00
|
|
|
|
2010-10-22 06:45:47 +00:00
|
|
|
if (argc == 2 && !strcmp(argv[1], "-h"))
|
|
|
|
usage_with_options(builtin_commit_usage, builtin_commit_options);
|
|
|
|
|
2013-09-12 10:50:04 +00:00
|
|
|
status_init_config(&s, git_commit_config);
|
2013-06-24 12:45:12 +00:00
|
|
|
status_format = STATUS_FORMAT_NONE; /* Ignore status.short */
|
2012-05-07 19:35:03 +00:00
|
|
|
s.colopts = 0;
|
2007-11-08 16:59:00 +00:00
|
|
|
|
2017-02-20 00:10:14 +00:00
|
|
|
if (get_sha1("HEAD", oid.hash))
|
2011-08-19 18:58:18 +00:00
|
|
|
current_head = NULL;
|
|
|
|
else {
|
2017-02-20 00:10:14 +00:00
|
|
|
current_head = lookup_commit_or_die(oid.hash, "HEAD");
|
2013-10-24 08:53:19 +00:00
|
|
|
if (parse_commit(current_head))
|
2011-08-19 18:58:18 +00:00
|
|
|
die(_("could not parse HEAD commit"));
|
|
|
|
}
|
2016-05-05 09:50:02 +00:00
|
|
|
verbose = -1; /* unspecified */
|
2012-05-07 19:18:26 +00:00
|
|
|
argc = parse_and_validate_options(argc, argv, builtin_commit_options,
|
|
|
|
builtin_commit_usage,
|
2011-08-19 18:58:18 +00:00
|
|
|
prefix, current_head, &s);
|
2016-05-05 09:50:02 +00:00
|
|
|
if (verbose == -1)
|
|
|
|
verbose = (config_commit_verbose < 0) ? 0 : config_commit_verbose;
|
|
|
|
|
2011-08-18 05:05:35 +00:00
|
|
|
if (dry_run)
|
2011-08-19 18:58:18 +00:00
|
|
|
return dry_run_commit(argc, argv, prefix, current_head, &s);
|
|
|
|
index_file = prepare_index(argc, argv, prefix, current_head, 0);
|
2007-11-08 16:59:00 +00:00
|
|
|
|
2008-02-05 10:01:46 +00:00
|
|
|
/* Set up everything for writing the commit object. This includes
|
|
|
|
running hooks, writing the trees, and interacting with the user. */
|
2011-08-19 18:58:18 +00:00
|
|
|
if (!prepare_to_commit(index_file, prefix,
|
|
|
|
current_head, &s, &author_ident)) {
|
2007-11-18 09:52:55 +00:00
|
|
|
rollback_index_files();
|
2007-11-08 16:59:00 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Determine parents */
|
2010-06-12 16:05:12 +00:00
|
|
|
reflog_msg = getenv("GIT_REFLOG_ACTION");
|
2011-08-19 18:58:18 +00:00
|
|
|
if (!current_head) {
|
2010-06-12 16:05:12 +00:00
|
|
|
if (!reflog_msg)
|
|
|
|
reflog_msg = "commit (initial)";
|
2007-11-08 16:59:00 +00:00
|
|
|
} else if (amend) {
|
2010-06-12 16:05:12 +00:00
|
|
|
if (!reflog_msg)
|
|
|
|
reflog_msg = "commit (amend)";
|
2016-10-29 12:55:36 +00:00
|
|
|
parents = copy_commit_list(current_head->parents);
|
2011-02-20 04:12:29 +00:00
|
|
|
} else if (whence == FROM_MERGE) {
|
2008-10-09 19:12:12 +00:00
|
|
|
struct strbuf m = STRBUF_INIT;
|
2007-11-08 16:59:00 +00:00
|
|
|
FILE *fp;
|
2014-01-30 15:15:56 +00:00
|
|
|
int allow_fast_forward = 1;
|
2016-10-29 12:55:36 +00:00
|
|
|
struct commit_list **pptr = &parents;
|
2007-11-08 16:59:00 +00:00
|
|
|
|
2010-06-12 16:05:12 +00:00
|
|
|
if (!reflog_msg)
|
|
|
|
reflog_msg = "commit (merge)";
|
2016-10-29 12:55:36 +00:00
|
|
|
pptr = commit_list_append(current_head, pptr);
|
memoize common git-path "constant" files
One of the most common uses of git_path() is to pass a
constant, like git_path("MERGE_MSG"). This has two
drawbacks:
1. The return value is a static buffer, and the lifetime
is dependent on other calls to git_path, etc.
2. There's no compile-time checking of the pathname. This
is OK for a one-off (after all, we have to spell it
correctly at least once), but many of these constant
strings appear throughout the code.
This patch introduces a series of functions to "memoize"
these strings, which are essentially globals for the
lifetime of the program. We compute the value once, take
ownership of the buffer, and return the cached value for
subsequent calls. cache.h provides a helper macro for
defining these functions as one-liners, and defines a few
common ones for global use.
Using a macro is a little bit gross, but it does nicely
document the purpose of the functions. If we need to touch
them all later (e.g., because we learned how to change the
git_dir variable at runtime, and need to invalidate all of
the stored values), it will be much easier to have the
complete list.
Note that the shared-global functions have separate, manual
declarations. We could do something clever with the macros
(e.g., expand it to a declaration in some places, and a
declaration _and_ a definition in path.c). But there aren't
that many, and it's probably better to stay away from
too-magical macros.
Likewise, if we abandon the C preprocessor in favor of
generating these with a script, we could get much fancier.
E.g., normalizing "FOO/BAR-BAZ" into "git_path_foo_bar_baz".
But the small amount of saved typing is probably not worth
the resulting confusion to readers who want to grep for the
function's definition.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-08-10 09:38:57 +00:00
|
|
|
fp = fopen(git_path_merge_head(), "r");
|
2007-11-08 16:59:00 +00:00
|
|
|
if (fp == NULL)
|
2011-02-22 23:41:44 +00:00
|
|
|
die_errno(_("could not open '%s' for reading"),
|
memoize common git-path "constant" files
One of the most common uses of git_path() is to pass a
constant, like git_path("MERGE_MSG"). This has two
drawbacks:
1. The return value is a static buffer, and the lifetime
is dependent on other calls to git_path, etc.
2. There's no compile-time checking of the pathname. This
is OK for a one-off (after all, we have to spell it
correctly at least once), but many of these constant
strings appear throughout the code.
This patch introduces a series of functions to "memoize"
these strings, which are essentially globals for the
lifetime of the program. We compute the value once, take
ownership of the buffer, and return the cached value for
subsequent calls. cache.h provides a helper macro for
defining these functions as one-liners, and defines a few
common ones for global use.
Using a macro is a little bit gross, but it does nicely
document the purpose of the functions. If we need to touch
them all later (e.g., because we learned how to change the
git_dir variable at runtime, and need to invalidate all of
the stored values), it will be much easier to have the
complete list.
Note that the shared-global functions have separate, manual
declarations. We could do something clever with the macros
(e.g., expand it to a declaration in some places, and a
declaration _and_ a definition in path.c). But there aren't
that many, and it's probably better to stay away from
too-magical macros.
Likewise, if we abandon the C preprocessor in favor of
generating these with a script, we could get much fancier.
E.g., normalizing "FOO/BAR-BAZ" into "git_path_foo_bar_baz".
But the small amount of saved typing is probably not worth
the resulting confusion to readers who want to grep for the
function's definition.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-08-10 09:38:57 +00:00
|
|
|
git_path_merge_head());
|
2016-01-13 23:31:17 +00:00
|
|
|
while (strbuf_getline_lf(&m, fp) != EOF) {
|
2011-11-08 00:21:32 +00:00
|
|
|
struct commit *parent;
|
|
|
|
|
|
|
|
parent = get_merge_parent(m.buf);
|
|
|
|
if (!parent)
|
2011-02-22 23:41:44 +00:00
|
|
|
die(_("Corrupt MERGE_HEAD file (%s)"), m.buf);
|
2016-10-29 12:55:36 +00:00
|
|
|
pptr = commit_list_append(parent, pptr);
|
2008-01-16 00:12:33 +00:00
|
|
|
}
|
2007-11-08 16:59:00 +00:00
|
|
|
fclose(fp);
|
|
|
|
strbuf_release(&m);
|
memoize common git-path "constant" files
One of the most common uses of git_path() is to pass a
constant, like git_path("MERGE_MSG"). This has two
drawbacks:
1. The return value is a static buffer, and the lifetime
is dependent on other calls to git_path, etc.
2. There's no compile-time checking of the pathname. This
is OK for a one-off (after all, we have to spell it
correctly at least once), but many of these constant
strings appear throughout the code.
This patch introduces a series of functions to "memoize"
these strings, which are essentially globals for the
lifetime of the program. We compute the value once, take
ownership of the buffer, and return the cached value for
subsequent calls. cache.h provides a helper macro for
defining these functions as one-liners, and defines a few
common ones for global use.
Using a macro is a little bit gross, but it does nicely
document the purpose of the functions. If we need to touch
them all later (e.g., because we learned how to change the
git_dir variable at runtime, and need to invalidate all of
the stored values), it will be much easier to have the
complete list.
Note that the shared-global functions have separate, manual
declarations. We could do something clever with the macros
(e.g., expand it to a declaration in some places, and a
declaration _and_ a definition in path.c). But there aren't
that many, and it's probably better to stay away from
too-magical macros.
Likewise, if we abandon the C preprocessor in favor of
generating these with a script, we could get much fancier.
E.g., normalizing "FOO/BAR-BAZ" into "git_path_foo_bar_baz".
But the small amount of saved typing is probably not worth
the resulting confusion to readers who want to grep for the
function's definition.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-08-10 09:38:57 +00:00
|
|
|
if (!stat(git_path_merge_mode(), &statbuf)) {
|
|
|
|
if (strbuf_read_file(&sb, git_path_merge_mode(), 0) < 0)
|
2011-02-22 23:41:44 +00:00
|
|
|
die_errno(_("could not read MERGE_MODE"));
|
builtin-commit: use reduce_heads() only when appropriate
Since commit 6bb6b034 (builtin-commit: use commit_tree(), 2008-09-10),
builtin-commit performs a reduce_heads() unconditionally. However,
it's not always needed, and in some cases even harmful.
reduce_heads() is not needed for the initial commit or for an
"ordinary" commit, because they don't have any or have only one
parent, respectively.
reduce_heads() must be avoided when 'git commit' is run after a 'git
merge --no-ff --no-commit', otherwise it will turn the
non-fast-forward merge into fast-forward. For the same reason,
reduce_heads() must be avoided when amending such a merge commit.
To resolve this issue, 'git merge' will write info about whether
fast-forward is allowed or not to $GIT_DIR/MERGE_MODE. Based on this
info, 'git commit' will only perform reduce_heads() when it's
committing a merge and fast-forward is enabled.
Also add test cases to ensure that non-fast-forward merges are
committed and amended properly.
Signed-off-by: Miklos Vajna <vmiklos@frugalware.org>
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2008-10-03 12:04:47 +00:00
|
|
|
if (!strcmp(sb.buf, "no-ff"))
|
|
|
|
allow_fast_forward = 0;
|
|
|
|
}
|
|
|
|
if (allow_fast_forward)
|
|
|
|
parents = reduce_heads(parents);
|
2007-11-08 16:59:00 +00:00
|
|
|
} else {
|
2010-06-12 16:05:12 +00:00
|
|
|
if (!reflog_msg)
|
2011-02-20 04:12:29 +00:00
|
|
|
reflog_msg = (whence == FROM_CHERRY_PICK)
|
|
|
|
? "commit (cherry-pick)"
|
|
|
|
: "commit";
|
2016-10-29 12:55:36 +00:00
|
|
|
commit_list_insert(current_head, &parents);
|
2007-11-08 16:59:00 +00:00
|
|
|
}
|
|
|
|
|
2008-02-05 10:01:46 +00:00
|
|
|
/* Finally, get the commit message */
|
builtin-commit: use reduce_heads() only when appropriate
Since commit 6bb6b034 (builtin-commit: use commit_tree(), 2008-09-10),
builtin-commit performs a reduce_heads() unconditionally. However,
it's not always needed, and in some cases even harmful.
reduce_heads() is not needed for the initial commit or for an
"ordinary" commit, because they don't have any or have only one
parent, respectively.
reduce_heads() must be avoided when 'git commit' is run after a 'git
merge --no-ff --no-commit', otherwise it will turn the
non-fast-forward merge into fast-forward. For the same reason,
reduce_heads() must be avoided when amending such a merge commit.
To resolve this issue, 'git merge' will write info about whether
fast-forward is allowed or not to $GIT_DIR/MERGE_MODE. Based on this
info, 'git commit' will only perform reduce_heads() when it's
committing a merge and fast-forward is enabled.
Also add test cases to ensure that non-fast-forward merges are
committed and amended properly.
Signed-off-by: Miklos Vajna <vmiklos@frugalware.org>
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2008-10-03 12:04:47 +00:00
|
|
|
strbuf_reset(&sb);
|
2016-05-24 19:19:50 +00:00
|
|
|
if (strbuf_read_file(&sb, git_path_commit_editmsg(), 0) < 0) {
|
2009-06-27 15:58:47 +00:00
|
|
|
int saved_errno = errno;
|
2007-12-09 07:23:20 +00:00
|
|
|
rollback_index_files();
|
2011-02-22 23:41:44 +00:00
|
|
|
die(_("could not read commit message: %s"), strerror(saved_errno));
|
2007-12-09 07:23:20 +00:00
|
|
|
}
|
2007-11-22 02:54:49 +00:00
|
|
|
|
2014-02-17 12:15:32 +00:00
|
|
|
if (verbose || /* Truncate the message just before the diff, if any. */
|
|
|
|
cleanup_mode == CLEANUP_SCISSORS)
|
2013-12-05 19:44:14 +00:00
|
|
|
wt_status_truncate_message_at_cut_line(&sb);
|
2007-11-22 02:54:49 +00:00
|
|
|
|
2007-12-22 18:46:24 +00:00
|
|
|
if (cleanup_mode != CLEANUP_NONE)
|
2015-10-16 15:16:42 +00:00
|
|
|
strbuf_stripspace(&sb, cleanup_mode == CLEANUP_ALL);
|
2012-03-30 19:14:33 +00:00
|
|
|
if (template_untouched(&sb) && !allow_empty_message) {
|
|
|
|
rollback_index_files();
|
|
|
|
fprintf(stderr, _("Aborting commit; you did not edit the message.\n"));
|
|
|
|
exit(1);
|
|
|
|
}
|
2010-04-06 08:40:35 +00:00
|
|
|
if (message_is_empty(&sb) && !allow_empty_message) {
|
2007-11-18 09:52:55 +00:00
|
|
|
rollback_index_files();
|
2011-02-22 23:41:44 +00:00
|
|
|
fprintf(stderr, _("Aborting commit due to empty commit message.\n"));
|
2008-07-31 07:36:09 +00:00
|
|
|
exit(1);
|
2007-11-18 09:52:55 +00:00
|
|
|
}
|
2007-11-08 16:59:00 +00:00
|
|
|
|
2011-12-20 21:20:56 +00:00
|
|
|
if (amend) {
|
2012-01-05 18:54:14 +00:00
|
|
|
const char *exclude_gpgsig[2] = { "gpgsig", NULL };
|
|
|
|
extra = read_commit_extra_headers(current_head, exclude_gpgsig);
|
2011-12-20 21:20:56 +00:00
|
|
|
} else {
|
|
|
|
struct commit_extra_header **tail = &extra;
|
|
|
|
append_merge_tag_headers(parents, &tail);
|
|
|
|
}
|
2011-11-08 23:38:07 +00:00
|
|
|
|
2017-05-01 02:28:56 +00:00
|
|
|
if (commit_tree_extended(sb.buf, sb.len, active_cache_tree->oid.hash,
|
2017-02-20 00:10:14 +00:00
|
|
|
parents, oid.hash, author_ident.buf, sign_commit, extra)) {
|
2007-11-18 09:52:55 +00:00
|
|
|
rollback_index_files();
|
2011-02-22 23:41:44 +00:00
|
|
|
die(_("failed to write commit object"));
|
2007-11-18 09:52:55 +00:00
|
|
|
}
|
2010-12-21 01:00:36 +00:00
|
|
|
strbuf_release(&author_ident);
|
2011-11-08 23:38:07 +00:00
|
|
|
free_commit_extra_headers(extra);
|
2007-11-08 16:59:00 +00:00
|
|
|
|
2008-09-10 20:10:32 +00:00
|
|
|
nl = strchr(sb.buf, '\n');
|
2007-11-08 12:15:26 +00:00
|
|
|
if (nl)
|
|
|
|
strbuf_setlen(&sb, nl + 1 - sb.buf);
|
|
|
|
else
|
|
|
|
strbuf_addch(&sb, '\n');
|
|
|
|
strbuf_insert(&sb, 0, reflog_msg, strlen(reflog_msg));
|
|
|
|
strbuf_insert(&sb, strlen(reflog_msg), ": ", 2);
|
2007-11-08 16:59:00 +00:00
|
|
|
|
2014-04-16 22:34:19 +00:00
|
|
|
transaction = ref_transaction_begin(&err);
|
|
|
|
if (!transaction ||
|
2017-02-20 00:10:14 +00:00
|
|
|
ref_transaction_update(transaction, "HEAD", oid.hash,
|
2014-04-16 22:34:19 +00:00
|
|
|
current_head
|
2015-11-10 02:22:29 +00:00
|
|
|
? current_head->object.oid.hash : null_sha1,
|
2015-02-17 17:00:15 +00:00
|
|
|
0, sb.buf, &err) ||
|
2014-04-30 19:22:42 +00:00
|
|
|
ref_transaction_commit(transaction, &err)) {
|
2007-11-18 09:52:55 +00:00
|
|
|
rollback_index_files();
|
2014-04-16 22:34:19 +00:00
|
|
|
die("%s", err.buf);
|
2007-11-18 09:52:55 +00:00
|
|
|
}
|
2014-04-16 22:34:19 +00:00
|
|
|
ref_transaction_free(transaction);
|
2007-11-08 16:59:00 +00:00
|
|
|
|
memoize common git-path "constant" files
One of the most common uses of git_path() is to pass a
constant, like git_path("MERGE_MSG"). This has two
drawbacks:
1. The return value is a static buffer, and the lifetime
is dependent on other calls to git_path, etc.
2. There's no compile-time checking of the pathname. This
is OK for a one-off (after all, we have to spell it
correctly at least once), but many of these constant
strings appear throughout the code.
This patch introduces a series of functions to "memoize"
these strings, which are essentially globals for the
lifetime of the program. We compute the value once, take
ownership of the buffer, and return the cached value for
subsequent calls. cache.h provides a helper macro for
defining these functions as one-liners, and defines a few
common ones for global use.
Using a macro is a little bit gross, but it does nicely
document the purpose of the functions. If we need to touch
them all later (e.g., because we learned how to change the
git_dir variable at runtime, and need to invalidate all of
the stored values), it will be much easier to have the
complete list.
Note that the shared-global functions have separate, manual
declarations. We could do something clever with the macros
(e.g., expand it to a declaration in some places, and a
declaration _and_ a definition in path.c). But there aren't
that many, and it's probably better to stay away from
too-magical macros.
Likewise, if we abandon the C preprocessor in favor of
generating these with a script, we could get much fancier.
E.g., normalizing "FOO/BAR-BAZ" into "git_path_foo_bar_baz".
But the small amount of saved typing is probably not worth
the resulting confusion to readers who want to grep for the
function's definition.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-08-10 09:38:57 +00:00
|
|
|
unlink(git_path_cherry_pick_head());
|
|
|
|
unlink(git_path_revert_head());
|
|
|
|
unlink(git_path_merge_head());
|
|
|
|
unlink(git_path_merge_msg());
|
|
|
|
unlink(git_path_merge_mode());
|
|
|
|
unlink(git_path_squash_msg());
|
2007-11-08 16:59:00 +00:00
|
|
|
|
2008-01-23 17:21:22 +00:00
|
|
|
if (commit_index_files())
|
2011-02-22 23:41:44 +00:00
|
|
|
die (_("Repository has been updated, but unable to write\n"
|
2014-08-30 19:56:01 +00:00
|
|
|
"new_index file. Check that disk is not full and quota is\n"
|
2011-02-22 23:41:44 +00:00
|
|
|
"not exceeded, and then \"git reset HEAD\" to recover."));
|
2007-11-08 16:59:00 +00:00
|
|
|
|
2009-12-04 08:20:48 +00:00
|
|
|
rerere(0);
|
2014-03-18 10:00:53 +00:00
|
|
|
run_commit_hook(use_editor, get_index_file(), "post-commit", NULL);
|
2010-03-12 17:04:28 +00:00
|
|
|
if (amend && !no_post_rewrite) {
|
2010-03-12 17:04:34 +00:00
|
|
|
struct notes_rewrite_cfg *cfg;
|
|
|
|
cfg = init_copy_notes_for_rewrite("amend");
|
|
|
|
if (cfg) {
|
2011-08-19 18:58:18 +00:00
|
|
|
/* we are amending, so current_head is not NULL */
|
2017-02-20 00:10:14 +00:00
|
|
|
copy_note_for_rewrite(cfg, current_head->object.oid.hash, oid.hash);
|
2013-06-12 00:12:59 +00:00
|
|
|
finish_copy_notes_for_rewrite(cfg, "Notes added by 'git commit --amend'");
|
2010-03-12 17:04:34 +00:00
|
|
|
}
|
2017-02-20 00:10:14 +00:00
|
|
|
run_rewrite_hook(¤t_head->object.oid, &oid);
|
2010-03-12 17:04:28 +00:00
|
|
|
}
|
2007-11-08 16:59:00 +00:00
|
|
|
if (!quiet)
|
2017-02-20 00:10:14 +00:00
|
|
|
print_summary(prefix, &oid, !current_head);
|
2007-11-08 16:59:00 +00:00
|
|
|
|
2014-04-16 22:34:19 +00:00
|
|
|
strbuf_release(&err);
|
2007-11-08 16:59:00 +00:00
|
|
|
return 0;
|
|
|
|
}
|