@matheusbsbs / matheus-bagliano / commits / 11f2441f05
Fork 0

Add a --dry-run option to git-push.

The default behaviour of git-push is potentially confusing for new users, since it will push changes that are not on the current branch. Publishing patches that were still cooking on a development branch is hard to undo. It would also be nice to be able to verify the expansion of refspecs if you've edited them, so that you know what branches matched on the server. Adding a --dry-run flag allows the user to experiment safely and learn how to use git-push properly. Originally suggested by Steffen Prohaska. Signed-off-by: Brian Ewins <brian.ewins@gmail.com> Signed-off-by: Lars Hjemli <hjemli@gmail.com> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Brian Ewins committed Oct 11, 2007 at 20:32 UTC 11f2441f05ace25f1dae833a804761f1ca7d5cbb
3 files changed +22 -3
Documentation/git-push.txt
+4 -1
@@ -9,7 +9,7 @@ git-push - Update remote refs along with associated objects
9 SYNOPSIS
10 --------
11 [verse]
12 -'git-push' [--all] [--tags] [--receive-pack=<git-receive-pack>]
12 +'git-push' [--all] [--dry-run] [--tags] [--receive-pack=<git-receive-pack>]
13 [--repo=all] [-f | --force] [-v] [<repository> <refspec>...]
14
15 DESCRIPTION
@@ -63,6 +63,9 @@ the remote repository.
63 Instead of naming each ref to push, specifies that all
64 refs under `$GIT_DIR/refs/heads/` be pushed.
65
66 +\--dry-run::
67 + Do everything except actually send the updates.
68 +
69 \--tags::
70 All refs under `$GIT_DIR/refs/tags` are pushed, in
71 addition to refspecs explicitly listed on the command
builtin-push.c
+8 -2
@@ -7,9 +7,9 @@
7 #include "builtin.h"
8 #include "remote.h"
9
10 -static const char push_usage[] = "git-push [--all] [--tags] [--receive-pack=<git-receive-pack>] [--repo=all] [-f | --force] [-v] [<repository> <refspec>...]";
10 +static const char push_usage[] = "git-push [--all] [--dry-run] [--tags] [--receive-pack=<git-receive-pack>] [--repo=all] [-f | --force] [-v] [<repository> <refspec>...]";
11
12 -static int all, force, thin, verbose;
12 +static int all, dry_run, force, thin, verbose;
13 static const char *receivepack;
14
15 static const char **refspec;
@@ -69,6 +69,8 @@ static int do_push(const char *repo)
69 argc = 1;
70 if (all)
71 argv[argc++] = "--all";
72 + if (dry_run)
73 + argv[argc++] = "--dry-run";
74 if (force)
75 argv[argc++] = "--force";
76 if (receivepack)
@@ -147,6 +149,10 @@ int cmd_push(int argc, const char **argv, const char *prefix)
149 all = 1;
150 continue;
151 }
152 + if (!strcmp(arg, "--dry-run")) {
153 + dry_run = 1;
154 + continue;
155 + }
156 if (!strcmp(arg, "--tags")) {
157 add_refspec("refs/tags/*");
158 continue;
t/t5516-fetch-push.sh
+10
@@ -244,4 +244,14 @@ test_expect_success 'push with colon-less refspec (4)' '
244
245 '
246
247 +test_expect_success 'push with dry-run' '
248 +
249 + mk_test heads/master &&
250 + cd testrepo &&
251 + old_commit=$(git show-ref -s --verify refs/heads/master) &&
252 + cd .. &&
253 + git push --dry-run testrepo &&
254 + check_push_result $old_commit heads/master
255 +'
256 +
257 test_done