From: Junio C Hamano <hidden> Date: 2016-07-25 17:28:13
John Keeping [off-list ref] writes:
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=<branch>:<expect> syntax, so all we do here is make
this behaviour the default if no explicit "expect" value is specified.
I like the loss of an extra field from "struct ref".
I suspect that the if/else cascade in the loop in apply_cas() can
also be taught that ':' followed by an empty string asks to check
that the target ref does not exist, in order to make it a bit more
useful for folks who do not rely on the "use the last observed
status of the tracking branch".
That would make the "explicit" test much less cumbersome to read.
From: John Keeping <hidden> Date: 2016-07-25 22:00:27
On Mon, Jul 25, 2016 at 10:28:01AM -0700, Junio C Hamano wrote:
John Keeping [off-list ref] writes:
quoted
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=<branch>:<expect> syntax, so all we do here is make
this behaviour the default if no explicit "expect" value is specified.
I like the loss of an extra field from "struct ref".
I suspect that the if/else cascade in the loop in apply_cas() can
also be taught that ':' followed by an empty string asks to check
that the target ref does not exist, in order to make it a bit more
useful for folks who do not rely on the "use the last observed
status of the tracking branch".
That would make the "explicit" test much less cumbersome to read.
Yes, that's nicer and it mirrors the syntax for deleting a remote
branch.
I've pulled it out as a preparatory step because I like the fact that
the "explicit" test passes even before the patch that is the main point
of the series.
From: John Keeping <hidden> Date: 2016-07-25 22:00:32
Format the placeholder as monospace to match other occurrences in this
file and obey CodingGuidelines.
Signed-off-by: John Keeping <redacted>
---
New in v2.
Documentation/git-push.txt | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
@@ -198,7 +198,7 @@ branch we have for it. + `--force-with-lease=<refname>:<expect>` 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 <expect> (which is allowed to be+the same as the specified value `<expect>` (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).
From: John Keeping <hidden> Date: 2016-07-25 22:00:35
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 <redacted>
---
New in v2.
Documentation/git-push.txt | 3 ++-
remote.c | 2 ++
t/t5533-push-cas.sh | 12 ++++++++++++
3 files changed, 16 insertions(+), 1 deletion(-)
@@ -201,7 +201,8 @@ if it is going to be updated, by requiring its current value to be the same as the specified value `<expect>` (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 `<expect>` is the empty string, then the named ref+must not already exist. + Note that all forms other than `--force-with-lease=<refname>:<expect>` that specifies the expected current value of the ref explicitly are
From: John Keeping <hidden> Date: 2016-07-25 22:00:41
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=<branch>:<expect> syntax, so all we do here is make
this behaviour the default if no explicit "expect" value is specified.
Signed-off-by: John Keeping <redacted>
---
Changes in v2:
- The "explicit" test was previously in this patch but is now added in
patch 2/3.
remote.c | 7 +++----
remote.h | 1 -
t/t5533-push-cas.sh | 26 ++++++++++++++++++++++++++
3 files changed, 29 insertions(+), 5 deletions(-)
@@ -1544,8 +1544,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. */
Do we need to test the negative, that is that if branch is not
new it prevents push (e.g. when <branch> is HEAD), or is it
covered by other tests?
--
Jakub Narębski
Do we need to test the negative, that is that if branch is not
new it prevents push (e.g. when <branch> is HEAD), or is it
covered by other tests?
It's covered by a test in patch 3 (at least for the implicit case added
there), but I could pull that forwards. In fact, converting that test
to the explicit syntax will make it simpler since we won't need to set
up a non-fast-forward push.
From: John Keeping <hidden> Date: 2016-07-26 20:45:22
Format the placeholder as monospace to match other occurrences in this
file and obey CodingGuidelines.
Signed-off-by: John Keeping <redacted>
---
No changes in v3.
Documentation/git-push.txt | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
@@ -198,7 +198,7 @@ branch we have for it. + `--force-with-lease=<refname>:<expect>` 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 <expect> (which is allowed to be+the same as the specified value `<expect>` (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).
From: John Keeping <hidden> Date: 2016-07-26 20:45:27
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 <redacted>
---
Changes in v3:
- use hashclr()
- pull 'new branch already exists' test forward from patch 3 and use
explicit --force-with-lease syntax
Documentation/git-push.txt | 3 ++-
remote.c | 2 ++
t/t5533-push-cas.sh | 26 ++++++++++++++++++++++++++
3 files changed, 30 insertions(+), 1 deletion(-)
@@ -201,7 +201,8 @@ if it is going to be updated, by requiring its current value to be the same as the specified value `<expect>` (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 `<expect>` is the empty string, then the named ref+must not already exist. + Note that all forms other than `--force-with-lease=<refname>:<expect>` that specifies the expected current value of the ref explicitly are
From: John Keeping <hidden> Date: 2016-07-26 20:47:08
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=<branch>:<expect> syntax, so all we do here is make
this behaviour the default if no explicit "expect" value is specified.
Signed-off-by: John Keeping <redacted>
---
Changes in v3:
- use oidclr()
- final test is now added in the previous patch and now uses the
explicit --force-with-lease syntax
remote.c | 7 +++----
remote.h | 1 -
t/t5533-push-cas.sh | 12 ++++++++++++
3 files changed, 15 insertions(+), 5 deletions(-)
@@ -1544,8 +1544,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. */