Re: [PATCH/GSoC] pull: implement --[no-]autostash for usage when rebasing

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

 



Hello everyone,

I want to participate in GSoC, and this is my microproject to get familiar
with git development.

I am a first year student, enrolled in the Computer Engineering program at
Silver Oak College of Engineering and Technology, Ahmedabad, India.
I have worked on open source software in the past, and have used git quite
a bit during that time. I'll include more details in my proposal, which
I'll send here when done.
I understand that this might be a bit late to get started, and I'll try my
best to get this patch in a good state and get the proposal ready ASAP.

As for the change, I spent a lot more time trying to get the test right
than doing the actual change, most of it trying to get familiar with the
test framework and figuring out what to use. It didn't take much time
though, overall.

I'm adding a few inline comments as I have a few questions.

On Sat, Mar 19, 2016 at 7:28 PM Chirayu Desai <chirayudesai1@xxxxxxxxx>
wrote:


Since 53c76dc0 pull understands the "rebase.autoStash" configuration
option, which was added to rebase in 58794775

This allows usage of the same option when running 'git pull --rebase',
passing it on to 'git rebase'

Signed-off-by: Chirayu Desai <chirayudesai1@xxxxxxxxx>
---
Documentation/git-pull.txt | 7 +++++++
builtin/pull.c | 10 ++++++++++
t/t5544-pull-autostash.sh | 37 +++++++++++++++++++++++++++++++++++++
3 files changed, 54 insertions(+)
create mode 100755 t/t5544-pull-autostash.sh

diff --git a/Documentation/git-pull.txt b/Documentation/git-pull.txt
index a62a2a615d..24db186c50 100644
--- a/Documentation/git-pull.txt
+++ b/Documentation/git-pull.txt
@@ -128,6 +128,13 @@ unless you have read linkgit:git-rebase[1] carefully.
--no-rebase::
Override earlier --rebase.

+--[no-]autostash::
+ Automatically create a temporary stash before the operation
+ begins, and apply it after the operation ends. This means
+ that you can run pull & rebase on a dirty worktree. However,
+ use with care: the final stash application after a successful
+ rebase might result in non-trivial conflicts.
+
Options related to fetching
~~~~~~~~~~~~~~~~~~~~~~~~~~~

diff --git a/builtin/pull.cb/builtin/pull.c
index 10eff03967..c22ce737ce 100644
--- a/builtin/pull.c
+++ b/builtin/pull.c
@@ -89,6 +89,7 @@ static char *opt_verify_signatures;
static struct argv_array opt_strategies = ARGV_ARRAY_INIT;
static struct argv_array opt_strategy_opts = ARGV_ARRAY_INIT;
static char *opt_gpg_sign;
+static char *opt_autostash;

/* Options passed to git-fetch */
static char *opt_all;
@@ -159,6 +160,8 @@ static struct option pull_options[] = {
OPT_PASSTHRU('S', "gpg-sign", &opt_gpg_sign, N_("key-id"),
N_("GPG sign commit"),
PARSE_OPT_OPTARG),
+ OPT_PASSTHRU(0, "autostash", &opt_autostash, NULL,
+ N_("automatically stash before pull, and apply it after rebase"),
PARSE_OPT_NOARG),


This shows only "--autostash" when you run 'git pull -help'

Any suggestions?


/* Options passed to git-fetch */
OPT_GROUP(N_("Options related to fetching")),
@@ -798,6 +801,9 @@ static int run_rebase(const unsigned char *curr_head,
else
argv_array_push(&args, sha1_to_hex(merge_head));

+ if (opt_autostash)
+ argv_array_push(&args, opt_autostash);
+
ret = run_command_v_opt(args.argv, RUN_GIT_CMD);
argv_array_clear(&args);
return ret;
@@ -841,6 +847,10 @@ int cmd_pull(int argc, const char **argv, const char
*prefix)
die(_("Updating an unborn branch with changes added to the index."));

git_config_get_bool("rebase.autostash", &autostash);
+ if (!strcmp(opt_autostash, "--autostash"))
+ autostash = 1;
+ if (!strcmp(opt_autostash, "--no-autostash"))
+ autostash = 0;
if (!autostash)
die_on_unclean_work_tree(prefix);

diff --git a/t/t5544-pull-autostash.sh b/t/t5544-pull-autostash.sh
new file mode 100755
index 0000000000..7f8309ef43
--- /dev/null
+++ b/t/t5544-pull-autostash.sh
@@ -0,0 +1,37 @@
+#!/bin/sh
+
+test_description='git pull --[no-]autostash tests'
+. ./test-lib.sh
+
+test_expect_success setup '
+ echo file >file &&
+ git add file &&
+ git commit -a -m original &&
+ git checkout -b test master &&
+ echo modified file >file &&
+ git commit -m file file
+'
+
+test_expect_success 'pull --rebase --autostash succeeds with dirty working
directory' '
+ git checkout -b test1 master &&
+ git reset --hard master &&
+ git log -1 &&
+ echo dirty >new_file &&
+ git add new_file &&
+ git pull --rebase --autostash . test &&


Would a test_comp_rev be needed / good here?

+ test "$(cat new_file)" = dirty &&
+ test "$(cat file)" = "modified file"
+'
+
+test_expect_success 'pull --rebase --no-autostash fails with dirty working
directory' '
+ git checkout -b test2 master &&
+ git reset --hard master &&
+ git log -1 &&
+ echo dirty >new_file &&
+ git add new_file &&
+ test_must_fail git pull --rebase --no-autostash . test &&


Same as above, test_comp_rev

+ test "$(cat new_file)" = dirty &&
+ test "$(cat file)" = "file"
+'
+
+test_done
\ No newline at end of file
--
2.7.4




Regards,

Chirayu Desai


On Sat, Mar 19, 2016 at 7:27 PM, Chirayu Desai <chirayudesai1@xxxxxxxxx> wrote:
> Since 53c76dc0 pull understands the "rebase.autoStash" configuration
> option, which was added to rebase in 58794775
>
> This allows usage of the same option when running 'git pull --rebase',
> passing it on to 'git rebase'
>
> Signed-off-by: Chirayu Desai <chirayudesai1@xxxxxxxxx>
> ---
>  Documentation/git-pull.txt |  7 +++++++
>  builtin/pull.c             | 10 ++++++++++
>  t/t5544-pull-autostash.sh  | 37 +++++++++++++++++++++++++++++++++++++
>  3 files changed, 54 insertions(+)
>  create mode 100755 t/t5544-pull-autostash.sh
>
> diff --git a/Documentation/git-pull.txt b/Documentation/git-pull.txt
> index a62a2a615d..24db186c50 100644
> --- a/Documentation/git-pull.txt
> +++ b/Documentation/git-pull.txt
> @@ -128,6 +128,13 @@ unless you have read linkgit:git-rebase[1] carefully.
>  --no-rebase::
>         Override earlier --rebase.
>
> +--[no-]autostash::
> +       Automatically create a temporary stash before the operation
> +       begins, and apply it after the operation ends.  This means
> +       that you can run pull & rebase on a dirty worktree.  However,
> +       use with care: the final stash application after a successful
> +       rebase might result in non-trivial conflicts.
> +
>  Options related to fetching
>  ~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> diff --git a/builtin/pull.c b/builtin/pull.c
> index 10eff03967..c22ce737ce 100644
> --- a/builtin/pull.c
> +++ b/builtin/pull.c
> @@ -89,6 +89,7 @@ static char *opt_verify_signatures;
>  static struct argv_array opt_strategies = ARGV_ARRAY_INIT;
>  static struct argv_array opt_strategy_opts = ARGV_ARRAY_INIT;
>  static char *opt_gpg_sign;
> +static char *opt_autostash;
>
>  /* Options passed to git-fetch */
>  static char *opt_all;
> @@ -159,6 +160,8 @@ static struct option pull_options[] = {
>         OPT_PASSTHRU('S', "gpg-sign", &opt_gpg_sign, N_("key-id"),
>                 N_("GPG sign commit"),
>                 PARSE_OPT_OPTARG),
> +       OPT_PASSTHRU(0, "autostash", &opt_autostash, NULL,
> +               N_("automatically stash before pull, and apply it after rebase"), PARSE_OPT_NOARG),
>
>         /* Options passed to git-fetch */
>         OPT_GROUP(N_("Options related to fetching")),
> @@ -798,6 +801,9 @@ static int run_rebase(const unsigned char *curr_head,
>         else
>                 argv_array_push(&args, sha1_to_hex(merge_head));
>
> +       if (opt_autostash)
> +               argv_array_push(&args, opt_autostash);
> +
>         ret = run_command_v_opt(args.argv, RUN_GIT_CMD);
>         argv_array_clear(&args);
>         return ret;
> @@ -841,6 +847,10 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
>                         die(_("Updating an unborn branch with changes added to the index."));
>
>                 git_config_get_bool("rebase.autostash", &autostash);
> +               if (!strcmp(opt_autostash, "--autostash"))
> +                       autostash = 1;
> +               if (!strcmp(opt_autostash, "--no-autostash"))
> +                       autostash = 0;
>                 if (!autostash)
>                         die_on_unclean_work_tree(prefix);
>
> diff --git a/t/t5544-pull-autostash.sh b/t/t5544-pull-autostash.sh
> new file mode 100755
> index 0000000000..7f8309ef43
> --- /dev/null
> +++ b/t/t5544-pull-autostash.sh
> @@ -0,0 +1,37 @@
> +#!/bin/sh
> +
> +test_description='git pull --[no-]autostash tests'
> +. ./test-lib.sh
> +
> +test_expect_success setup '
> +       echo file >file &&
> +       git add file &&
> +       git commit -a -m original &&
> +       git checkout -b test master &&
> +       echo modified file >file &&
> +       git commit -m file file
> +'
> +
> +test_expect_success 'pull --rebase --autostash succeeds with dirty working directory' '
> +       git checkout -b test1 master &&
> +       git reset --hard master &&
> +       git log -1 &&
> +       echo dirty >new_file &&
> +       git add new_file &&
> +       git pull --rebase --autostash . test &&
> +       test "$(cat new_file)" = dirty &&
> +       test "$(cat file)" = "modified file"
> +'
> +
> +test_expect_success 'pull --rebase --no-autostash fails with dirty working directory' '
> +       git checkout -b test2 master &&
> +       git reset --hard master &&
> +       git log -1 &&
> +       echo dirty >new_file &&
> +       git add new_file &&
> +       test_must_fail git pull --rebase --no-autostash . test &&
> +       test "$(cat new_file)" = dirty &&
> +       test "$(cat file)" = "file"
> +'
> +
> +test_done
> \ No newline at end of file
> --
> 2.7.4
>
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



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