git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v10 0/2] introduce --[no-]autostash command line flag

From
Mehul Jain <mehul.jain2029@gmail.com>
Date
Mar 21, 2016, 18:18 UTC
Message-ID
<1458584283-23816-1-git-send-email-mehul.jain2029@gmail.com>

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
Next: Mehul Jain
Message 1 of 16 in “introduce --[no-]autostash command line flag”
  1. 0/2 introduce --[no-]autostash command line flagMehul Jain, Mar 21, 2016
  2. 1/2 git-pull.c: introduce git_pull_config()Mehul Jain, Mar 21, 2016
  3. 2/2 pull --rebase: add --[no-]autostash flagMehul Jain, Mar 21, 2016
  4. Matthieu MoyMar 21, 2016
  5. 2/2 pull --rebase: add --[no-]autostash flagMehul Jain, Mar 21, 2016
  6. Eric SunshineMar 25, 2016
  7. Eric SunshineMar 25, 2016
  8. Eric SunshineMar 25, 2016
  9. Mehul JainMar 25, 2016
  10. Eric SunshineMar 25, 2016
  11. Matthieu MoyMar 25, 2016
  12. Mehul JainMar 25, 2016
  13. Matthieu MoyMar 25, 2016
  14. Mehul JainMar 25, 2016
  15. Eric SunshineMar 25, 2016
  16. Mehul JainMar 25, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.