Skip to content

Commit

Permalink
Add a --dry-run option to git-push.
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Brian Ewins authored and Shawn O. Pearce committed Oct 16, 2007
1 parent a63103a commit 11f2441
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
5 changes: 4 additions & 1 deletion Documentation/git-push.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ git-push - Update remote refs along with associated objects
SYNOPSIS
--------
[verse]
'git-push' [--all] [--tags] [--receive-pack=<git-receive-pack>]
'git-push' [--all] [--dry-run] [--tags] [--receive-pack=<git-receive-pack>]
[--repo=all] [-f | --force] [-v] [<repository> <refspec>...]

DESCRIPTION
Expand Down Expand Up @@ -63,6 +63,9 @@ the remote repository.
Instead of naming each ref to push, specifies that all
refs under `$GIT_DIR/refs/heads/` be pushed.

\--dry-run::
Do everything except actually send the updates.

\--tags::
All refs under `$GIT_DIR/refs/tags` are pushed, in
addition to refspecs explicitly listed on the command
Expand Down
10 changes: 8 additions & 2 deletions builtin-push.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
#include "builtin.h"
#include "remote.h"

static const char push_usage[] = "git-push [--all] [--tags] [--receive-pack=<git-receive-pack>] [--repo=all] [-f | --force] [-v] [<repository> <refspec>...]";
static const char push_usage[] = "git-push [--all] [--dry-run] [--tags] [--receive-pack=<git-receive-pack>] [--repo=all] [-f | --force] [-v] [<repository> <refspec>...]";

static int all, force, thin, verbose;
static int all, dry_run, force, thin, verbose;
static const char *receivepack;

static const char **refspec;
Expand Down Expand Up @@ -69,6 +69,8 @@ static int do_push(const char *repo)
argc = 1;
if (all)
argv[argc++] = "--all";
if (dry_run)
argv[argc++] = "--dry-run";
if (force)
argv[argc++] = "--force";
if (receivepack)
Expand Down Expand Up @@ -147,6 +149,10 @@ int cmd_push(int argc, const char **argv, const char *prefix)
all = 1;
continue;
}
if (!strcmp(arg, "--dry-run")) {
dry_run = 1;
continue;
}
if (!strcmp(arg, "--tags")) {
add_refspec("refs/tags/*");
continue;
Expand Down
10 changes: 10 additions & 0 deletions t/t5516-fetch-push.sh
Original file line number Diff line number Diff line change
Expand Up @@ -244,4 +244,14 @@ test_expect_success 'push with colon-less refspec (4)' '
'

test_expect_success 'push with dry-run' '
mk_test heads/master &&
cd testrepo &&
old_commit=$(git show-ref -s --verify refs/heads/master) &&
cd .. &&
git push --dry-run testrepo &&
check_push_result $old_commit heads/master
'

test_done

0 comments on commit 11f2441

Please sign in to comment.