From: Chirayu Desai <chirayudesai1@gmail.com>
To: git@vger.kernel.org
Cc: Chirayu Desai <chirayudesai1@gmail.com>
Subject: [PATCH/GSoC] pull: implement --[no-]autostash for usage when rebasing
Date: Sat, 19 Mar 2016 19:27:42 +0530 [thread overview]
Message-ID: <1458395862-5113-1-git-send-email-chirayudesai1@gmail.com> (raw)
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@gmail.com>
---
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
next reply other threads:[~2016-03-19 13:59 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-19 13:57 Chirayu Desai [this message]
2016-03-19 14:08 ` [PATCH/GSoC] pull: implement --[no-]autostash for usage when rebasing Chirayu Desai
2016-03-19 14:23 ` Sidhant Sharma
2016-03-19 14:31 ` Chirayu Desai
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1458395862-5113-1-git-send-email-chirayudesai1@gmail.com \
--to=chirayudesai1@gmail.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).