From: Jay Soffian <jaysoffian@gmail.com>
To: git@vger.kernel.org
Cc: "Jay Soffian" <jaysoffian@gmail.com>,
"Junio C Hamano" <gitster@pobox.com>,
"Björn Gustavsson" <bgustavsson@gmail.com>
Subject: [PATCH 4/4] builtin-fetch: add --dry-run option
Date: Mon, 9 Nov 2009 23:58:33 -0500 [thread overview]
Message-ID: <1257829113-52168-5-git-send-email-jaysoffian@gmail.com> (raw)
In-Reply-To: <1257829113-52168-4-git-send-email-jaysoffian@gmail.com>
Teach fetch --dry-run as users of "git remote prune" switching to "git fetch
--prune" may expect it. Unfortunately OPT__DRY_RUN() cannot be used as fetch
already uses "-n" for something else.
---
Documentation/fetch-options.txt | 5 +++++
builtin-fetch.c | 14 ++++++++++----
2 files changed, 15 insertions(+), 4 deletions(-)
diff --git a/Documentation/fetch-options.txt b/Documentation/fetch-options.txt
index 500637a..ab6419f 100644
--- a/Documentation/fetch-options.txt
+++ b/Documentation/fetch-options.txt
@@ -12,6 +12,11 @@
`git clone` with `--depth=<depth>` option (see linkgit:git-clone[1])
by the specified number of commits.
+ifndef::git-pull[]
+--dry-run::
+ Show what would be done, without making any changes.
+endif::git-pull[]
+
-f::
--force::
When 'git-fetch' is used with `<rbranch>:<lbranch>`
diff --git a/builtin-fetch.c b/builtin-fetch.c
index fd31072..8082d36 100644
--- a/builtin-fetch.c
+++ b/builtin-fetch.c
@@ -26,7 +26,7 @@ enum {
TAGS_SET = 2
};
-static int all, append, force, keep, multiple, prune, update_head_ok, verbosity;
+static int all, append, dry_run, force, keep, multiple, prune, update_head_ok, verbosity;
static int tags = TAGS_DEFAULT;
static const char *depth;
static const char *upload_pack;
@@ -51,6 +51,8 @@ static struct option builtin_fetch_options[] = {
"do not fetch all tags (--no-tags)", TAGS_UNSET),
OPT_BOOLEAN('p', "prune", &prune,
"prune tracking branches no longer on remote"),
+ OPT_BOOLEAN(0, "dry-run", &dry_run,
+ "dry run"),
OPT_BOOLEAN('k', "keep", &keep, "keep downloaded pack"),
OPT_BOOLEAN('u', "update-head-ok", &update_head_ok,
"allow updating of HEAD ref"),
@@ -187,6 +189,8 @@ static int s_update_ref(const char *action,
char *rla = getenv("GIT_REFLOG_ACTION");
static struct ref_lock *lock;
+ if (dry_run)
+ return 0;
if (!rla)
rla = default_rla.buf;
snprintf(msg, sizeof(msg), "%s: %s", rla, action);
@@ -312,7 +316,7 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
char note[1024];
const char *what, *kind;
struct ref *rm;
- char *url, *filename = git_path("FETCH_HEAD");
+ char *url, *filename = dry_run ? "/dev/null" : git_path("FETCH_HEAD");
fp = fopen(filename, "a");
if (!fp)
@@ -658,7 +662,7 @@ static int do_fetch(struct transport *transport,
die("Don't know how to fetch from %s", transport->url);
/* if not appending, truncate FETCH_HEAD */
- if (!append) {
+ if (!append && !dry_run) {
char *filename = git_path("FETCH_HEAD");
FILE *fp = fopen(filename, "w");
if (!fp)
@@ -766,9 +770,11 @@ static int add_remote_or_group(const char *name, struct string_list *list)
static int fetch_multiple(struct string_list *list)
{
int i, result = 0;
- const char *argv[] = { "fetch", NULL, NULL, NULL, NULL, NULL };
+ const char *argv[] = { "fetch", NULL, NULL, NULL, NULL, NULL, NULL };
int argc = 1;
+ if (dry_run)
+ argv[argc++] = "--dry-run";
if (prune)
argv[argc++] = "--prune";
if (verbosity >= 2)
--
1.6.4.2
next prev parent reply other threads:[~2009-11-10 4:59 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-11-10 4:58 [PATCH 0/4] Teach fetch --prune and --dry run options Jay Soffian
2009-11-10 4:58 ` [PATCH 1/4] remote: refactor some logic into get_stale_heads() Jay Soffian
2009-11-10 4:58 ` [PATCH 2/4] teach warn_dangling_symref to take a FILE argument Jay Soffian
2009-11-10 4:58 ` [PATCH 3/4] builtin-fetch: add --prune option Jay Soffian
2009-11-10 4:58 ` Jay Soffian [this message]
-- strict thread matches above, loose matches on Subject: below --
2009-11-10 5:03 [PATCH 0/4] Teach fetch --prune and --dry run options Jay Soffian
2009-11-10 5:03 ` [PATCH 1/4] remote: refactor some logic into get_stale_heads() Jay Soffian
2009-11-10 5:03 ` [PATCH 2/4] teach warn_dangling_symref to take a FILE argument Jay Soffian
2009-11-10 5:03 ` [PATCH 3/4] builtin-fetch: add --prune option Jay Soffian
2009-11-10 5:03 ` [PATCH 4/4] builtin-fetch: add --dry-run option Jay Soffian
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=1257829113-52168-5-git-send-email-jaysoffian@gmail.com \
--to=jaysoffian@gmail.com \
--cc=bgustavsson@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.
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).