Often you want to push only the current branch to the default remote. This was awkward to do in the past. You needed to remember the default remote and type "git push $remote HEAD". This commit teaches push to do this if you use '--current'. Signed-off-by: Steffen Prohaska <prohaska@xxxxxx> --- Documentation/git-push.txt | 6 +++++- builtin-push.c | 16 +++++++++++----- t/t5516-fetch-push.sh | 29 +++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 6 deletions(-) diff --git a/Documentation/git-push.txt b/Documentation/git-push.txt index d2417f3..2dfaf50 100644 --- a/Documentation/git-push.txt +++ b/Documentation/git-push.txt @@ -9,7 +9,7 @@ git-push - Update remote refs along with associated objects SYNOPSIS -------- [verse] -'git-push' [--all] [--matching] [--dry-run] [--tags] [--receive-pack=<git-receive-pack>] +'git-push' [--all] [--matching] [--current] [--dry-run] [--tags] [--receive-pack=<git-receive-pack>] [--repo=all] [-f | --force] [-v | --verbose] [<repository> <refspec>...] DESCRIPTION @@ -69,6 +69,10 @@ the remote repository. the branch exists locally and at the remote under the same name. Currently, this is the default. But this will change in the future. +\--current:: + Instead of naming each ref to push, specifies that only the + current branch be pushed. + \--dry-run:: Do everything except actually send the updates. diff --git a/builtin-push.c b/builtin-push.c index 7e9dcf1..e5646d4 100644 --- a/builtin-push.c +++ b/builtin-push.c @@ -10,7 +10,7 @@ #include "parse-options.h" static const char * const push_usage[] = { - "git-push [--all] [--matching] [--dry-run] [--tags] [--receive-pack=<git-receive-pack>] [--repo=all] [-f | --force] [-v] [<repository> <refspec>...]", + "git-push [--all] [--matching] [--current] [--dry-run] [--tags] [--receive-pack=<git-receive-pack>] [--repo=all] [-f | --force] [-v] [<repository> <refspec>...]", NULL, }; @@ -101,6 +101,7 @@ int cmd_push(int argc, const char **argv, const char *prefix) int flags = 0; int all = 0; int matching = 0; + int current = 0; int dry_run = 0; int force = 0; int tags = 0; @@ -111,6 +112,7 @@ int cmd_push(int argc, const char **argv, const char *prefix) OPT_STRING( 0 , "repo", &repo, "repository", "repository"), OPT_BOOLEAN( 0 , "all", &all, "push all refs"), OPT_BOOLEAN( 0 , "matching", &matching, "push matching refs"), + OPT_BOOLEAN( 0 , "current", ¤t, "push current branch"), OPT_BOOLEAN( 0 , "tags", &tags, "push tags"), OPT_BOOLEAN( 0 , "dry-run", &dry_run, "dry run"), OPT_BOOLEAN('f', "force", &force, "force updates"), @@ -137,15 +139,19 @@ int cmd_push(int argc, const char **argv, const char *prefix) repo = argv[0]; set_refspecs(argv + 1, argc - 1); } - if ((all != 0) + (matching != 0) > 1) { - fprintf(stderr, "--all and --matching are mutual exclusive.\n"); + if ((all != 0) + (matching != 0) + (current != 0) > 1) { + fprintf(stderr, "--all, --matching, and --current are mutual exclusive.\n"); usage_with_options(push_usage, options); } - if ((all || matching) && refspec) + if ((all || matching || current) && refspec) usage_with_options(push_usage, options); - if (!all && !matching && !refspec) + if (!all && !matching && !current && !refspec) fprintf(stderr, "Warning: assuming '--matching'." " This default will change in the future.\n"); + if (current) { + const char* head[1] = { "HEAD" }; + set_refspecs(head, 1); + } return do_push(repo, flags); } diff --git a/t/t5516-fetch-push.sh b/t/t5516-fetch-push.sh index 21aa7c3..20e0796 100755 --- a/t/t5516-fetch-push.sh +++ b/t/t5516-fetch-push.sh @@ -113,6 +113,18 @@ test_expect_success 'push command line options (3)' ' grep -q "Warning: assuming.*--matching" stderr.txt ' +test_expect_code 129 'push command line options (4)' ' + git push --all --current testrepo +' + +test_expect_code 129 'push command line options (5)' ' + git push --matching --current testrepo +' + +test_expect_code 129 'push command line options (6)' ' + git push --current testrepo master +' + test_expect_success 'push without wildcard' ' mk_empty && @@ -284,6 +296,23 @@ test_expect_success 'push with HEAD nonexisting at remote' ' check_push_result $the_commit heads/local ' +test_expect_success 'push with --current' ' + + mk_test heads/master && + git checkout master && + git push --current testrepo && + check_push_result $the_commit heads/master + +' + +test_expect_success 'push with --current nonexisting at remote' ' + + mk_test heads/master && + git checkout local && + git push --current testrepo && + check_push_result $the_commit heads/local +' + test_expect_success 'push with dry-run' ' mk_test heads/master && -- 1.5.3.5.743.g87c5c - To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html