Re: [PATCH v2 13/19] pull: implement pulling into an unborn branch
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Jun 10, 2015, 01:31 UTC
- Message-ID
- <xmqqoakouz5k.fsf@gitster.dls.corp.google.com>
- In-Reply-To
- <1433314143-4478-14-git-send-email-pyokagan@gmail.com>
Paul Tan <pyokagan@gmail.com> writes:
Show 6 quoted lines
> /**
> + * "Pulls into void" by branching off merge_head.
> + */
> +static int pull_into_void(unsigned char merge_head[GIT_SHA1_RAWSZ],
> + unsigned char curr_head[GIT_SHA1_RAWSZ])
> +{It is not wrong per-se, but is rather unusual (and misleading) to specify the array-ness and array-size of parameters. Our codebase tends to prefer spelling it like so instead:
static int pull_into_void(unsigned char *merge_head,
unsigned char *curr_head)
{> + /* > + * Two-way merge: we claim the index is based on an empty tree,
s/claim/treat/ perhaps?
Show 29 quoted lines
> + * and try to fast-forward to HEAD. This ensures we will not lose
> + * index/worktree changes that the user already made on the unborn
> + * branch.
> + */
> + if (checkout_fast_forward(EMPTY_TREE_SHA1_BIN, merge_head, 0))
> + return 1;
> +
> + if (update_ref("initial pull", "HEAD", merge_head, curr_head, 0, UPDATE_REFS_DIE_ON_ERR))
> + return 1;
> +
> + return 0;
> +}
> +
> +/**
> * Runs git-merge, returning its exit status.
> */
> static int run_merge(void)
> @@ -475,5 +497,10 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
> if (!merge_heads.nr)
> die_no_merge_candidates(repo, refspecs);
>
> - return run_merge();
> + if (is_null_sha1(orig_head)) {
> + if (merge_heads.nr > 1)
> + die(_("Cannot merge multiple branches into empty head."));
> + return pull_into_void(*merge_heads.sha1, curr_head);
> + } else
> + return run_merge();
> }Sensible.