Skip to contentSkip to conversation

Deprecate "not allow as-is commit with i-t-a entries"

PATCH In review Nguyễn Thái Ngọc Duy 2 participants 10 messages Jun 15, 2016 Documentation

lore
Share & tools
lore
#0 lore raw

v2 cover Deprecate "not allow as-is commit with i-t-a entries"

- git-add.txt changes are removed. In the end all kinds of commit behave the same way, not worth putting more explanation during the transition.

- reword config text and warning text (or more precisely copy/paste from Junio/Jonathan's words)

- Hard coded release numbers are removed. Now it's simply "in future".

- Step 2 may be too annoying. Users are warned on every commit if commit.ignoreIntentToAdd is set. I think it's good because it keeps config file clean, but people may think otherwise.

Nguyễn Thái Ngọc Duy (4):
cache-tree: update API to take abitrary flags
commit: introduce a config key to allow as-is commit with i-t-a entries
commit: turn commit.ignoreIntentToAdd to true by default
commit: remove commit.ignoreIntentToAdd, assume it's always true

 builtin/commit.c       |    9 ++++++---
 cache-tree.c           |   35 +++++++++++++++++------------------
 cache-tree.h           |    5 ++++-
 merge-recursive.c      |    2 +-
 t/t2203-add-intent.sh  |   21 ++++++++++++++++++++-
 test-dump-cache-tree.c |    2 +-
 6 files changed, 49 insertions(+), 25 deletions(-)
Signature · 1 line
1.7.8.36.g69ee2
#1 lore raw

PATCH v2 1/4 cache-tree: update API to take abitrary flags

---
 builtin/commit.c       |    4 ++--
 cache-tree.c           |   27 ++++++++++++---------------
 cache-tree.h           |    4 +++-
 merge-recursive.c      |    2 +-
 test-dump-cache-tree.c |    2 +-
 5 files changed, 19 insertions(+), 20 deletions(-)
builtin/commit.c +2 -2
index eba1377..bf42bb3 100644
@@ -400,7 +400,7 @@ static char *prepare_index(int argc, const char **argv, const char *prefix,
 		fd = hold_locked_index(&index_lock, 1);
 		add_files_to_cache(also ? prefix : NULL, pathspec, 0);
 		refresh_cache_or_die(refresh_flags);
-		update_main_cache_tree(1);
+		update_main_cache_tree(WRITE_TREE_SILENT);
 		if (write_cache(fd, active_cache, active_nr) ||
 		    close_lock_file(&index_lock))
 			die(_("unable to write new_index file"));
@@ -421,7 +421,7 @@ static char *prepare_index(int argc, const char **argv, const char *prefix,
 		fd = hold_locked_index(&index_lock, 1);
 		refresh_cache_or_die(refresh_flags);
 		if (active_cache_changed) {
-			update_main_cache_tree(1);
+			update_main_cache_tree(WRITE_TREE_SILENT);
 			if (write_cache(fd, active_cache, active_nr) ||
 			    commit_locked_index(&index_lock))
 				die(_("unable to write new_index file"));
cache-tree.c +12 -15
index 8de3959..16355d6 100644
@@ -150,9 +150,10 @@ void cache_tree_invalidate_path(struct cache_tree *it, const char *path)
 }
 
 static int verify_cache(struct cache_entry **cache,
-			int entries, int silent)
+			int entries, int flags)
 {
 	int i, funny;
+	int silent = flags & WRITE_TREE_SILENT;
 
 	/* Verify that the tree is merged */
 	funny = 0;
@@ -241,10 +242,11 @@ static int update_one(struct cache_tree *it,
 		      int entries,
 		      const char *base,
 		      int baselen,
-		      int missing_ok,
-		      int dryrun)
+		      int flags)
 {
 	struct strbuf buffer;
+	int missing_ok = flags & WRITE_TREE_MISSING_OK;
+	int dryrun = flags & WRITE_TREE_DRY_RUN;
 	int i;
 
 	if (0 <= it->entry_count && has_sha1_file(it->sha1))
@@ -288,8 +290,7 @@ static int update_one(struct cache_tree *it,
 				    cache + i, entries - i,
 				    path,
 				    baselen + sublen + 1,
-				    missing_ok,
-				    dryrun);
+				    flags);
 		if (subcnt < 0)
 			return subcnt;
 		i += subcnt - 1;
@@ -371,15 +372,13 @@ static int update_one(struct cache_tree *it,
 int cache_tree_update(struct cache_tree *it,
 		      struct cache_entry **cache,
 		      int entries,
-		      int missing_ok,
-		      int dryrun,
-		      int silent)
+		      int flags)
 {
 	int i;
-	i = verify_cache(cache, entries, silent);
+	i = verify_cache(cache, entries, flags);
 	if (i)
 		return i;
-	i = update_one(it, cache, entries, "", 0, missing_ok, dryrun);
+	i = update_one(it, cache, entries, "", 0, flags);
 	if (i < 0)
 		return i;
 	return 0;
@@ -572,11 +571,9 @@ int write_cache_as_tree(unsigned char *sha1, int flags, const char *prefix)
 
 	was_valid = cache_tree_fully_valid(active_cache_tree);
 	if (!was_valid) {
-		int missing_ok = flags & WRITE_TREE_MISSING_OK;
-
 		if (cache_tree_update(active_cache_tree,
 				      active_cache, active_nr,
-				      missing_ok, 0, 0) < 0)
+				      flags) < 0)
 			return WRITE_TREE_UNMERGED_INDEX;
 		if (0 <= newfd) {
 			if (!write_cache(newfd, active_cache, active_nr) &&
@@ -672,10 +669,10 @@ int cache_tree_matches_traversal(struct cache_tree *root,
 	return 0;
 }
 
-int update_main_cache_tree (int silent)
+int update_main_cache_tree (int flags)
 {
 	if (!the_index.cache_tree)
 		the_index.cache_tree = cache_tree();
 	return cache_tree_update(the_index.cache_tree,
-				 the_index.cache, the_index.cache_nr, 0, 0, silent);
+				 the_index.cache, the_index.cache_nr, flags);
 }
cache-tree.h +3 -1
index 0ec0b2a..d8cb2e9 100644
@@ -29,13 +29,15 @@ void cache_tree_write(struct strbuf *, struct cache_tree *root);
 struct cache_tree *cache_tree_read(const char *buffer, unsigned long size);
 
 int cache_tree_fully_valid(struct cache_tree *);
-int cache_tree_update(struct cache_tree *, struct cache_entry **, int, int, int, int);
+int cache_tree_update(struct cache_tree *, struct cache_entry **, int, int);
 
 int update_main_cache_tree(int);
 
 /* bitmasks to write_cache_as_tree flags */
 #define WRITE_TREE_MISSING_OK 1
 #define WRITE_TREE_IGNORE_CACHE_TREE 2
+#define WRITE_TREE_DRY_RUN 4
+#define WRITE_TREE_SILENT 8
 
 /* error return codes */
 #define WRITE_TREE_UNREADABLE_INDEX (-1)
merge-recursive.c +1 -1
index d83cd6c..6479a60 100644
@@ -264,7 +264,7 @@ struct tree *write_tree_from_memory(struct merge_options *o)
 
 	if (!cache_tree_fully_valid(active_cache_tree) &&
 	    cache_tree_update(active_cache_tree,
-			      active_cache, active_nr, 0, 0, 0) < 0)
+			      active_cache, active_nr, 0) < 0)
 		die("error building trees");
 
 	result = lookup_tree(active_cache_tree->sha1);
test-dump-cache-tree.c +1 -1
index e6c2923..a6ffdf3 100644
@@ -59,6 +59,6 @@ int main(int ac, char **av)
 	struct cache_tree *another = cache_tree();
 	if (read_cache() < 0)
 		die("unable to read index file");
-	cache_tree_update(another, active_cache, active_nr, 0, 1, 0);
+	cache_tree_update(another, active_cache, active_nr, WRITE_TREE_DRY_RUN);
 	return dump_cache_tree(active_cache_tree, another, "");
 }
Signature · 1 line
1.7.8.36.g69ee2
#2 lore raw

PATCH v2 2/4 commit: introduce a config key to allow as-is commit with i-t-a entries

In reply to Nguyễn Thái Ngọc Duy

"git add -N" is introduced some time ago to help prevent users's forgetting to add new files when committing. "git add -N" sets CE_INTENT_TO_ADD bit to index, hence i-t-a entries from now on. For safety reasons, as-is commits in the existence of i-t-a entries are rejected ("I intend to add these files. If I type "git commit -m foo", it may be a mistake if those files's contents are not added yet. Stop me in that case").

However unless you are doing "commit -a" or "commit pathspec", you are responsible for adding all contents you want to have in the commit before you run the "git commit" command (and for the purpose of this statement, "add -N" to tell Git to keey an eye on a path does _not_ add contents).

A change to the file in the working tree that is left unadded is what you decided to deliberately leave out of the commit, be it a change to a path already in HEAD, or a path marked with "add -N". Forgetting to add modified file and forgetting to add a file you earlier used "add -N" amount to the same kind of risk, and "git status" is the way to make sure your partial commit has exactly what you want. If you are not worried about partial commit, you would be doing "commit -a", so the "safety" is a moot point.

This patch is the beginning of the deprecation process to remove this safety check, allowing "git commit" to proceed anyway. The process consists of three steps to help users get used to new behavior:

1. Introduce a temporary config var, commit.ignoreIntentToAdd to help the migration process, default to false. If the var is true, the remove safety check.

Users who encounter the safety check are pointed to commit.ignoreIntentToAdd documentation and advised to set the variable to true.

2. A few releases after step 1 is out in the field, turn commit.ignoreIntentToAdd default value to true (affecting mostly new users).

Those who decided to stick to "false" from step 1 are warned the "false" support will soon be gone and encouraged to move to "true" (or simply remove the config variable).

Those who set the config to "true" is advised to remove it to keep config file clean.

Those who encountered the safety check and did not bother to set this config var is left out in the cold.

3. A few more releases after step 2, commit.ignoreIntentToAdd is removed. There's no way to bring back the safety check.

This patch implements step 1.

---
 Documentation/config.txt |   16 ++++++++++++++++
 builtin/commit.c         |   29 ++++++++++++++++++++++++++---
 cache-tree.c             |    8 +++++---
 cache-tree.h             |    1 +
 t/t2203-add-intent.sh    |   21 ++++++++++++++++++++-
 5 files changed, 68 insertions(+), 7 deletions(-)
Documentation/config.txt +16 -0
index abeb82b..6839e44 100644
@@ -831,6 +831,22 @@ commit.template::
 	"{tilde}/" is expanded to the value of `$HOME` and "{tilde}user/" to the
 	specified user's home directory.
 
+commit.ignoreIntentToAdd::
+	When set to `false`, prevent `git commit` from creating a
+	commit from an index that has entries that were added with
+	`git add -N` but have not been updated with real contents, as
+	the user may have forgotten to tell the final contents for
+	these entries.  Setting this to `true` makes `git commit`
+	pretend as if these entries do not exist in the index.
++
+The default for this variable is `false`, but it will change to `true`
+in future releases of git. To ease the transition, you may want to set
+it to `true` now and get used to the new behaviour early, or you may
+want to set it to `false` to keep the old behaviour a bit longer. We
+however expect to support setting this to `false` (to keep the current
+behaviour) only for a limited time after the default is changed to
+`true`.
+
 credential.helper::
 	Specify an external helper to be called when a username or
 	password credential is needed; the helper may consult external
builtin/commit.c +26 -3
index bf42bb3..da67653 100644
@@ -86,6 +86,7 @@ static int all, also, interactive, patch_interactive, only, amend, signoff;
 static int edit_flag = -1; /* unspecified */
 static int quiet, verbose, no_verify, allow_empty, dry_run, renew_authorship;
 static int no_post_rewrite, allow_empty_message;
+static int cache_tree_flags;
 static char *untracked_files_arg, *force_date, *ignore_submodule_arg;
 static char *sign_commit;
 
@@ -117,6 +118,8 @@ static enum {
 } status_format = STATUS_FORMAT_LONG;
 static int status_show_branch;
 
+static int set_commit_ignoreintenttoadd;
+
 static int opt_parse_m(const struct option *opt, const char *arg, int unset)
 {
 	struct strbuf *buf = opt->value;
@@ -400,7 +403,7 @@ static char *prepare_index(int argc, const char **argv, const char *prefix,
 		fd = hold_locked_index(&index_lock, 1);
 		add_files_to_cache(also ? prefix : NULL, pathspec, 0);
 		refresh_cache_or_die(refresh_flags);
-		update_main_cache_tree(WRITE_TREE_SILENT);
+		update_main_cache_tree(cache_tree_flags | WRITE_TREE_SILENT);
 		if (write_cache(fd, active_cache, active_nr) ||
 		    close_lock_file(&index_lock))
 			die(_("unable to write new_index file"));
@@ -420,8 +423,21 @@ static char *prepare_index(int argc, const char **argv, const char *prefix,
 	if (!pathspec || !*pathspec) {
 		fd = hold_locked_index(&index_lock, 1);
 		refresh_cache_or_die(refresh_flags);
+		if (!set_commit_ignoreintenttoadd) {
+			int i;
+			for (i = 0; i < active_nr; i++)
+				if (active_cache[i]->ce_flags & CE_INTENT_TO_ADD)
+					break;
+			if (i < active_nr) {
+				error(_("you intended to add \"%s\" but did not add it; not committing\n"
+					"hint: to commit all changes to tracked files, use \"commit -a\"\n"
+					"hint: to commit anyway without adding, set commit.ignoreIntentToAdd to true"),
+				      active_cache[i]->name);
+				exit(128); /* die() */
+			}
+		}
 		if (active_cache_changed) {
-			update_main_cache_tree(WRITE_TREE_SILENT);
+			update_main_cache_tree(cache_tree_flags | WRITE_TREE_SILENT);
 			if (write_cache(fd, active_cache, active_nr) ||
 			    commit_locked_index(&index_lock))
 				die(_("unable to write new_index file"));
@@ -870,7 +886,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
 	 */
 	discard_cache();
 	read_cache_from(index_file);
-	if (update_main_cache_tree(0)) {
+	if (update_main_cache_tree(cache_tree_flags)) {
 		error(_("Error building trees"));
 		return 0;
 	}
@@ -1338,6 +1354,13 @@ static int git_commit_config(const char *k, const char *v, void *cb)
 		include_status = git_config_bool(k, v);
 		return 0;
 	}
+	if (!strcmp(k, "commit.ignoreintenttoadd")) {
+		set_commit_ignoreintenttoadd = 1;
+		if (git_config_bool(k, v))
+			cache_tree_flags |= WRITE_TREE_IGNORE_INTENT_TO_ADD;
+		else
+			cache_tree_flags &= ~WRITE_TREE_IGNORE_INTENT_TO_ADD;
+	}
 
 	status = git_gpg_config(k, v, NULL);
 	if (status)
cache-tree.c +5 -3
index 16355d6..d0be159 100644
@@ -159,7 +159,9 @@ static int verify_cache(struct cache_entry **cache,
 	funny = 0;
 	for (i = 0; i < entries; i++) {
 		struct cache_entry *ce = cache[i];
-		if (ce_stage(ce) || (ce->ce_flags & CE_INTENT_TO_ADD)) {
+		if (ce_stage(ce) ||
+		    ((flags & WRITE_TREE_IGNORE_INTENT_TO_ADD) == 0 &&
+		     (ce->ce_flags & CE_INTENT_TO_ADD))) {
 			if (silent)
 				return -1;
 			if (10 < ++funny) {
@@ -339,8 +341,8 @@ static int update_one(struct cache_tree *it,
 				mode, sha1_to_hex(sha1), entlen+baselen, path);
 		}
 
-		if (ce->ce_flags & CE_REMOVE)
-			continue; /* entry being removed */
+		if (ce->ce_flags & (CE_REMOVE | CE_INTENT_TO_ADD))
+			continue; /* entry being removed or placeholder */
 
 		strbuf_grow(&buffer, entlen + 100);
 		strbuf_addf(&buffer, "%o %.*s%c", mode, entlen, path + baselen, '\0');
cache-tree.h +1 -0
index d8cb2e9..af3b917 100644
@@ -38,6 +38,7 @@ int update_main_cache_tree(int);
 #define WRITE_TREE_IGNORE_CACHE_TREE 2
 #define WRITE_TREE_DRY_RUN 4
 #define WRITE_TREE_SILENT 8
+#define WRITE_TREE_IGNORE_INTENT_TO_ADD 16
 
 /* error return codes */
 #define WRITE_TREE_UNREADABLE_INDEX (-1)
t/t2203-add-intent.sh +20 -1
index 58a3299..88a508e 100755
@@ -41,7 +41,26 @@ test_expect_success 'cannot commit with i-t-a entry' '
 	echo frotz >nitfol &&
 	git add rezrov &&
 	git add -N nitfol &&
-	test_must_fail git commit
+	test_must_fail git commit -minitial
+'
+
+test_expect_success 'can commit tree with i-t-a entry' '
+	git reset --hard &&
+	echo xyzzy >rezrov &&
+	echo frotz >nitfol &&
+	git add rezrov &&
+	git add -N nitfol &&
+	git config commit.ignoreIntentToAdd true &&
+	git commit -m initial &&
+	git ls-tree -r HEAD >actual &&
+	cat >expected <<EOF &&
+100644 blob ce013625030ba8dba906f756967f9e9ca394464a	elif
+100644 blob ce013625030ba8dba906f756967f9e9ca394464a	file
+100644 blob cf7711b63209d0dbc2d030f7fe3513745a9880e4	rezrov
+EOF
+	test_cmp expected actual &&
+	git config commit.ignoreIntentToAdd false &&
+	git reset HEAD^
 '
 
 test_expect_success 'can commit with an unrelated i-t-a entry in index' '
Signature · 1 line
1.7.8.36.g69ee2
#3 lore raw

PATCH v2 3/4 commit: turn commit.ignoreIntentToAdd to true by default

In reply to Nguyễn Thái Ngọc Duy

This is step 2 from commit.ignoreIntentToAdd deprecation plan. To recap:

2. A few releases after step 1 is out in the field, turn commit.ignoreIntentToAdd default value to true (affecting mostly new users).

Those who decided to stick to "false" from step 1 are warned the "false" support will soon be gone and encouraged to move to "true" (or simply remove the config variable).

Those who set the config to "true" is advised to remove it to keep config file clean.

Those who encountered the safety check and did not bother to set this config var is left out in the cold.

3. A few more releases after step 2, commit.ignoreIntentToAdd is removed. There's no way to bring back the safety check.

---
 Documentation/config.txt |   11 ++++-------
 builtin/commit.c         |   19 ++++++++++++++++---
 t/t2203-add-intent.sh    |    4 ++--
 3 files changed, 22 insertions(+), 12 deletions(-)
Documentation/config.txt +4 -7
index 6839e44..fa56753 100644
@@ -839,13 +839,10 @@ commit.ignoreIntentToAdd::
 	these entries.  Setting this to `true` makes `git commit`
 	pretend as if these entries do not exist in the index.
 +
-The default for this variable is `false`, but it will change to `true`
-in future releases of git. To ease the transition, you may want to set
-it to `true` now and get used to the new behaviour early, or you may
-want to set it to `false` to keep the old behaviour a bit longer. We
-however expect to support setting this to `false` (to keep the current
-behaviour) only for a limited time after the default is changed to
-`true`.
+The default for this variable is `true`. You are discouraged to set it
+to `false` to keep the old behaviour a bit longer because support
+setting this to `false` will be removed in future releases without
+warning.
 
 credential.helper::
 	Specify an external helper to be called when a username or
builtin/commit.c +16 -3
index da67653..cd28081 100644
@@ -423,15 +423,16 @@ static char *prepare_index(int argc, const char **argv, const char *prefix,
 	if (!pathspec || !*pathspec) {
 		fd = hold_locked_index(&index_lock, 1);
 		refresh_cache_or_die(refresh_flags);
-		if (!set_commit_ignoreintenttoadd) {
+		if (!(cache_tree_flags & WRITE_TREE_IGNORE_INTENT_TO_ADD)) {
 			int i;
 			for (i = 0; i < active_nr; i++)
 				if (active_cache[i]->ce_flags & CE_INTENT_TO_ADD)
 					break;
 			if (i < active_nr) {
 				error(_("you intended to add \"%s\" but did not add it; not committing\n"
-					"hint: to commit all changes to tracked files, use \"commit -a\"\n"
-					"hint: to commit anyway without adding, set commit.ignoreIntentToAdd to true"),
+					"this behavior is deprecated, please set commit.ignoreIntentToAdd\n"
+					"to true or remove the configuration variable. See the configuration\n"
+					"variable documentation for more information."),
 				      active_cache[i]->name);
 				exit(128); /* die() */
 			}
@@ -1424,6 +1425,9 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
 	git_config(git_commit_config, &s);
 	determine_whence(&s);
 
+	if (!set_commit_ignoreintenttoadd)
+		cache_tree_flags |= WRITE_TREE_IGNORE_INTENT_TO_ADD;
+
 	if (get_sha1("HEAD", sha1))
 		current_head = NULL;
 	else {
@@ -1583,5 +1587,14 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
 	if (!quiet)
 		print_summary(prefix, sha1, !current_head);
 
+	if (set_commit_ignoreintenttoadd) {
+		if (cache_tree_flags & WRITE_TREE_IGNORE_INTENT_TO_ADD)
+			warning(_("commit.ignoreIntentToAdd = true is not needed anymore.\n"
+				  "Please remove it."));
+		else
+			warning(_("commit.ignoreIntentToAdd = false is deprecated.\n"
+				  "Please see the commit.ignoreIntentToAdd documentation for\n"
+				  "more information and remove the configuration variable."));
+	}
 	return 0;
 }
t/t2203-add-intent.sh +2 -2
index 88a508e..09b8bbf 100755
@@ -41,11 +41,11 @@ test_expect_success 'cannot commit with i-t-a entry' '
 	echo frotz >nitfol &&
 	git add rezrov &&
 	git add -N nitfol &&
-	test_must_fail git commit -minitial
+	git commit -minitial
 '
 
 test_expect_success 'can commit tree with i-t-a entry' '
-	git reset --hard &&
+	git reset --hard HEAD^ &&
 	echo xyzzy >rezrov &&
 	echo frotz >nitfol &&
 	git add rezrov &&
Signature · 1 line
1.7.8.36.g69ee2
#4 lore raw

PATCH v2 4/4 commit: remove commit.ignoreIntentToAdd, assume it's always true

In reply to Nguyễn Thái Ngọc Duy
---
 Documentation/config.txt |   13 -------------
 builtin/commit.c         |   35 +----------------------------------
 t/t2203-add-intent.sh    |    4 ++--
 3 files changed, 3 insertions(+), 49 deletions(-)
Documentation/config.txt +0 -13
index fa56753..abeb82b 100644
@@ -831,19 +831,6 @@ commit.template::
 	"{tilde}/" is expanded to the value of `$HOME` and "{tilde}user/" to the
 	specified user's home directory.
 
-commit.ignoreIntentToAdd::
-	When set to `false`, prevent `git commit` from creating a
-	commit from an index that has entries that were added with
-	`git add -N` but have not been updated with real contents, as
-	the user may have forgotten to tell the final contents for
-	these entries.  Setting this to `true` makes `git commit`
-	pretend as if these entries do not exist in the index.
-+
-The default for this variable is `true`. You are discouraged to set it
-to `false` to keep the old behaviour a bit longer because support
-setting this to `false` will be removed in future releases without
-warning.
-
 credential.helper::
 	Specify an external helper to be called when a username or
 	password credential is needed; the helper may consult external
builtin/commit.c +1 -34
index cd28081..491cae1 100644
@@ -118,8 +118,6 @@ static enum {
 } status_format = STATUS_FORMAT_LONG;
 static int status_show_branch;
 
-static int set_commit_ignoreintenttoadd;
-
 static int opt_parse_m(const struct option *opt, const char *arg, int unset)
 {
 	struct strbuf *buf = opt->value;
@@ -423,20 +421,6 @@ static char *prepare_index(int argc, const char **argv, const char *prefix,
 	if (!pathspec || !*pathspec) {
 		fd = hold_locked_index(&index_lock, 1);
 		refresh_cache_or_die(refresh_flags);
-		if (!(cache_tree_flags & WRITE_TREE_IGNORE_INTENT_TO_ADD)) {
-			int i;
-			for (i = 0; i < active_nr; i++)
-				if (active_cache[i]->ce_flags & CE_INTENT_TO_ADD)
-					break;
-			if (i < active_nr) {
-				error(_("you intended to add \"%s\" but did not add it; not committing\n"
-					"this behavior is deprecated, please set commit.ignoreIntentToAdd\n"
-					"to true or remove the configuration variable. See the configuration\n"
-					"variable documentation for more information."),
-				      active_cache[i]->name);
-				exit(128); /* die() */
-			}
-		}
 		if (active_cache_changed) {
 			update_main_cache_tree(cache_tree_flags | WRITE_TREE_SILENT);
 			if (write_cache(fd, active_cache, active_nr) ||
@@ -1355,13 +1339,6 @@ static int git_commit_config(const char *k, const char *v, void *cb)
 		include_status = git_config_bool(k, v);
 		return 0;
 	}
-	if (!strcmp(k, "commit.ignoreintenttoadd")) {
-		set_commit_ignoreintenttoadd = 1;
-		if (git_config_bool(k, v))
-			cache_tree_flags |= WRITE_TREE_IGNORE_INTENT_TO_ADD;
-		else
-			cache_tree_flags &= ~WRITE_TREE_IGNORE_INTENT_TO_ADD;
-	}
 
 	status = git_gpg_config(k, v, NULL);
 	if (status)
@@ -1425,8 +1402,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
 	git_config(git_commit_config, &s);
 	determine_whence(&s);
 
-	if (!set_commit_ignoreintenttoadd)
-		cache_tree_flags |= WRITE_TREE_IGNORE_INTENT_TO_ADD;
+	cache_tree_flags |= WRITE_TREE_IGNORE_INTENT_TO_ADD;
 
 	if (get_sha1("HEAD", sha1))
 		current_head = NULL;
@@ -1587,14 +1563,5 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
 	if (!quiet)
 		print_summary(prefix, sha1, !current_head);
 
-	if (set_commit_ignoreintenttoadd) {
-		if (cache_tree_flags & WRITE_TREE_IGNORE_INTENT_TO_ADD)
-			warning(_("commit.ignoreIntentToAdd = true is not needed anymore.\n"
-				  "Please remove it."));
-		else
-			warning(_("commit.ignoreIntentToAdd = false is deprecated.\n"
-				  "Please see the commit.ignoreIntentToAdd documentation for\n"
-				  "more information and remove the configuration variable."));
-	}
 	return 0;
 }
t/t2203-add-intent.sh +2 -2
index 09b8bbf..6dbfb74 100755
@@ -44,13 +44,13 @@ test_expect_success 'cannot commit with i-t-a entry' '
 	git commit -minitial
 '
 
-test_expect_success 'can commit tree with i-t-a entry' '
+test_expect_success 'commit.ignoreIntentToAdd = false is ignored' '
 	git reset --hard HEAD^ &&
 	echo xyzzy >rezrov &&
 	echo frotz >nitfol &&
 	git add rezrov &&
 	git add -N nitfol &&
-	git config commit.ignoreIntentToAdd true &&
+	git config commit.ignoreIntentToAdd false &&
 	git commit -m initial &&
 	git ls-tree -r HEAD >actual &&
 	cat >expected <<EOF &&
Signature · 1 line
1.7.8.36.g69ee2
#5 lore raw
In reply to Nguyễn Thái Ngọc Duy
Quoted 4 lines · Nguyễn Thái Ngọc Duy

- git-add.txt changes are removed. In the end all kinds of commit behave the same way, not worth putting more explanation during the transition.

Quoted 8 lines

- reword config text and warning text (or more precisely copy/paste from Junio/Jonathan's words)

- Hard coded release numbers are removed. Now it's simply "in future".

- Step 2 may be too annoying. Users are warned on every commit if commit.ignoreIntentToAdd is set. I think it's good because it keeps config file clean, but people may think otherwise.

Ahh, thanks.

But when I said "let's admit that this is just fixing an UI mistake, no configuration, no options", I really meant it. Without the backward compatiblity "For now please do not fix this bug for me and keep being buggy until I get used to the non-buggy behaviour" fuss, which we never do to any bugfix.

That is how we are planning to handle "git merge" update to spawn editor in interactive session in the next release. There is no "Please keep the buggy behaviour" option; only an environment variable to help when we mistake a scripted use as interactive, whose support is not going away because it is not about "until I get used to the new behaviour".

#6 lore raw
Quoted 7 lines · Junio C Hamano

Ahh, thanks.

But when I said "let's admit that this is just fixing an UI mistake, no configuration, no options", I really meant it. Without the backward compatiblity "For now please do not fix this bug for me and keep being buggy until I get used to the non-buggy behaviour" fuss, which we never do to any bugfix.

Given that a patch to do so (with or without your 1/4 which is an independently good change) on top of an ancient v1.7.6 codebase looks like this, I am inclined to think this is the way to go.

I still need to review the existing documentation to see if anything needs to be fixed up, though.

-- >8 --
From: Junio C Hamano <[email protected]>
Subject: [PATCH] commit: ignore intent-to-add entries instead of refusing

Originally, "git add -N" was introduced to help users from forgetting to add new files to the index before they ran "git commit -a". As an attempt to help them further so that they do not forget to say "-a", "git commit" to commit the index as-is was taught to error out, reminding the user that they may have forgotten to add the final contents of the paths before running the command.

This turned out to be a false "safety" that is useless. If the user made changes to already tracked paths and paths added with "git add -N", and then ran "git add" to register the final contents of the paths added with "git add -N", "git commit" will happily create a commit out of the index, without including the local changes made to the already tracked paths. It was not a useful "safety" measure to prevent "forgetful" mistakes from happening.

It turns out that this behaviour is not just a useless false "safety", but actively hurts use cases of "git add -N" that were discovered later and have become popular, namely, to tell Git to be aware of these paths added by "git add -N", so that commands like "git status" and "git diff" would include them in their output, even though the user is not interested in including them in the next commit they are going to make.

Fix this ancient UI mistake, and instead make a commit from the index ignoring the paths added by "git add -N" without adding real contents.

Based on the work by Nguyễn Thái Ngọc Duy, and helped by injection of sanity from Jonathan Nieder and others on the Git mailing list.

---
* The last hunk of t2203 is because the test assumed the previous one failed to make a commit and "rezrov" in HEAD does not have "xyzzy". Now that the previous test creates a commit and records "xyzzy" in "rezrov", this test will fail with "Nothing to commit" without it.

 cache-tree.c          |    6 +++---
 t/t2203-add-intent.sh |    8 +++++---
 2 files changed, 8 insertions(+), 6 deletions(-)
cache-tree.c +3 -3
index f755590..ce0d0e3 100644
@@ -158,7 +158,7 @@ static int verify_cache(struct cache_entry **cache,
 	funny = 0;
 	for (i = 0; i < entries; i++) {
 		struct cache_entry *ce = cache[i];
-		if (ce_stage(ce) || (ce->ce_flags & CE_INTENT_TO_ADD)) {
+		if (ce_stage(ce)) {
 			if (10 < ++funny) {
 				fprintf(stderr, "...\n");
 				break;
@@ -336,8 +336,8 @@ static int update_one(struct cache_tree *it,
 				mode, sha1_to_hex(sha1), entlen+baselen, path);
 		}
 
-		if (ce->ce_flags & CE_REMOVE)
-			continue; /* entry being removed */
+		if (ce->ce_flags & (CE_REMOVE | CE_INTENT_TO_ADD))
+			continue; /* entry being removed or placeholder */
 
 		strbuf_grow(&buffer, entlen + 100);
 		strbuf_addf(&buffer, "%o %.*s%c", mode, entlen, path + baselen, '\0');
t/t2203-add-intent.sh +5 -3
index 2543529..ec35409 100755
@@ -32,7 +32,7 @@ test_expect_success 'intent to add does not clobber existing paths' '
 	! grep "$empty" actual
 '
 
-test_expect_success 'cannot commit with i-t-a entry' '
+test_expect_success 'i-t-a entry is simply ignored' '
 	test_tick &&
 	git commit -a -m initial &&
 	git reset --hard &&
@@ -41,12 +41,14 @@ test_expect_success 'cannot commit with i-t-a entry' '
 	echo frotz >nitfol &&
 	git add rezrov &&
 	git add -N nitfol &&
-	test_must_fail git commit -m initial
+	git commit -m second &&
+	test $(git ls-tree HEAD -- nitfol | wc -l) = 0 &&
+	test $(git diff --name-only HEAD -- nitfol | wc -l) = 1
 '
 
 test_expect_success 'can commit with an unrelated i-t-a entry in index' '
 	git reset --hard &&
-	echo xyzzy >rezrov &&
+	echo bozbar >rezrov &&
 	echo frotz >nitfol &&
 	git add rezrov &&
 	git add -N nitfol &&
Signature · 1 line
1.7.9.231.g87173
#7 lore raw
In reply to Junio C Hamano

2012/2/7 Junio C Hamano <[email protected]>:

Quoted 5 lines

But when I said "let's admit that this is just fixing an UI mistake, no configuration, no options", I really meant it.  Without the backward compatiblity "For now please do not fix this bug for me and keep being buggy until I get used to the non-buggy behaviour" fuss, which we never do to any bugfix.

Ahh I missed something again. Your patch looks good too.

Quoted 5 lines

That is how we are planning to handle "git merge" update to spawn editor in interactive session in the next release. There is no "Please keep the buggy behaviour" option; only an environment variable to help when we mistake a scripted use as interactive, whose support is not going away because it is not about "until I get used to the new behaviour".

Signature · 1 line
Duy
#8 lore raw
Quoted 8 lines · Nguyen Thai Ngoc Duy

2012/2/7 Junio C Hamano <[email protected]>:

Quoted 5 lines

But when I said "let's admit that this is just fixing an UI mistake, no configuration, no options", I really meant it. Without the backward compatiblity "For now please do not fix this bug for me and keep being buggy until I get used to the non-buggy behaviour" fuss, which we never do to any bugfix.

Ahh I missed something again. Your patch looks good too.

Ok, the strategy part is now behind us, but I have this slight suspicion (I didn't look at the code nor tried it out myself---I don't have time to do this myself today) that using this codepath might result in a corrupt cache-tree, whose entries point at a section of the index it covers as a subtree of the whole project but with incorrect counters or something like that. It would be good to make sure this "just ignoring i-t-a" is doing the right thing not to the resulting commit, but in the resulting index as well, before we go forward with this change.

#9 lore raw
Quoted 8 lines · Junio C Hamano

Ok, the strategy part is now behind us, but I have this slight suspicion (I didn't look at the code nor tried it out myself---I don't have time to do this myself today) that using this codepath might result in a corrupt cache-tree, whose entries point at a section of the index it covers as a subtree of the whole project but with incorrect counters or something like that.  It would be good to make sure this "just ignoring i-t-a" is doing the right thing not to the resulting commit, but in the resulting index as well, before we go forward with this change.

I looked a little bit and I think i-t-a entries do not break cache-tree. CE_REMOVE ones might though because they are taken into account in entry_count field, but they are not written down to file. Will look into it tonight.

Signature · 1 line
Duy