git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Lidong Yan <yldhome2d2@gmail.com>
To: gitster@pobox.com
Cc: git@vger.kernel.org, hi@looping.me, j6t@kdbg.org, yldhome2d2@gmail.com
Subject: [PATCH] pull: add pull.autoStash config option
Date: Thu, 17 Jul 2025 11:07:32 +0800	[thread overview]
Message-ID: <20250717030732.75106-1-yldhome2d2@gmail.com> (raw)
In-Reply-To: <xmqq5xfsdv3w.fsf@gitster.g>

Git uses the `rebase.autoStash` option to decide if git-pull is allowed
when the working tree has uncommitted changes. However, since the
documentation does not explicitly state this, users may find it difficult
to associate `rebase.autoStash` with the git-pull command. Add
`pull.autoStash` option along with its documentation.

`pull.autoStash` provides the same functionality as `rebase.autoStash`
but is more user-friendly because its prefix clearly associates it
with git-pull commands. Additionally, when both options are set,
`pull.autoStash` takes precedence and overrides the value of
`rebase.autoStash`.

Signed-off-by: Lidong Yan <yldhome2d2@gmail.com>
---
 Documentation/config/pull.adoc |  9 +++++++++
 builtin/pull.c                 | 10 +++++++---
 2 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/Documentation/config/pull.adoc b/Documentation/config/pull.adoc
index 9349e09261..da9686dbd2 100644
--- a/Documentation/config/pull.adoc
+++ b/Documentation/config/pull.adoc
@@ -13,6 +13,15 @@ pull.rebase::
 	of merging the default branch from the default remote when "git
 	pull" is run. See "branch.<name>.rebase" for setting this on a
 	per-branch basis.
+
+pull.autoStash::
+	When true, Git will automatically perform a `git stash` before the
+	operation and then restore the local changes with `git stash pop`
+	after the merge or rebase is complete. This means that you can run
+	pull on a dirty worktree. Noticed that `rebase.autoStash` provides
+	the same functionality, but `pull.autoStash` overrides its behavior
+	when both are set. This option can be overridden by the `--no-autostash`
+	and `--autostash` options of linkgit:git-pull[1]. Defaults to false.
 +
 When `merges` (or just 'm'), pass the `--rebase-merges` option to 'git rebase'
 so that the local merge commits are included in the rebase (see
diff --git a/builtin/pull.c b/builtin/pull.c
index c593f324fe..dfc3d4656b 100644
--- a/builtin/pull.c
+++ b/builtin/pull.c
@@ -90,7 +90,8 @@ static char *opt_ff;
 static const char *opt_verify_signatures;
 static const char *opt_verify;
 static int opt_autostash = -1;
-static int config_autostash;
+static int config_rebase_autostash;
+static int config_pull_autostash = -1;
 static int check_trust_level = 1;
 static struct strvec opt_strategies = STRVEC_INIT;
 static struct strvec opt_strategy_opts = STRVEC_INIT;
@@ -367,7 +368,10 @@ static int git_pull_config(const char *var, const char *value,
 			   const struct config_context *ctx, void *cb)
 {
 	if (!strcmp(var, "rebase.autostash")) {
-		config_autostash = git_config_bool(var, value);
+		config_rebase_autostash = git_config_bool(var, value);
+		return 0;
+	} else if (!strcmp(var, "pull.autostash")) {
+		config_pull_autostash = git_config_bool(var, value);
 		return 0;
 	} else if (!strcmp(var, "submodule.recurse")) {
 		recurse_submodules = git_config_bool(var, value) ?
@@ -1052,7 +1056,7 @@ int cmd_pull(int argc,
 
 	if (opt_rebase) {
 		if (opt_autostash == -1)
-			opt_autostash = config_autostash;
+			opt_autostash = config_pull_autostash == -1 ? config_rebase_autostash : config_pull_autostash;
 
 		if (is_null_oid(&orig_head) && !is_index_unborn(the_repository->index))
 			die(_("Updating an unborn branch with changes added to the index."));
-- 
2.39.5 (Apple Git-154)


  reply	other threads:[~2025-07-17  3:07 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-15  3:26 [BUG] git pull ignores pull.autostash=true configuration when used with --git-dir and --work-tree flags on a bare repository Bryan Lee
2025-07-15  4:09 ` Lidong Yan
2025-07-15  5:31   ` Bryan Lee
2025-07-15  5:31   ` Bryan Lee
2025-07-15 15:02     ` Lidong Yan
2025-07-15 20:46       ` Junio C Hamano
2025-07-16  1:39         ` Lidong Yan
2025-07-16  5:55           ` Johannes Sixt
2025-07-16 11:20             ` Lidong Yan
2025-07-16 15:16             ` Junio C Hamano
2025-07-17  3:07               ` Lidong Yan [this message]
2025-07-17  3:27                 ` [PATCH] pull: add pull.autoStash config option Eric Sunshine
2025-07-17  4:09                   ` Lidong Yan
2025-07-17  4:37                     ` Junio C Hamano
2025-07-17  5:01                       ` Lidong Yan
2025-07-17  5:48                         ` Junio C Hamano
2025-07-17  4:44                   ` Junio C Hamano
2025-07-18  3:52                 ` Lidong Yan
2025-07-18 22:13                   ` Junio C Hamano
2025-07-19  3:14                     ` Lidong Yan
2025-07-20 12:43                   ` [PATCH v2] " Lidong Yan
2025-07-21 22:10                     ` Junio C Hamano
2025-07-17 19:32               ` [BUG] git pull ignores pull.autostash=true configuration when used with --git-dir and --work-tree flags on a bare repository Ben Knoble

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=20250717030732.75106-1-yldhome2d2@gmail.com \
    --to=yldhome2d2@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=hi@looping.me \
    --cc=j6t@kdbg.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).