Re: [PATCH] Give git-pull a --reset option

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

 



On Wed, Apr 17, 2019 at 12:07 AM Alex Henrie <alexhenrie24@xxxxxxxxx> wrote:
> A common workflow is to make a commit on a local branch, push the branch
> to the remote, check out the remote branch on a second computer, amend
> the commit on the second computer, force-push back to the remote branch,
> and finally submit a pull request. However, if the user switches back to
> the first computer, they must then run the cumbersome command
> `git fetch && git reset --hard origin`. (Actually, at this point Git
> novices often try running `git pull --force`, but it doesn't do what
> they expect.) This patch adds the shortcut `git pull --reset` to serve
> as a complement to `git push --force`.

I didn't know this was a particularly common workflow, although I
admit to working this way myself often enough.

> Signed-off-by: Alex Henrie <alexhenrie24@xxxxxxxxx>
> ---
>  Documentation/git-pull.txt |  8 ++++++++
>  builtin/pull.c             | 28 ++++++++++++++++++++++++++++

Perhaps add a test or two to t/t5520-pull.sh covering this new feature.

> diff --git a/builtin/pull.c b/builtin/pull.c
> @@ -860,6 +864,21 @@ static int run_rebase(const struct object_id *curr_head,
> +/**
> + * Runs git-reset, returning its exit status.
> + */
> +static int run_reset(void)
> +{
> +       int ret;
> +       struct argv_array args = ARGV_ARRAY_INIT;

In this codebase, it's typical to have a blank line following the declarations.

> +       argv_array_pushl(&args, "reset", NULL);
> +       argv_array_push(&args, "--hard");
> +       argv_array_push(&args, "FETCH_HEAD");

Not sure why you're using "pushl" for the first and then plain "push"
for the rest. With "pushl", the entire setup can be collapsed to:

    argv_array_pushl(&args, "reset", "--hard", "FETCH_HEAD", NULL);

But, given that this argument list isn't dynamic, you could simplify
further by just declaring:

    const char *argv[] = { "reset", "--hard", "FETCH_HEAD", NULL };

> +       ret = run_command_v_opt(args.argv, RUN_GIT_CMD);
> +       argv_array_clear(&args);

...and do away with the argv_array_clear() altogether.

> +       return ret;
> +}

In fact, taking these suggestions into account, the code collapses to
just two lines, which you could easily inline into the sole caller,
thus you don't need a separate function at all.

> @@ -892,6 +911,9 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
> +       if (opt_rebase && opt_reset)
> +               die(_("--rebase and --reset are mutually exclusive."));

Modern practice on this project is to not end these messages with a
period, however, as most messages in this file currently end with a
period, this may be okay.

>         if (!opt_rebase && opt_autostash != -1)
>                 die(_("--[no-]autostash option is only valid with --rebase."));



[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]

  Powered by Linux