From: Kunal Gangakhedkar <kunal.gangakhedkar@gmail.com>
To: gitster@pobox.com
Cc: git@vger.kernel.org, Kunal Gangakhedkar <kunal.gangakhedkar@gmail.com>
Subject: [PATCH] merge: Preserve ORIG_HEAD if already up-to-date with remote.
Date: Mon, 13 Jun 2011 13:05:25 +0530 [thread overview]
Message-ID: <1307950525-8011-2-git-send-email-kunal.gangakhedkar@gmail.com> (raw)
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
next prev parent reply other threads:[~2011-06-13 7:35 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-06-13 7:35 [PATCH] Preserve ORIG_HEAD if already up-to-date with remote Kunal Gangakhedkar
2011-06-13 7:35 ` Kunal Gangakhedkar [this message]
2011-06-14 23:14 ` [PATCH] merge: " Junio C Hamano
2011-07-17 16:31 ` Kunal Gangakhedkar
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1307950525-8011-2-git-send-email-kunal.gangakhedkar@gmail.com \
--to=kunal.gangakhedkar@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/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.
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 NNTP newsgroup(s).