From: marcandre.lureau@redhat.com
To: git@vger.kernel.org
Cc: "Marc-André Lureau" <marcandre.lureau@redhat.com>
Subject: [PATCH] RFC: commit: add a commit.all-ignore-submodules config option
Date: Fri, 3 Jan 2020 16:06:13 +0400 [thread overview]
Message-ID: <20200103120613.1063828-1-marcandre.lureau@redhat.com> (raw)
From: Marc-André Lureau <marcandre.lureau@redhat.com>
One of my most frequent mistake is to commit undesired submodules
changes when doing "commit -a", and I have seen a number of people doing
the same mistake in various projects. I wish there would be a config to
change this default behaviour.
submodule.<name>.ignore or diff.ignoreSubmodules have different
tradeoffs, as they change the diff or status behaviour. I just wish the
default behaviour of "commit -a" to be different, to exclude submodules
by default.
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
builtin/add.c | 6 ++++++
builtin/commit.c | 10 +++++++++-
cache.h | 1 +
3 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/builtin/add.c b/builtin/add.c
index 4c38aff419..4023ee2681 100644
--- a/builtin/add.c
+++ b/builtin/add.c
@@ -82,6 +82,12 @@ static void update_callback(struct diff_queue_struct *q,
for (i = 0; i < q->nr; i++) {
struct diff_filepair *p = q->queue[i];
const char *path = p->one->path;
+
+ if (data->flags & ADD_CACHE_IGNORE_SUBMODULES &&
+ S_ISGITLINK(p->one->mode)) {
+ continue;
+ }
+
switch (fix_unmerged_status(p, data)) {
default:
die(_("unexpected diff status %c"), p->status);
diff --git a/builtin/commit.c b/builtin/commit.c
index aa1332308a..ce37e4e6da 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -110,6 +110,7 @@ static int config_commit_verbose = -1; /* unspecified */
static int no_post_rewrite, allow_empty_message, pathspec_file_nul;
static char *untracked_files_arg, *force_date, *ignore_submodule_arg, *ignored_arg;
static char *sign_commit, *pathspec_from_file;
+static int commit_all_ignore_submodules;
/*
* The default commit message cleanup mode will remove the lines
@@ -415,8 +416,10 @@ static const char *prepare_index(int argc, const char **argv, const char *prefix
* (B) on failure, rollback the real index.
*/
if (all || (also && pathspec.nr)) {
+ int flags = commit_all_ignore_submodules ? ADD_CACHE_IGNORE_SUBMODULES : 0;
+
hold_locked_index(&index_lock, LOCK_DIE_ON_ERROR);
- add_files_to_cache(also ? prefix : NULL, &pathspec, 0);
+ add_files_to_cache(also ? prefix : NULL, &pathspec, flags);
refresh_cache_or_die(refresh_flags);
update_main_cache_tree(WRITE_TREE_SILENT);
if (write_locked_index(&the_index, &index_lock, 0))
@@ -1475,6 +1478,11 @@ static int git_commit_config(const char *k, const char *v, void *cb)
return 0;
}
+ if (!strcmp(k, "commit.all-ignore-submodules")) {
+ commit_all_ignore_submodules = git_config_bool(k, v);
+ return 0;
+ }
+
status = git_gpg_config(k, v, NULL);
if (status)
return status;
diff --git a/cache.h b/cache.h
index 1554488d66..5fb3b18916 100644
--- a/cache.h
+++ b/cache.h
@@ -816,6 +816,7 @@ int remove_file_from_index(struct index_state *, const char *path);
#define ADD_CACHE_IGNORE_ERRORS 4
#define ADD_CACHE_IGNORE_REMOVAL 8
#define ADD_CACHE_INTENT 16
+#define ADD_CACHE_IGNORE_SUBMODULES 32
/*
* These two are used to add the contents of the file at path
* to the index, marking the working tree up-to-date by storing
base-commit: 8679ef24ed64018bb62170c43ce73e0261c0600a
--
2.25.0.rc1.1.gb0343b22ed
next reply other threads:[~2020-01-03 12:06 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-03 12:06 marcandre.lureau [this message]
2020-01-04 0:45 ` [PATCH] RFC: commit: add a commit.all-ignore-submodules config option Jonathan Nieder
2020-01-04 17:24 ` Marc-André Lureau
2020-01-07 0:05 ` Jonathan Nieder
2020-01-07 5:15 ` Marc-André Lureau
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200103120613.1063828-1-marcandre.lureau@redhat.com \
--to=marcandre.lureau@redhat.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).