{"thread":{"id":"21561","subject":"[PATCH 7/8] builtin-fetch: add --dry-run option","startedAt":"2009-11-10T08:19:43Z","lastAt":"2009-11-10T08:19:43Z","messageCount":1,"participants":["Björn Gustavsson"],"isPatch":true,"patchVersion":1,"patchTotal":8},"messages":[{"id":"127224","messageId":"4AF9221F.3080605@gmail.com","threadId":"21561","inReplyTo":null,"subject":"[PATCH 7/8] builtin-fetch: add --dry-run option","fromName":"Björn Gustavsson","fromEmail":"bgustavsson@gmail.com","sentAt":"2009-11-10T08:19:43Z","receivedAt":"2009-11-10T08:19:43Z","isPatch":true,"sender":{"key":"bgustavsson@gmail.com","avatar":"https://avatars.githubusercontent.com/u/74840?v=4"},"body":"From: Jay Soffian <jaysoffian@gmail.com>\n\nTeach fetch --dry-run as users of \"git remote prune\" switching to \"git fetch\n--prune\" may expect it. Unfortunately OPT__DRY_RUN() cannot be used as fetch\nalready uses \"-n\" for something else.\n\nSigned-off-by: Jay Soffian <jaysoffian@gmail.com>\nSigned-off-by: Björn Gustavsson <bgustavsson@gmail.com>\n---\nI have removed the changes to builtin_remote.c and\nthe test case and also removed mentioning of those\nchanges in the commit message.\n\n Documentation/fetch-options.txt |    5 +++++\n builtin-fetch.c                 |   14 ++++++++++----\n 2 files changed, 15 insertions(+), 4 deletions(-)\n\ndiff --git a/Documentation/fetch-options.txt b/Documentation/fetch-options.txt\nindex 500637a..ab6419f 100644\n--- a/Documentation/fetch-options.txt\n+++ b/Documentation/fetch-options.txt\n@@ -12,6 +12,11 @@\n \t`git clone` with `--depth=<depth>` option (see linkgit:git-clone[1])\n \tby the specified number of commits.\n \n+ifndef::git-pull[]\n+--dry-run::\n+\tShow what would be done, without making any changes.\n+endif::git-pull[]\n+\n -f::\n --force::\n \tWhen 'git-fetch' is used with `<rbranch>:<lbranch>`\ndiff --git a/builtin-fetch.c b/builtin-fetch.c\nindex fd31072..8082d36 100644\n--- a/builtin-fetch.c\n+++ b/builtin-fetch.c\n@@ -26,7 +26,7 @@ enum {\n \tTAGS_SET = 2\n };\n \n-static int all, append, force, keep, multiple, prune, update_head_ok, verbosity;\n+static int all, append, dry_run, force, keep, multiple, prune, update_head_ok, verbosity;\n static int tags = TAGS_DEFAULT;\n static const char *depth;\n static const char *upload_pack;\n@@ -51,6 +51,8 @@ static struct option builtin_fetch_options[] = {\n \t\t    \"do not fetch all tags (--no-tags)\", TAGS_UNSET),\n \tOPT_BOOLEAN('p', \"prune\", &prune,\n \t\t    \"prune tracking branches no longer on remote\"),\n+\tOPT_BOOLEAN(0, \"dry-run\", &dry_run,\n+\t\t    \"dry run\"),\n \tOPT_BOOLEAN('k', \"keep\", &keep, \"keep downloaded pack\"),\n \tOPT_BOOLEAN('u', \"update-head-ok\", &update_head_ok,\n \t\t    \"allow updating of HEAD ref\"),\n@@ -187,6 +189,8 @@ static int s_update_ref(const char *action,\n \tchar *rla = getenv(\"GIT_REFLOG_ACTION\");\n \tstatic struct ref_lock *lock;\n \n+\tif (dry_run)\n+\t\treturn 0;\n \tif (!rla)\n \t\trla = default_rla.buf;\n \tsnprintf(msg, sizeof(msg), \"%s: %s\", rla, action);\n@@ -312,7 +316,7 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,\n \tchar note[1024];\n \tconst char *what, *kind;\n \tstruct ref *rm;\n-\tchar *url, *filename = git_path(\"FETCH_HEAD\");\n+\tchar *url, *filename = dry_run ? \"/dev/null\" : git_path(\"FETCH_HEAD\");\n \n \tfp = fopen(filename, \"a\");\n \tif (!fp)\n@@ -658,7 +662,7 @@ static int do_fetch(struct transport *transport,\n \t\tdie(\"Don't know how to fetch from %s\", transport->url);\n \n \t/* if not appending, truncate FETCH_HEAD */\n-\tif (!append) {\n+\tif (!append && !dry_run) {\n \t\tchar *filename = git_path(\"FETCH_HEAD\");\n \t\tFILE *fp = fopen(filename, \"w\");\n \t\tif (!fp)\n@@ -766,9 +770,11 @@ static int add_remote_or_group(const char *name, struct string_list *list)\n static int fetch_multiple(struct string_list *list)\n {\n \tint i, result = 0;\n-\tconst char *argv[] = { \"fetch\", NULL, NULL, NULL, NULL, NULL };\n+\tconst char *argv[] = { \"fetch\", NULL, NULL, NULL, NULL, NULL, NULL };\n \tint argc = 1;\n \n+\tif (dry_run)\n+\t\targv[argc++] = \"--dry-run\";\n \tif (prune)\n \t\targv[argc++] = \"--prune\";\n \tif (verbosity >= 2)\n-- \n1.6.5.1.69.g36942\n"}]}