git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v10 0/2] introduce --[no-]autostash command line flag
@ 2016-03-21 18:18 Mehul Jain
  2016-03-21 18:18 ` [PATCH v10 1/2] git-pull.c: introduce git_pull_config() Mehul Jain
                   ` (3 more replies)
  0 siblings, 4 replies; 16+ messages in thread
From: Mehul Jain @ 2016-03-21 18:18 UTC (permalink / raw)
  To: git; +Cc: gitster, Matthieu.Moy, pyokagan, sunshine, Mehul Jain

Following series of patches introduce --[no-]autostash command line flag
for "git pull --rebase".

[PATCH v10 1/2] git-pull.c: introduce git_pull_config()
It's a clean-up patch for changes introduced in [PATCH v10 2/2].

[PATCH v10 2/2] pull --rebase: add --[no-]autostash flag
Changes introduced w.r.t. previous patch:

* Unnecessary tight coupling between git-rebase and git-pull introduced
  in previous patch has been removed by passing "--[no-]autostash" option
  to git-rebase only when user explicitly tell via command line.

* Patch looks more clearer than before as "autostash" variable is used for
  implementation of logic (thanks to Eric).

* Test titles are modified for better understanding of tests.

* Two new tests are added to cover all the combinations of
  "--[no-]autostash" and rebase.autoStash.

* Two more tests are added to checkout for error when "git pull
  --[no-]autostash" is called. Here I'm forced to use "test_i18ncmp"
  instead of "test_i18ngrep" to compare the expected error message with
  the actual because grep was, unfortunately, reading "--[no-]autostash"
  as an option and thus leading to test failure.

Previous patch: http://thread.gmane.org/gmane.comp.version-control.git/289127

Here's the interdiff between previous patch and current patch.

diff --git a/builtin/pull.c b/builtin/pull.c
index 671179b..d98f481 100644
--- a/builtin/pull.c
+++ b/builtin/pull.c
@@ -308,6 +308,7 @@ static enum rebase_type config_get_rebase(void)
 
 	return REBASE_FALSE;
 }
+
 /**
  * Read config variables.
  */
@@ -804,7 +805,10 @@ static int run_rebase(const unsigned char *curr_head,
 	argv_array_pushv(&args, opt_strategy_opts.argv);
 	if (opt_gpg_sign)
 		argv_array_push(&args, opt_gpg_sign);
-	argv_array_push(&args, opt_autostash ? "--autostash" : "--no-autostash");
+	if (opt_autostash == 0)
+		argv_array_push(&args, "--no-autostash");
+	else if (opt_autostash == 1)
+		argv_array_push(&args, "--autostash");
 
 	argv_array_push(&args, "--onto");
 	argv_array_push(&args, sha1_to_hex(merge_head));
@@ -854,13 +858,14 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
 		die(_("--[no-]autostash option is only valid with --rebase."));
 
 	if (opt_rebase) {
+		int autostash = config_autostash;
+		if (opt_autostash != -1)
+			autostash = opt_autostash;
+
 		if (is_null_sha1(orig_head) && !is_cache_unborn())
 			die(_("Updating an unborn branch with changes added to the index."));
 
-		if (opt_autostash == -1)
-			opt_autostash = config_autostash;
-
-		if (!opt_autostash)
+		if (!autostash)
 			die_on_unclean_work_tree(prefix);
 
 		if (get_rebase_fork_point(rebase_fork_point, repo, *refspecs))
diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index 85d9bea..745e59e 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -255,7 +255,19 @@ test_expect_success 'pull --rebase succeeds with dirty working directory and reb
 	test "$(cat new_file)" = dirty &&
 	test "$(cat file)" = "modified again"
 '
-test_expect_success 'pull --rebase: --autostash overrides rebase.autostash' '
+
+test_expect_success 'pull --rebase --autostash & rebase.autostash=true' '
+	test_config rebase.autostash true &&
+	git reset --hard before-rebase &&
+	echo dirty >new_file &&
+	git add new_file &&
+	git pull --rebase --autostash . copy &&
+	test_cmp_rev HEAD^ copy &&
+	test "$(cat new_file)" = dirty &&
+	test "$(cat file)" = "modified again"
+'
+
+test_expect_success 'pull --rebase --autostash & rebase.autoStash=false' '
 	test_config rebase.autostash false &&
 	git reset --hard before-rebase &&
 	echo dirty >new_file &&
@@ -266,8 +278,7 @@ test_expect_success 'pull --rebase: --autostash overrides rebase.autostash' '
 	test "$(cat file)" = "modified again"
 '
 
-test_expect_success 'pull --rebase --autostash works with rebase.autostash set true' '
-	test_config rebase.autostash true &&
+test_expect_success 'pull --rebase: --autostash & rebase.autoStash unset' '
 	git reset --hard before-rebase &&
 	echo dirty >new_file &&
 	git add new_file &&
@@ -277,7 +288,7 @@ test_expect_success 'pull --rebase --autostash works with rebase.autostash set t
 	test "$(cat file)" = "modified again"
 '
 
-test_expect_success 'pull --rebase: --no-autostash overrides rebase.autostash' '
+test_expect_success 'pull --rebase --no-autostash & rebase.autostash=true' '
 	test_config rebase.autostash true &&
 	git reset --hard before-rebase &&
 	echo dirty >new_file &&
@@ -286,7 +297,7 @@ test_expect_success 'pull --rebase: --no-autostash overrides rebase.autostash' '
 	test_i18ngrep "Cannot pull with rebase: Your index contains uncommitted changes." err
 '
 
-test_expect_success 'pull --rebase --no-autostash works with rebase.autostash set false' '
+test_expect_success 'pull --rebase --no-autostash & rebase.autostash=false' '
 	test_config rebase.autostash false &&
 	git reset --hard before-rebase &&
 	echo dirty >new_file &&
@@ -295,6 +306,26 @@ test_expect_success 'pull --rebase --no-autostash works with rebase.autostash se
 	test_i18ngrep "Cannot pull with rebase: Your index contains uncommitted changes." err
 '
 
+test_expect_success 'pull --rebase --no-autostash & rebase.autostash unset' '
+	git reset --hard before-rebase &&
+	echo dirty >new_file &&
+	git add new_file &&
+	test_must_fail git pull --rebase --no-autostash . copy 2>err &&
+	test_i18ngrep "Cannot pull with rebase: Your index contains uncommitted changes." err
+'
+
+test_expect_success 'pull --autostash (without --rebase) should error out' '
+	test_must_fail git pull --autostash . copy 2>actual &&
+	echo "fatal: --[no-]autostash option is only valid with --rebase." >expect &&
+	test_i18ncmp actual expect
+'
+
+test_expect_success 'pull --no-autostash (without --rebase) should error out' '
+	test_must_fail git pull --no-autostash . copy 2>actual &&
+	echo "fatal: --[no-]autostash option is only valid with --rebase." >expect &&
+	test_i18ncmp actual expect
+'
+
 test_expect_success 'pull.rebase' '
 	git reset --hard before-rebase &&
 	test_config pull.rebase true &&


Mehul Jain (2):
  git-pull.c: introduce git_pull_config()
  pull --rebase: add --[no-]autostash flag

 Documentation/git-pull.txt |  9 ++++++
 builtin/pull.c             | 30 ++++++++++++++++++--
 t/t5520-pull.sh            | 70 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 106 insertions(+), 3 deletions(-)

-- 
2.7.1.340.g69eb491.dirty

^ permalink raw reply related	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2016-03-25 22:29 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-03-21 18:18 [PATCH v10 0/2] introduce --[no-]autostash command line flag Mehul Jain
2016-03-21 18:18 ` [PATCH v10 1/2] git-pull.c: introduce git_pull_config() Mehul Jain
2016-03-21 18:18 ` [PATCH v10 2/2] pull --rebase: add --[no-]autostash flag Mehul Jain
2016-03-21 18:39   ` Matthieu Moy
2016-03-21 20:12 ` Mehul Jain
2016-03-25  8:31   ` Eric Sunshine
2016-03-25  8:44     ` Eric Sunshine
2016-03-25 16:37       ` Eric Sunshine
2016-03-25 18:07     ` Mehul Jain
2016-03-25 22:29       ` Eric Sunshine
2016-03-25  9:05   ` Matthieu Moy
2016-03-25 18:10     ` Mehul Jain
2016-03-25 18:37       ` Matthieu Moy
2016-03-25 19:07         ` Mehul Jain
2016-03-25  7:23 ` [PATCH v10 0/2] introduce --[no-]autostash command line flag Eric Sunshine
2016-03-25 18:01   ` Mehul Jain

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).