pull: fast-forward working tree if head is updated
Since b10ac50
(Fix pulling into the same branch., 2005-08-25), git-pull,
upon detecting that git-fetch updated the current head, will
fast-forward the working tree to the updated head commit.
Re-implement this behavior.
Signed-off-by: Paul Tan <pyokagan@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
maint
parent
4a4cf9e821
commit
fe911b8ca0
|
@ -412,6 +412,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
|
||||||
{
|
{
|
||||||
const char *repo, **refspecs;
|
const char *repo, **refspecs;
|
||||||
struct sha1_array merge_heads = SHA1_ARRAY_INIT;
|
struct sha1_array merge_heads = SHA1_ARRAY_INIT;
|
||||||
|
unsigned char orig_head[GIT_SHA1_RAWSZ], curr_head[GIT_SHA1_RAWSZ];
|
||||||
|
|
||||||
if (!getenv("_GIT_USE_BUILTIN_PULL")) {
|
if (!getenv("_GIT_USE_BUILTIN_PULL")) {
|
||||||
const char *path = mkpath("%s/git-pull", git_exec_path());
|
const char *path = mkpath("%s/git-pull", git_exec_path());
|
||||||
|
@ -435,12 +436,41 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
|
||||||
if (file_exists(git_path("MERGE_HEAD")))
|
if (file_exists(git_path("MERGE_HEAD")))
|
||||||
die_conclude_merge();
|
die_conclude_merge();
|
||||||
|
|
||||||
|
if (get_sha1("HEAD", orig_head))
|
||||||
|
hashclr(orig_head);
|
||||||
|
|
||||||
if (run_fetch(repo, refspecs))
|
if (run_fetch(repo, refspecs))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
if (opt_dry_run)
|
if (opt_dry_run)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
if (get_sha1("HEAD", curr_head))
|
||||||
|
hashclr(curr_head);
|
||||||
|
|
||||||
|
if (!is_null_sha1(orig_head) && !is_null_sha1(curr_head) &&
|
||||||
|
hashcmp(orig_head, curr_head)) {
|
||||||
|
/*
|
||||||
|
* The fetch involved updating the current branch.
|
||||||
|
*
|
||||||
|
* The working tree and the index file are still based on
|
||||||
|
* orig_head commit, but we are merging into curr_head.
|
||||||
|
* Update the working tree to match curr_head.
|
||||||
|
*/
|
||||||
|
|
||||||
|
warning(_("fetch updated the current branch head.\n"
|
||||||
|
"fast-forwarding your working tree from\n"
|
||||||
|
"commit %s."), sha1_to_hex(orig_head));
|
||||||
|
|
||||||
|
if (checkout_fast_forward(orig_head, curr_head, 0))
|
||||||
|
die(_("Cannot fast-forward your working tree.\n"
|
||||||
|
"After making sure that you saved anything precious from\n"
|
||||||
|
"$ git diff %s\n"
|
||||||
|
"output, run\n"
|
||||||
|
"$ git reset --hard\n"
|
||||||
|
"to recover."), sha1_to_hex(orig_head));
|
||||||
|
}
|
||||||
|
|
||||||
get_merge_heads(&merge_heads);
|
get_merge_heads(&merge_heads);
|
||||||
|
|
||||||
if (!merge_heads.nr)
|
if (!merge_heads.nr)
|
||||||
|
|
Loading…
Reference in New Issue