[PATCH 7/9] commit: give empty-commit avoidance code its own function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



With v1.7.1.1~16^2 (commit: give advice on empty amend, 2010-06-06),
"git commit" was taught to provide some extra advice in response to
attempts to amend a commit into emptiness, but "git commit --amend
--dry-run" was not updated to match.  Split out a function that could
be used to carry out such an update if it seems to be a good idea.

Signed-off-by: Jonathan Nieder <jrnieder@xxxxxxxxx>
---
 builtin/commit.c |   24 ++++++++++++++++++------
 1 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/builtin/commit.c b/builtin/commit.c
index 85e560e..febefee 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -705,6 +705,18 @@ static int something_is_staged(void)
 		return index_differs_from(parent, 0);
 }
 
+static int empty_commit_ok(const char *index_file, const char *prefix,
+				struct wt_status *s)
+{
+	if (in_merge || allow_empty || (amend && is_a_merge(head_sha1)))
+		return 1;
+
+	run_status(stdout, index_file, prefix, 0, s);
+	if (amend)
+		fputs(empty_amend_advice, stderr);
+	return 0;
+}
+
 static int prepare_to_commit(const char *index_file, const char *prefix,
 			     struct wt_status *s)
 {
@@ -745,13 +757,13 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
 
 	fclose(fp);
 
-	if (!commitable && !in_merge && !allow_empty &&
-	    !(amend && is_a_merge(head_sha1))) {
-		run_status(stdout, index_file, prefix, 0, s);
-		if (amend)
-			fputs(empty_amend_advice, stderr);
+	/*
+	 * If there is nothing staged for commit, this is not a
+	 * merge, and --allow-empty was not supplied, dump status
+	 * followed by some hints for staging changes.
+	 */
+	if (!commitable && !empty_commit_ok(index_file, prefix, s))
 		return 0;
-	}
 
 	/*
 	 * Re-read the index as pre-commit hook could have updated it,
-- 
1.7.2.9.ge3789.dirty

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]