git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] merge: Preserve ORIG_HEAD if already up-to-date with remote.

From
KGKunal Gangakhedkar <kunal.gangakhedkar@gmail.com>
Date
Jun 13, 2011, 07:35 UTC
Message-ID
<1307950525-8011-2-git-send-email-kunal.gangakhedkar@gmail.com>
In-Reply-To
<1307950525-8011-1-git-send-email-kunal.gangakhedkar@gmail.com>

Do not update ORIG_HEAD ref to current HEAD if the repo is already in-sync with the remote.

Otherwise, it becomes difficult to keep track of last set of changes.

With this patch, it's possible to do a diffstat/log for last set of changes even after a pull/merge that returns 'Already up-to-date'. This is especially useful when the pull is performed via a cronjob/script.

The old behaviour can still be forced via: o. --force-update-orig-head cmd line option o. merge.forceupdateorighead config option

Signed-off-by: Kunal Gangakhedkar <kunal.gangakhedkar@gmail.com>
---
 builtin/merge.c |   26 ++++++++++++++++++++++++--
 1 files changed, 24 insertions(+), 2 deletions(-)
diff --git a/builtin/merge.c b/builtin/merge.c
index 325891e..6ac26f0 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -63,6 +63,7 @@ static int allow_rerere_auto;
 static int abort_current_merge;
 static int show_progress = -1;
 static int default_to_upstream;
+static int force_update_orig_head = 0;
 
 static struct strategy all_strategy[] = {
 	{ "recursive",  DEFAULT_TWOHEAD | NO_TRIVIAL },
@@ -206,6 +207,8 @@ static struct option builtin_merge_options[] = {
 	OPT_BOOLEAN(0, "abort", &abort_current_merge,
 		"abort the current in-progress merge"),
 	OPT_SET_INT(0, "progress", &show_progress, "force progress reporting", 1),
+	OPT_BOOLEAN(0, "force-update-orig-head", &force_update_orig_head,
+			"force-update ORIG_HEAD even if in sync with remote"),
 	OPT_END()
 };
 
@@ -563,7 +566,11 @@ static int git_merge_config(const char *k, const char *v, void *cb)
 	} else if (!strcmp(k, "merge.defaulttoupstream")) {
 		default_to_upstream = git_config_bool(k, v);
 		return 0;
+	} else if (!strcmp(k, "merge.forceupdateorighead")) {
+		force_update_orig_head = git_config_bool(k, v);
+		return 0;
 	}
+
 	return git_diff_ui_config(k, v, cb);
 }
 
@@ -1017,6 +1024,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
 	struct commit_list *common = NULL;
 	const char *best_strategy = NULL, *wt_strategy = NULL;
 	struct commit_list **remotes = &remoteheads;
+	int orig_head_updated = 0;
 
 	if (argc == 2 && !strcmp(argv[1], "-h"))
 		usage_with_options(builtin_merge_usage, builtin_merge_options);
@@ -1212,8 +1220,11 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
 		free(list);
 	}
 
-	update_ref("updating ORIG_HEAD", "ORIG_HEAD", head, NULL, 0,
-		DIE_ON_ERR);
+	if (force_update_orig_head) {
+		update_ref("updating ORIG_HEAD", "ORIG_HEAD", head, NULL, 0,
+			DIE_ON_ERR);
+		orig_head_updated = 1;
+	}
 
 	if (!common)
 		; /* No common ancestors found. We need a real merge. */
@@ -1254,6 +1265,11 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
 
 		finish(o->sha1, msg.buf);
 		drop_save();
+		if (!orig_head_updated) {
+			update_ref("updating ORIG_HEAD", "ORIG_HEAD", head, NULL, 0,
+				DIE_ON_ERR);
+			orig_head_updated = 1;
+		}
 		return 0;
 	} else if (!remoteheads->next && common->next)
 		;
@@ -1306,6 +1322,12 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
 		}
 	}
 
+	if (!orig_head_updated) {
+		update_ref("updating ORIG_HEAD", "ORIG_HEAD", head, NULL, 0,
+			DIE_ON_ERR);
+		orig_head_updated = 1;
+	}
+
 	if (fast_forward_only)
 		die(_("Not possible to fast-forward, aborting."));
 
-- 
1.7.6.rc1.2.g20c4a.dirty
Previous: Kunal GangakhedkarNext: Junio C Hamano
Message 2 of 4 in “Preserve ORIG_HEAD if already up-to-date with remote.”
  1. Preserve ORIG_HEAD if already up-to-date with remote.Kunal Gangakhedkar, Jun 13, 2011
  2. merge: Preserve ORIG_HEAD if already up-to-date with remote.Kunal Gangakhedkar, Jun 13, 2011
  3. Junio C HamanoJun 14, 2011
  4. Kunal GangakhedkarJul 17, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.