Re: [PATCH 2/4] stash: convert branch to builtin
On Sat, Mar 24, 2018 at 1:37 PM, Joel Teichroeb <joel@teichroeb.net> wrote:
Show 14 quoted lines
> diff --git a/builtin/stash--helper.c b/builtin/stash--helper.c
> @@ -307,6 +313,42 @@ static int apply_stash(int argc, const char **argv, const char *prefix)
> +static int branch_stash(int argc, const char **argv, const char *prefix)
> +{
> + const char *commit = NULL, *branch = NULL;
> +
> + argc = parse_options(argc, argv, prefix, options,
> + git_stash_helper_branch_usage, 0);
> +
> + if (argc != 0) {
> + branch = argv[0];
> + if (argc == 2)
> + commit = argv[1];
> + }This seems fragile. What happens if there are three args?
Show 16 quoted lines
> + if (get_stash_info(&info, commit))
> + return -1;
> +
> + argv_array_pushl(&args, "checkout", "-b", NULL);
> + argv_array_push(&args, branch);
> + argv_array_push(&args, sha1_to_hex(info.b_commit.hash));
> + ret = cmd_checkout(args.argc, args.argv, prefix);
> + if (ret)
> + return -1;
> +
> + ret = do_apply_stash(prefix, &info, 1);
> + if (!ret && info.is_stash_ref)
> + ret = do_drop_stash(prefix, &info);
> +
> + return ret;
> +}