{"thread":{"id":"41750","subject":"[PATCH/GSoC] pull: implement --[no-]autostash for usage when rebasing","startedAt":"2016-03-19T13:57:42Z","lastAt":"2016-03-19T14:31:38Z","messageCount":4,"participants":["Chirayu Desai","Sidhant Sharma"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"281230","messageId":"1458395862-5113-1-git-send-email-chirayudesai1@gmail.com","threadId":"41750","inReplyTo":null,"subject":"[PATCH/GSoC] pull: implement --[no-]autostash for usage when rebasing","fromName":"Chirayu Desai","fromEmail":"chirayudesai1@gmail.com","sentAt":"2016-03-19T13:57:42Z","receivedAt":"2016-03-19T13:57:42Z","isPatch":true,"sender":{"key":"chirayudesai1@gmail.com","avatar":"https://gravatar.com/avatar/c2d0bd062b197c940eaaf3ac349f63fdbe0df58a2421c140ee8c9b4f52af95e3?d=mp&s=160"},"body":"Since 53c76dc0 pull understands the \"rebase.autoStash\" configuration\noption, which was added to rebase in 58794775\n\nThis allows usage of the same option when running 'git pull --rebase',\npassing it on to 'git rebase'\n\nSigned-off-by: Chirayu Desai <chirayudesai1@gmail.com>\n---\n Documentation/git-pull.txt |  7 +++++++\n builtin/pull.c             | 10 ++++++++++\n t/t5544-pull-autostash.sh  | 37 +++++++++++++++++++++++++++++++++++++\n 3 files changed, 54 insertions(+)\n create mode 100755 t/t5544-pull-autostash.sh\n\ndiff --git a/Documentation/git-pull.txt b/Documentation/git-pull.txt\nindex a62a2a615d..24db186c50 100644\n--- a/Documentation/git-pull.txt\n+++ b/Documentation/git-pull.txt\n@@ -128,6 +128,13 @@ unless you have read linkgit:git-rebase[1] carefully.\n --no-rebase::\n \tOverride earlier --rebase.\n \n+--[no-]autostash::\n+\tAutomatically create a temporary stash before the operation\n+\tbegins, and apply it after the operation ends.  This means\n+\tthat you can run pull & rebase on a dirty worktree.  However,\n+\tuse with care: the final stash application after a successful\n+\trebase might result in non-trivial conflicts.\n+\n Options related to fetching\n ~~~~~~~~~~~~~~~~~~~~~~~~~~~\n \ndiff --git a/builtin/pull.c b/builtin/pull.c\nindex 10eff03967..c22ce737ce 100644\n--- a/builtin/pull.c\n+++ b/builtin/pull.c\n@@ -89,6 +89,7 @@ static char *opt_verify_signatures;\n static struct argv_array opt_strategies = ARGV_ARRAY_INIT;\n static struct argv_array opt_strategy_opts = ARGV_ARRAY_INIT;\n static char *opt_gpg_sign;\n+static char *opt_autostash;\n \n /* Options passed to git-fetch */\n static char *opt_all;\n@@ -159,6 +160,8 @@ static struct option pull_options[] = {\n \tOPT_PASSTHRU('S', \"gpg-sign\", &opt_gpg_sign, N_(\"key-id\"),\n \t\tN_(\"GPG sign commit\"),\n \t\tPARSE_OPT_OPTARG),\n+\tOPT_PASSTHRU(0, \"autostash\", &opt_autostash, NULL,\n+\t\tN_(\"automatically stash before pull, and apply it after rebase\"), PARSE_OPT_NOARG),\n \n \t/* Options passed to git-fetch */\n \tOPT_GROUP(N_(\"Options related to fetching\")),\n@@ -798,6 +801,9 @@ static int run_rebase(const unsigned char *curr_head,\n \telse\n \t\targv_array_push(&args, sha1_to_hex(merge_head));\n \n+\tif (opt_autostash)\n+\t\targv_array_push(&args, opt_autostash);\n+\n \tret = run_command_v_opt(args.argv, RUN_GIT_CMD);\n \targv_array_clear(&args);\n \treturn ret;\n@@ -841,6 +847,10 @@ int cmd_pull(int argc, const char **argv, const char *prefix)\n \t\t\tdie(_(\"Updating an unborn branch with changes added to the index.\"));\n \n \t\tgit_config_get_bool(\"rebase.autostash\", &autostash);\n+\t\tif (!strcmp(opt_autostash, \"--autostash\"))\n+\t\t\tautostash = 1;\n+\t\tif (!strcmp(opt_autostash, \"--no-autostash\"))\n+\t\t\tautostash = 0;\n \t\tif (!autostash)\n \t\t\tdie_on_unclean_work_tree(prefix);\n \ndiff --git a/t/t5544-pull-autostash.sh b/t/t5544-pull-autostash.sh\nnew file mode 100755\nindex 0000000000..7f8309ef43\n--- /dev/null\n+++ b/t/t5544-pull-autostash.sh\n@@ -0,0 +1,37 @@\n+#!/bin/sh\n+\n+test_description='git pull --[no-]autostash tests'\n+. ./test-lib.sh\n+\n+test_expect_success setup '\n+\techo file >file &&\n+\tgit add file &&\n+\tgit commit -a -m original &&\n+\tgit checkout -b test master &&\n+\techo modified file >file &&\n+\tgit commit -m file file\n+'\n+\n+test_expect_success 'pull --rebase --autostash succeeds with dirty working directory' '\n+\tgit checkout -b test1 master &&\n+\tgit reset --hard master &&\n+\tgit log -1 &&\n+\techo dirty >new_file &&\n+\tgit add new_file &&\n+\tgit pull --rebase --autostash . test &&\n+\ttest \"$(cat new_file)\" = dirty &&\n+\ttest \"$(cat file)\" = \"modified file\"\n+'\n+\n+test_expect_success 'pull --rebase --no-autostash fails with dirty working directory' '\n+\tgit checkout -b test2 master &&\n+\tgit reset --hard master &&\n+\tgit log -1 &&\n+\techo dirty >new_file &&\n+\tgit add new_file &&\n+\ttest_must_fail git pull --rebase --no-autostash . test &&\n+\ttest \"$(cat new_file)\" = dirty &&\n+\ttest \"$(cat file)\" = \"file\"\n+'\n+\n+test_done\n\\ No newline at end of file\n-- \n2.7.4\n"},{"id":"281231","messageId":"CAJj6+1ECzKw9jnO1wGZqSyrJ0V=G3TzzE5YKhSKzVO1kqXpXPw@mail.gmail.com","threadId":"41750","inReplyTo":"1458395862-5113-1-git-send-email-chirayudesai1@gmail.com","subject":"Re: [PATCH/GSoC] pull: implement --[no-]autostash for usage when rebasing","fromName":"Chirayu Desai","fromEmail":"chirayudesai1@gmail.com","sentAt":"2016-03-19T14:08:17Z","receivedAt":"2016-03-19T14:08:17Z","isPatch":true,"sender":{"key":"chirayudesai1@gmail.com","avatar":"https://gravatar.com/avatar/c2d0bd062b197c940eaaf3ac349f63fdbe0df58a2421c140ee8c9b4f52af95e3?d=mp&s=160"},"body":"Hello everyone,\n\nI want to participate in GSoC, and this is my microproject to get familiar\nwith git development.\n\nI am a first year student, enrolled in the Computer Engineering program at\nSilver Oak College of Engineering and Technology, Ahmedabad, India.\nI have worked on open source software in the past, and have used git quite\na bit during that time. I'll include more details in my proposal, which\nI'll send here when done.\nI understand that this might be a bit late to get started, and I'll try my\nbest to get this patch in a good state and get the proposal ready ASAP.\n\nAs for the change, I spent a lot more time trying to get the test right\nthan doing the actual change, most of it trying to get familiar with the\ntest framework and figuring out what to use. It didn't take much time\nthough, overall.\n\nI'm adding a few inline comments as I have a few questions.\n\nOn Sat, Mar 19, 2016 at 7:28 PM Chirayu Desai <chirayudesai1@gmail.com>\nwrote:\n\n\nSince 53c76dc0 pull understands the \"rebase.autoStash\" configuration\noption, which was added to rebase in 58794775\n\nThis allows usage of the same option when running 'git pull --rebase',\npassing it on to 'git rebase'\n\nSigned-off-by: Chirayu Desai <chirayudesai1@gmail.com>\n---\nDocumentation/git-pull.txt | 7 +++++++\nbuiltin/pull.c | 10 ++++++++++\nt/t5544-pull-autostash.sh | 37 +++++++++++++++++++++++++++++++++++++\n3 files changed, 54 insertions(+)\ncreate mode 100755 t/t5544-pull-autostash.sh\n\ndiff --git a/Documentation/git-pull.txt b/Documentation/git-pull.txt\nindex a62a2a615d..24db186c50 100644\n--- a/Documentation/git-pull.txt\n+++ b/Documentation/git-pull.txt\n@@ -128,6 +128,13 @@ unless you have read linkgit:git-rebase[1] carefully.\n--no-rebase::\nOverride earlier --rebase.\n\n+--[no-]autostash::\n+ Automatically create a temporary stash before the operation\n+ begins, and apply it after the operation ends. This means\n+ that you can run pull & rebase on a dirty worktree. However,\n+ use with care: the final stash application after a successful\n+ rebase might result in non-trivial conflicts.\n+\nOptions related to fetching\n~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\ndiff --git a/builtin/pull.cb/builtin/pull.c\nindex 10eff03967..c22ce737ce 100644\n--- a/builtin/pull.c\n+++ b/builtin/pull.c\n@@ -89,6 +89,7 @@ static char *opt_verify_signatures;\nstatic struct argv_array opt_strategies = ARGV_ARRAY_INIT;\nstatic struct argv_array opt_strategy_opts = ARGV_ARRAY_INIT;\nstatic char *opt_gpg_sign;\n+static char *opt_autostash;\n\n/* Options passed to git-fetch */\nstatic char *opt_all;\n@@ -159,6 +160,8 @@ static struct option pull_options[] = {\nOPT_PASSTHRU('S', \"gpg-sign\", &opt_gpg_sign, N_(\"key-id\"),\nN_(\"GPG sign commit\"),\nPARSE_OPT_OPTARG),\n+ OPT_PASSTHRU(0, \"autostash\", &opt_autostash, NULL,\n+ N_(\"automatically stash before pull, and apply it after rebase\"),\nPARSE_OPT_NOARG),\n\n\nThis shows only \"--autostash\" when you run 'git pull -help'\n\nAny suggestions?\n\n\n/* Options passed to git-fetch */\nOPT_GROUP(N_(\"Options related to fetching\")),\n@@ -798,6 +801,9 @@ static int run_rebase(const unsigned char *curr_head,\nelse\nargv_array_push(&args, sha1_to_hex(merge_head));\n\n+ if (opt_autostash)\n+ argv_array_push(&args, opt_autostash);\n+\nret = run_command_v_opt(args.argv, RUN_GIT_CMD);\nargv_array_clear(&args);\nreturn ret;\n@@ -841,6 +847,10 @@ int cmd_pull(int argc, const char **argv, const char\n*prefix)\ndie(_(\"Updating an unborn branch with changes added to the index.\"));\n\ngit_config_get_bool(\"rebase.autostash\", &autostash);\n+ if (!strcmp(opt_autostash, \"--autostash\"))\n+ autostash = 1;\n+ if (!strcmp(opt_autostash, \"--no-autostash\"))\n+ autostash = 0;\nif (!autostash)\ndie_on_unclean_work_tree(prefix);\n\ndiff --git a/t/t5544-pull-autostash.sh b/t/t5544-pull-autostash.sh\nnew file mode 100755\nindex 0000000000..7f8309ef43\n--- /dev/null\n+++ b/t/t5544-pull-autostash.sh\n@@ -0,0 +1,37 @@\n+#!/bin/sh\n+\n+test_description='git pull --[no-]autostash tests'\n+. ./test-lib.sh\n+\n+test_expect_success setup '\n+ echo file >file &&\n+ git add file &&\n+ git commit -a -m original &&\n+ git checkout -b test master &&\n+ echo modified file >file &&\n+ git commit -m file file\n+'\n+\n+test_expect_success 'pull --rebase --autostash succeeds with dirty working\ndirectory' '\n+ git checkout -b test1 master &&\n+ git reset --hard master &&\n+ git log -1 &&\n+ echo dirty >new_file &&\n+ git add new_file &&\n+ git pull --rebase --autostash . test &&\n\n\nWould a test_comp_rev be needed / good here?\n\n+ test \"$(cat new_file)\" = dirty &&\n+ test \"$(cat file)\" = \"modified file\"\n+'\n+\n+test_expect_success 'pull --rebase --no-autostash fails with dirty working\ndirectory' '\n+ git checkout -b test2 master &&\n+ git reset --hard master &&\n+ git log -1 &&\n+ echo dirty >new_file &&\n+ git add new_file &&\n+ test_must_fail git pull --rebase --no-autostash . test &&\n\n\nSame as above, test_comp_rev\n\n+ test \"$(cat new_file)\" = dirty &&\n+ test \"$(cat file)\" = \"file\"\n+'\n+\n+test_done\n\\ No newline at end of file\n--\n2.7.4\n\n\n\n\nRegards,\n\nChirayu Desai\n\n\nOn Sat, Mar 19, 2016 at 7:27 PM, Chirayu Desai <chirayudesai1@gmail.com> wrote:\n> Since 53c76dc0 pull understands the \"rebase.autoStash\" configuration\n> option, which was added to rebase in 58794775\n>\n> This allows usage of the same option when running 'git pull --rebase',\n> passing it on to 'git rebase'\n>\n> Signed-off-by: Chirayu Desai <chirayudesai1@gmail.com>\n> ---\n>  Documentation/git-pull.txt |  7 +++++++\n>  builtin/pull.c             | 10 ++++++++++\n>  t/t5544-pull-autostash.sh  | 37 +++++++++++++++++++++++++++++++++++++\n>  3 files changed, 54 insertions(+)\n>  create mode 100755 t/t5544-pull-autostash.sh\n>\n> diff --git a/Documentation/git-pull.txt b/Documentation/git-pull.txt\n> index a62a2a615d..24db186c50 100644\n> --- a/Documentation/git-pull.txt\n> +++ b/Documentation/git-pull.txt\n> @@ -128,6 +128,13 @@ unless you have read linkgit:git-rebase[1] carefully.\n>  --no-rebase::\n>         Override earlier --rebase.\n>\n> +--[no-]autostash::\n> +       Automatically create a temporary stash before the operation\n> +       begins, and apply it after the operation ends.  This means\n> +       that you can run pull & rebase on a dirty worktree.  However,\n> +       use with care: the final stash application after a successful\n> +       rebase might result in non-trivial conflicts.\n> +\n>  Options related to fetching\n>  ~~~~~~~~~~~~~~~~~~~~~~~~~~~\n>\n> diff --git a/builtin/pull.c b/builtin/pull.c\n> index 10eff03967..c22ce737ce 100644\n> --- a/builtin/pull.c\n> +++ b/builtin/pull.c\n> @@ -89,6 +89,7 @@ static char *opt_verify_signatures;\n>  static struct argv_array opt_strategies = ARGV_ARRAY_INIT;\n>  static struct argv_array opt_strategy_opts = ARGV_ARRAY_INIT;\n>  static char *opt_gpg_sign;\n> +static char *opt_autostash;\n>\n>  /* Options passed to git-fetch */\n>  static char *opt_all;\n> @@ -159,6 +160,8 @@ static struct option pull_options[] = {\n>         OPT_PASSTHRU('S', \"gpg-sign\", &opt_gpg_sign, N_(\"key-id\"),\n>                 N_(\"GPG sign commit\"),\n>                 PARSE_OPT_OPTARG),\n> +       OPT_PASSTHRU(0, \"autostash\", &opt_autostash, NULL,\n> +               N_(\"automatically stash before pull, and apply it after rebase\"), PARSE_OPT_NOARG),\n>\n>         /* Options passed to git-fetch */\n>         OPT_GROUP(N_(\"Options related to fetching\")),\n> @@ -798,6 +801,9 @@ static int run_rebase(const unsigned char *curr_head,\n>         else\n>                 argv_array_push(&args, sha1_to_hex(merge_head));\n>\n> +       if (opt_autostash)\n> +               argv_array_push(&args, opt_autostash);\n> +\n>         ret = run_command_v_opt(args.argv, RUN_GIT_CMD);\n>         argv_array_clear(&args);\n>         return ret;\n> @@ -841,6 +847,10 @@ int cmd_pull(int argc, const char **argv, const char *prefix)\n>                         die(_(\"Updating an unborn branch with changes added to the index.\"));\n>\n>                 git_config_get_bool(\"rebase.autostash\", &autostash);\n> +               if (!strcmp(opt_autostash, \"--autostash\"))\n> +                       autostash = 1;\n> +               if (!strcmp(opt_autostash, \"--no-autostash\"))\n> +                       autostash = 0;\n>                 if (!autostash)\n>                         die_on_unclean_work_tree(prefix);\n>\n> diff --git a/t/t5544-pull-autostash.sh b/t/t5544-pull-autostash.sh\n> new file mode 100755\n> index 0000000000..7f8309ef43\n> --- /dev/null\n> +++ b/t/t5544-pull-autostash.sh\n> @@ -0,0 +1,37 @@\n> +#!/bin/sh\n> +\n> +test_description='git pull --[no-]autostash tests'\n> +. ./test-lib.sh\n> +\n> +test_expect_success setup '\n> +       echo file >file &&\n> +       git add file &&\n> +       git commit -a -m original &&\n> +       git checkout -b test master &&\n> +       echo modified file >file &&\n> +       git commit -m file file\n> +'\n> +\n> +test_expect_success 'pull --rebase --autostash succeeds with dirty working directory' '\n> +       git checkout -b test1 master &&\n> +       git reset --hard master &&\n> +       git log -1 &&\n> +       echo dirty >new_file &&\n> +       git add new_file &&\n> +       git pull --rebase --autostash . test &&\n> +       test \"$(cat new_file)\" = dirty &&\n> +       test \"$(cat file)\" = \"modified file\"\n> +'\n> +\n> +test_expect_success 'pull --rebase --no-autostash fails with dirty working directory' '\n> +       git checkout -b test2 master &&\n> +       git reset --hard master &&\n> +       git log -1 &&\n> +       echo dirty >new_file &&\n> +       git add new_file &&\n> +       test_must_fail git pull --rebase --no-autostash . test &&\n> +       test \"$(cat new_file)\" = dirty &&\n> +       test \"$(cat file)\" = \"file\"\n> +'\n> +\n> +test_done\n> \\ No newline at end of file\n> --\n> 2.7.4\n>\n"},{"id":"281232","messageId":"56ED60FD.1030005@gmail.com","threadId":"41750","inReplyTo":"CAJj6+1ECzKw9jnO1wGZqSyrJ0V=G3TzzE5YKhSKzVO1kqXpXPw@mail.gmail.com","subject":"Re: [PATCH/GSoC] pull: implement --[no-]autostash for usage when rebasing","fromName":"Sidhant Sharma","fromEmail":"tigerkid001@gmail.com","sentAt":"2016-03-19T14:23:57Z","receivedAt":"2016-03-19T14:23:57Z","isPatch":true,"sender":{"key":"tigerkid001@gmail.com","avatar":"https://avatars.githubusercontent.com/u/7801881?v=4"},"body":"\nOn Saturday 19 March 2016 07:38 PM, Chirayu Desai wrote:\n> Hello everyone,\n>\n> I want to participate in GSoC, and this is my microproject to get familiar\n> with git development.\n>\n> I am a first year student, enrolled in the Computer Engineering program at\n> Silver Oak College of Engineering and Technology, Ahmedabad, India.\n> I have worked on open source software in the past, and have used git quite\n> a bit during that time. I'll include more details in my proposal, which\n> I'll send here when done.\n> I understand that this might be a bit late to get started, and I'll try my\n> best to get this patch in a good state and get the proposal ready ASAP.\n>\n> As for the change, I spent a lot more time trying to get the test right\n> than doing the actual change, most of it trying to get familiar with the\n> test framework and figuring out what to use. It didn't take much time\n> though, overall.\n>\n> I'm adding a few inline comments as I have a few questions.\nHi,\n\nThanks for the patch. I believe there already is work in progress on this (See\n[1] and [2]). You may want to try another microproject. It may also be a good\nidea to mention which GSoC project idea you would like to work on, as there\nalready may be other proposals on their way.\n\n\nThanks and regards,\nSidhant Sharma\n\n[1] http://thread.gmane.org/gmane.comp.version-control.git/287568/focus=287569\n[2] http://thread.gmane.org/gmane.comp.version-control.git/289127/focus=289222\n"},{"id":"281233","messageId":"CAJj6+1F6eAyhs8xxtukKw+sCE63ASq=K+hxtH8VC95FEuNKGBQ@mail.gmail.com","threadId":"41750","inReplyTo":"56ED60FD.1030005@gmail.com","subject":"Re: [PATCH/GSoC] pull: implement --[no-]autostash for usage when rebasing","fromName":"Chirayu Desai","fromEmail":"chirayudesai1@gmail.com","sentAt":"2016-03-19T14:31:38Z","receivedAt":"2016-03-19T14:31:38Z","isPatch":true,"sender":{"key":"chirayudesai1@gmail.com","avatar":"https://gravatar.com/avatar/c2d0bd062b197c940eaaf3ac349f63fdbe0df58a2421c140ee8c9b4f52af95e3?d=mp&s=160"},"body":"Apologies, I did not see the patch, I looked for threads with GSoC in\ntheir titles but missed looking for \"rebase\" / this microproject. I'll\ngo through the list and make sure it hasn't been picked yet.\n\nAs for the GSoC project idea, I was thinking of \"Git remote\nwhitelist/blacklist\", and writing another e-mail to this list for\ndiscussion, however I felt that it might be a little less to do as a\nwhole for GSoC, so I was trying to pick something else to do alongwith\nthis.\n\nI'll make sure I check the existing applications and threads.\n\nThanks,\nChirayu Desai\n\nOn Sat, Mar 19, 2016 at 7:53 PM, Sidhant Sharma <tigerkid001@gmail.com> wrote:\n>\n> On Saturday 19 March 2016 07:38 PM, Chirayu Desai wrote:\n>> Hello everyone,\n>>\n>> I want to participate in GSoC, and this is my microproject to get familiar\n>> with git development.\n>>\n>> I am a first year student, enrolled in the Computer Engineering program at\n>> Silver Oak College of Engineering and Technology, Ahmedabad, India.\n>> I have worked on open source software in the past, and have used git quite\n>> a bit during that time. I'll include more details in my proposal, which\n>> I'll send here when done.\n>> I understand that this might be a bit late to get started, and I'll try my\n>> best to get this patch in a good state and get the proposal ready ASAP.\n>>\n>> As for the change, I spent a lot more time trying to get the test right\n>> than doing the actual change, most of it trying to get familiar with the\n>> test framework and figuring out what to use. It didn't take much time\n>> though, overall.\n>>\n>> I'm adding a few inline comments as I have a few questions.\n> Hi,\n>\n> Thanks for the patch. I believe there already is work in progress on this (See\n> [1] and [2]). You may want to try another microproject. It may also be a good\n> idea to mention which GSoC project idea you would like to work on, as there\n> already may be other proposals on their way.\n>\n>\n> Thanks and regards,\n> Sidhant Sharma\n>\n> [1] http://thread.gmane.org/gmane.comp.version-control.git/287568/focus=287569\n> [2] http://thread.gmane.org/gmane.comp.version-control.git/289127/focus=289222\n>\n"}]}