From: Damien Robert <damien.olivier.robert@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org
Subject: Re: Pull without fetch
Date: Mon, 8 Apr 2019 18:11:34 +0200 [thread overview]
Message-ID: <20190408161134.gdxmxvqitxioeibp@feanor> (raw)
In-Reply-To: <20190408145340.3rdprg3yu5shpelu@feanor>
From Damien Robert, Mon 08 Apr 2019 at 16:53:40 (+0200) :
> > Others may have a better idea, but I do not immediately see any
> > solution better than inventing a new option to "git pull".
So here is a RFC patch that implements --no-fetch. (I am not sure about
the wording of the documentation, and what's the best way to test that
fetch was not called).
-- >8 --
From: Damien Robert <damien.olivier.robert+git@gmail.com>
Date: Mon, 8 Apr 2019 17:51:51 +0200
Subject: [PATCH 1/1] pull: add --no-fetch
A common workflow is to do a fetch, review the changes, and then
integrate the changes via an explicit merge or rebase.
In the good old days `git pull` was essentially `git fetch` followed by
`git merge FETCH_HEAD` so it was easy to separate the fetching part from
the integrating part.
But nowadays there are no easy way to do the integrating part of `git
pull`. Indeed, `git pull` learnt to read the config values of
`branch.<current>.rebase` and `pull.rebase`, whose possible values are
growing. At the time of this commit, they can be 'true', 'merges',
'preserve' and 'interactive'.
To remedy this, add a new --no-fetch option to `git pull`.
Signed-off-by: Damien Robert <damien.olivier.robert+git@gmail.com>
---
Documentation/git-pull.txt | 9 +++++++++
builtin/pull.c | 8 ++++++--
t/t5520-pull.sh | 14 ++++++++++++++
3 files changed, 29 insertions(+), 2 deletions(-)
diff --git a/Documentation/git-pull.txt b/Documentation/git-pull.txt
index 118d9d86f7..cec06bf6e3 100644
--- a/Documentation/git-pull.txt
+++ b/Documentation/git-pull.txt
@@ -144,6 +144,15 @@ This option is only valid when "--rebase" is used.
Options related to fetching
~~~~~~~~~~~~~~~~~~~~~~~~~~~
+--fetch::
+--no-fetch::
+ Perform a fetch first. This option can be used to override
+ --no-fetch.
++
+With --no-fetch don't fetch before updating the branch via a merge or a
+rebase. This can be used to review changes by doing a fetch first before
+pulling.
+
include::fetch-options.txt[]
include::pull-fetch-param.txt[]
diff --git a/builtin/pull.c b/builtin/pull.c
index 33db889955..0c14701abe 100644
--- a/builtin/pull.c
+++ b/builtin/pull.c
@@ -111,6 +111,7 @@ static char *opt_gpg_sign;
static int opt_allow_unrelated_histories;
/* Options passed to git-fetch */
+static int opt_fetch = 1;
static char *opt_all;
static char *opt_append;
static char *opt_upload_pack;
@@ -195,6 +196,8 @@ static struct option pull_options[] = {
/* Options passed to git-fetch */
OPT_GROUP(N_("Options related to fetching")),
+ OPT_BOOL(0, "fetch", &opt_fetch,
+ N_("fetch before merging / rebasing (default)")),
OPT_PASSTHRU(0, "all", &opt_all, NULL,
N_("fetch from all remotes"),
PARSE_OPT_NOARG),
@@ -912,8 +915,9 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
oidclr(&rebase_fork_point);
}
- if (run_fetch(repo, refspecs))
- return 1;
+ if (opt_fetch)
+ if (run_fetch(repo, refspecs))
+ return 1;
if (opt_dry_run)
return 0;
diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index cf4cc32fd0..058c85e6a4 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -134,6 +134,20 @@ test_expect_success 'the default remote . should not break explicit pull' '
test_cmp reflog.expected reflog.fuzzy
'
+test_expect_success 'With --no-fetch will not fetch but still merge pending changes' '
+ git checkout -b nofetch master^ &&
+ echo modified >file &&
+ git commit -a -m modified &&
+ git checkout copy &&
+ git reset --hard HEAD^ &&
+ test "$(cat file)" = file &&
+ stat --format %Y .git/FETCH_HEAD > fetch_head_before &&
+ git pull --no-fetch . nofetch &&
+ stat --format %Y .git/FETCH_HEAD > fetch_head_after &&
+ test "$(cat file)" = modified &&
+ test_cmp fetch_head_before fetch_head_after
+'
+
test_expect_success 'fail if wildcard spec does not match any refs' '
git checkout -b test copy^ &&
test_when_finished "git checkout -f copy && git branch -D test" &&
--
Patched on top of v2.21.0-196-g041f5ea1cf (git version 2.21.0)
next prev parent reply other threads:[~2019-04-08 16:11 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-06 13:12 Pull without fetch Damien Robert
2019-04-08 1:34 ` Junio C Hamano
2019-04-08 2:17 ` Duy Nguyen
2019-04-08 12:51 ` Ævar Arnfjörð Bjarmason
2019-04-08 13:18 ` Duy Nguyen
2019-04-08 14:53 ` Damien Robert
2019-04-08 16:11 ` Damien Robert [this message]
2019-04-09 8:03 ` Junio C Hamano
2019-04-11 11:07 ` Damien Robert
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190408161134.gdxmxvqitxioeibp@feanor \
--to=damien.olivier.robert@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).