From d132b32b4e3146e4aa5a719418f85d6db1134140 Mon Sep 17 00:00:00 2001 From: John Keeping Date: Mon, 25 Jul 2016 22:59:55 +0100 Subject: Documentation/git-push: fix placeholder formatting Format the placeholder as monospace to match other occurrences in this file and obey CodingGuidelines. Signed-off-by: John Keeping Signed-off-by: Junio C Hamano --- Documentation/git-push.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Documentation/git-push.txt b/Documentation/git-push.txt index af521f8990..5355a8d54a 100644 --- a/Documentation/git-push.txt +++ b/Documentation/git-push.txt @@ -198,7 +198,7 @@ branch we have for it. + `--force-with-lease=:` will protect the named ref (alone), if it is going to be updated, by requiring its current value to be -the same as the specified value (which is allowed to be +the same as the specified value `` (which is allowed to be different from the remote-tracking branch we have for the refname, or we do not even have to have such a remote-tracking branch when this form is used). -- cgit v1.2.3 From eee98e74f928a49c310038c77026ebc04e6cf4b2 Mon Sep 17 00:00:00 2001 From: John Keeping Date: Tue, 26 Jul 2016 21:44:44 +0100 Subject: push: add shorthand for --force-with-lease branch creation Allow the empty string to stand in for the null SHA-1 when pushing a new branch, like we do when deleting branches. This means that the following command ensures that `new-branch` is created on the remote (that is, is must not already exist): git push --force-with-lease=new-branch: origin new-branch Signed-off-by: John Keeping Signed-off-by: Junio C Hamano --- Documentation/git-push.txt | 3 ++- remote.c | 2 ++ t/t5533-push-cas.sh | 26 ++++++++++++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/Documentation/git-push.txt b/Documentation/git-push.txt index 5355a8d54a..02b5dd3490 100644 --- a/Documentation/git-push.txt +++ b/Documentation/git-push.txt @@ -201,7 +201,8 @@ if it is going to be updated, by requiring its current value to be the same as the specified value `` (which is allowed to be different from the remote-tracking branch we have for the refname, or we do not even have to have such a remote-tracking branch when -this form is used). +this form is used). If `` is the empty string, then the named ref +must not already exist. + Note that all forms other than `--force-with-lease=:` that specifies the expected current value of the ref explicitly are diff --git a/remote.c b/remote.c index 6e5c1a876f..29ecd3d8c5 100644 --- a/remote.c +++ b/remote.c @@ -2304,6 +2304,8 @@ int parse_push_cas_option(struct push_cas_option *cas, const char *arg, int unse entry = add_cas_entry(cas, arg, colon - arg); if (!*colon) entry->use_tracking = 1; + else if (!colon[1]) + hashclr(entry->expect); else if (get_sha1(colon + 1, entry->expect)) return error("cannot parse expected object name '%s'", colon + 1); return 0; diff --git a/t/t5533-push-cas.sh b/t/t5533-push-cas.sh index c7320121ec..ed631c3d0b 100755 --- a/t/t5533-push-cas.sh +++ b/t/t5533-push-cas.sh @@ -191,4 +191,30 @@ test_expect_success 'cover everything with default force-with-lease (allowed)' ' test_cmp expect actual ' +test_expect_success 'new branch covered by force-with-lease (explicit)' ' + setup_srcdst_basic && + ( + cd dst && + git branch branch master && + git push --force-with-lease=branch: origin branch + ) && + git ls-remote dst refs/heads/branch >expect && + git ls-remote src refs/heads/branch >actual && + test_cmp expect actual +' + +test_expect_success 'new branch already exists' ' + setup_srcdst_basic && + ( + cd src && + git checkout -b branch master && + test_commit c + ) && + ( + cd dst && + git branch branch master && + test_must_fail git push --force-with-lease=branch: origin branch + ) +' + test_done -- cgit v1.2.3 From 64ac39af7020f3a8bc52d51137804ce9f46baf66 Mon Sep 17 00:00:00 2001 From: John Keeping Date: Tue, 26 Jul 2016 21:44:45 +0100 Subject: push: allow pushing new branches with --force-with-lease If there is no upstream information for a branch, it is likely that it is newly created and can safely be pushed under the normal fast-forward rules. Relax the --force-with-lease check so that we do not reject these branches immediately but rather attempt to push them as new branches, using the null SHA-1 as the expected value. In fact, it is already possible to push new branches using the explicit --force-with-lease=: syntax, so all we do here is make this behaviour the default if no explicit "expect" value is specified. Signed-off-by: John Keeping Signed-off-by: Junio C Hamano --- remote.c | 7 +++---- remote.h | 1 - t/t5533-push-cas.sh | 12 ++++++++++++ 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/remote.c b/remote.c index 29ecd3d8c5..3b6f4b7e6d 100644 --- a/remote.c +++ b/remote.c @@ -1554,8 +1554,7 @@ void set_ref_status_for_push(struct ref *remote_refs, int send_mirror, * branch. */ if (ref->expect_old_sha1) { - if (ref->expect_old_no_trackback || - oidcmp(&ref->old_oid, &ref->old_oid_expect)) + if (oidcmp(&ref->old_oid, &ref->old_oid_expect)) reject_reason = REF_STATUS_REJECT_STALE; else /* If the ref isn't stale then force the update. */ @@ -2355,7 +2354,7 @@ static void apply_cas(struct push_cas_option *cas, if (!entry->use_tracking) hashcpy(ref->old_oid_expect.hash, cas->entry[i].expect); else if (remote_tracking(remote, ref->name, &ref->old_oid_expect)) - ref->expect_old_no_trackback = 1; + oidclr(&ref->old_oid_expect); return; } @@ -2365,7 +2364,7 @@ static void apply_cas(struct push_cas_option *cas, ref->expect_old_sha1 = 1; if (remote_tracking(remote, ref->name, &ref->old_oid_expect)) - ref->expect_old_no_trackback = 1; + oidclr(&ref->old_oid_expect); } void apply_push_cas(struct push_cas_option *cas, diff --git a/remote.h b/remote.h index 4a039bae0b..9674ddb0af 100644 --- a/remote.h +++ b/remote.h @@ -87,7 +87,6 @@ struct ref { force:1, forced_update:1, expect_old_sha1:1, - expect_old_no_trackback:1, deletion:1, matched:1; diff --git a/t/t5533-push-cas.sh b/t/t5533-push-cas.sh index ed631c3d0b..09899af3b0 100755 --- a/t/t5533-push-cas.sh +++ b/t/t5533-push-cas.sh @@ -191,6 +191,18 @@ test_expect_success 'cover everything with default force-with-lease (allowed)' ' test_cmp expect actual ' +test_expect_success 'new branch covered by force-with-lease' ' + setup_srcdst_basic && + ( + cd dst && + git branch branch master && + git push --force-with-lease=branch origin branch + ) && + git ls-remote dst refs/heads/branch >expect && + git ls-remote src refs/heads/branch >actual && + test_cmp expect actual +' + test_expect_success 'new branch covered by force-with-lease (explicit)' ' setup_srcdst_basic && ( -- cgit v1.2.3 From 9eed4f3711a605ab2d9b986357879a09a6d54f36 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Thu, 4 Aug 2016 16:54:35 +0200 Subject: t5533: make it pass on case-sensitive filesystems The newly-added test case wants to commit a file "c.t" (note the lower case) when a previous test case already committed a file "C.t". This confuses Git to the point that it thinks "c.t" was not staged when "git add c.t" was called. Simply make the naming of the test commits consistent with the previous test cases: use upper-case, and advance in the alphabet. This came up in local work to rebase the Windows-specific patches to the current `next` branch. An identical fix was suggested by John Keeping. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- t/t5533-push-cas.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/t/t5533-push-cas.sh b/t/t5533-push-cas.sh index 09899af3b0..a2c9e7439f 100755 --- a/t/t5533-push-cas.sh +++ b/t/t5533-push-cas.sh @@ -220,7 +220,7 @@ test_expect_success 'new branch already exists' ' ( cd src && git checkout -b branch master && - test_commit c + test_commit F ) && ( cd dst && -- cgit v1.2.3