Skip to content

Commit

Permalink
Fix git push --dry-run to not report spurious errors
Browse files Browse the repository at this point in the history
  • Loading branch information
glandium committed Sep 12, 2024
1 parent 32a79d4 commit b62e036
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4816,7 +4816,7 @@ fn remote_helper_push(
.map(|n| n > 0)
.unwrap_or_default())
} else if source_cid.is_some() {
Ok(!pushed.is_empty())
Ok(!pushed.is_empty() || dry_run)
} else {
Err("Deleting remote branches is unsupported")
};
Expand Down
87 changes: 87 additions & 0 deletions tests/push.t
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ Create an empty mercurial repository where we are going to push.

Pushing from a repo with cinnabar metadata to an empty mercurial repo works

$ git -C abc-git push --dry-run origin d04f6df4abe2870ceb759263ee6aaa9241c4f93c:refs/heads/branches/default/tip
To hg::.*/push.t/repo (re)
* [new branch] d04f6df4abe2870ceb759263ee6aaa9241c4f93c -> branches/default/tip
$ git -C abc-git push origin d04f6df4abe2870ceb759263ee6aaa9241c4f93c:refs/heads/branches/default/tip
remote: adding changesets
remote: adding manifests
Expand All @@ -94,6 +97,9 @@ Pushing from a repo without cinnabar metadata to an empty mercurial repo works
$ git -C abc-git cinnabar rollback 0000000000000000000000000000000000000000
$ rm -rf $REPO/.hg
$ hg init $REPO
$ git -C abc-git push --dry-run origin d04f6df4abe2870ceb759263ee6aaa9241c4f93c:refs/heads/branches/default/tip
To hg::.*/push.t/repo (re)
* [new branch] d04f6df4abe2870ceb759263ee6aaa9241c4f93c -> branches/default/tip
$ git -C abc-git push origin d04f6df4abe2870ceb759263ee6aaa9241c4f93c:refs/heads/branches/default/tip
remote: adding changesets
remote: adding manifests
Expand All @@ -106,6 +112,11 @@ Pushing from a repo without cinnabar metadata to a non-empty mercurial repo
requires pulling first.

$ git -C abc-git cinnabar rollback 0000000000000000000000000000000000000000
$ git -C abc-git push --dry-run origin 687e015f9f646bb19797d991f2f53087297fbe14:refs/heads/branches/default/tip
\r (no-eol) (esc)
ERROR Cannot push to this remote without pulling/updating first.
error: failed to push some refs to 'hg::.*/push.t/repo' (re)
[1]
$ git -C abc-git push origin 687e015f9f646bb19797d991f2f53087297fbe14:refs/heads/branches/default/tip
\r (no-eol) (esc)
ERROR Cannot push to this remote without pulling/updating first.
Expand All @@ -114,6 +125,11 @@ requires pulling first.

Same, even when forced.

$ git -C abc-git push -f --dry-run origin 687e015f9f646bb19797d991f2f53087297fbe14:refs/heads/branches/default/tip
\r (no-eol) (esc)
ERROR Cannot push to this remote without pulling/updating first.
error: failed to push some refs to 'hg::.*/push.t/repo' (re)
[1]
$ git -C abc-git push -f origin 687e015f9f646bb19797d991f2f53087297fbe14:refs/heads/branches/default/tip
\r (no-eol) (esc)
ERROR Cannot push to this remote without pulling/updating first.
Expand All @@ -125,6 +141,9 @@ However, after pulling, we have a shared root, and we can push
$ git -c fetch.prune=true -C abc-git remote update origin
Fetching origin

$ git -C abc-git push --dry-run origin 687e015f9f646bb19797d991f2f53087297fbe14:refs/heads/branches/default/tip
To hg::.*/push.t/repo (re)
d04f6df..687e015 687e015f9f646bb19797d991f2f53087297fbe14 -> branches/default/tip
$ git -C abc-git push origin 687e015f9f646bb19797d991f2f53087297fbe14:refs/heads/branches/default/tip
remote: adding changesets
remote: adding manifests
Expand All @@ -137,6 +156,11 @@ Pushing from a repo without cinnabar metadata to a non-empty mercurial repo
with different contents requires pulling first.

$ git -C def-git cinnabar rollback 0000000000000000000000000000000000000000
$ git -C def-git push --dry-run origin 62326f34fea5b80510f57599da9fd6e5997c0ca4:refs/heads/branches/default/tip
\r (no-eol) (esc)
ERROR Cannot push to this remote without pulling/updating first.
error: failed to push some refs to 'hg::.*/push.t/repo' (re)
[1]
$ git -C def-git push origin 62326f34fea5b80510f57599da9fd6e5997c0ca4:refs/heads/branches/default/tip
\r (no-eol) (esc)
ERROR Cannot push to this remote without pulling/updating first.
Expand All @@ -145,6 +169,11 @@ with different contents requires pulling first.

Same, even when forced.

$ git -C def-git push -f --dry-run origin 62326f34fea5b80510f57599da9fd6e5997c0ca4:refs/heads/branches/default/tip
\r (no-eol) (esc)
ERROR Cannot push to this remote without pulling/updating first.
error: failed to push some refs to 'hg::.*/push.t/repo' (re)
[1]
$ git -C def-git push -f origin 62326f34fea5b80510f57599da9fd6e5997c0ca4:refs/heads/branches/default/tip
\r (no-eol) (esc)
ERROR Cannot push to this remote without pulling/updating first.
Expand All @@ -159,6 +188,15 @@ and can't push, but that's caught by git itself.
From hg::.*/push.t/repo (re)
+ 62326f3...687e015 branches/default/tip -> origin/branches/default/tip (forced update)

$ git -c advice.pushnonffcurrent=true -c advice.pushupdaterejected=true -C def-git push --dry-run origin 62326f34fea5b80510f57599da9fd6e5997c0ca4:refs/heads/branches/default/tip
To hg::.*/push.t/repo (re)
! [rejected] 62326f34fea5b80510f57599da9fd6e5997c0ca4 -> branches/default/tip (non-fast-forward)
error: failed to push some refs to 'hg::.*/push.t/repo' (re)
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart.* (re)
hint: .*before pushing again. (re)
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
[1]
$ git -c advice.pushnonffcurrent=true -c advice.pushupdaterejected=true -C def-git push origin 62326f34fea5b80510f57599da9fd6e5997c0ca4:refs/heads/branches/default/tip
To hg::.*/push.t/repo (re)
! [rejected] 62326f34fea5b80510f57599da9fd6e5997c0ca4 -> branches/default/tip (non-fast-forward)
Expand All @@ -171,6 +209,11 @@ and can't push, but that's caught by git itself.

This time, forced push is allowed.

$ git -c advice.pushnonffcurrent=true -c advice.pushupdaterejected=true -C def-git push origin -f --dry-run 62326f34fea5b80510f57599da9fd6e5997c0ca4:refs/heads/branches/default/tip
\r (no-eol) (esc)
WARNING Pushing a new root
To hg::.*/push.t/repo (re)
+ 687e015...62326f3 62326f34fea5b80510f57599da9fd6e5997c0ca4 -> branches/default/tip (forced update)
$ git -c advice.pushnonffcurrent=true -c advice.pushupdaterejected=true -C def-git push origin -f 62326f34fea5b80510f57599da9fd6e5997c0ca4:refs/heads/branches/default/tip
\r (no-eol) (esc)
WARNING Pushing a new root
Expand All @@ -188,11 +231,21 @@ Similarly, when pushing from a shallow git repository.
$ rm -rf $REPO/.hg
$ hg init $REPO
$ git -C abc-shallow remote set-url origin hg::$REPO
$ git -C abc-shallow push --dry-run origin 687e015f9f646bb19797d991f2f53087297fbe14:refs/heads/branches/default/tip
\r (no-eol) (esc)
ERROR Pushing git shallow clones is not supported.
error: failed to push some refs to 'hg::.*/push.t/repo' (re)
[1]
$ git -C abc-shallow push origin 687e015f9f646bb19797d991f2f53087297fbe14:refs/heads/branches/default/tip
\r (no-eol) (esc)
ERROR Pushing git shallow clones is not supported.
error: failed to push some refs to 'hg::.*/push.t/repo' (re)
[1]
$ git -C abc-shallow push -f --dry-run origin 687e015f9f646bb19797d991f2f53087297fbe14:refs/heads/branches/default/tip
\r (no-eol) (esc)
ERROR Pushing git shallow clones is not supported.
error: failed to push some refs to 'hg::.*/push.t/repo' (re)
[1]
$ git -C abc-shallow push -f origin 687e015f9f646bb19797d991f2f53087297fbe14:refs/heads/branches/default/tip
\r (no-eol) (esc)
ERROR Pushing git shallow clones is not supported.
Expand All @@ -204,6 +257,11 @@ After pulling from a different repo, we still recognize we have a shallow clone.
$ git -C abc-shallow cinnabar fetch hg::$DEF 90f6163d2820561ebe0f6c28e87d766ef619e43c
From hg::.*/push.t/def (re)
* branch hg/revs/90f6163d2820561ebe0f6c28e87d766ef619e43c -> FETCH_HEAD
$ git -C abc-shallow push -f --dry-run origin 687e015f9f646bb19797d991f2f53087297fbe14:refs/heads/branches/default/tip
\r (no-eol) (esc)
ERROR Pushing git shallow clones is not supported.
error: failed to push some refs to 'hg::.*/push.t/repo' (re)
[1]
$ git -C abc-shallow push -f origin 687e015f9f646bb19797d991f2f53087297fbe14:refs/heads/branches/default/tip
\r (no-eol) (esc)
ERROR Pushing git shallow clones is not supported.
Expand All @@ -216,6 +274,9 @@ supported and makes it unshallowed.
$ git -C abc-shallow cinnabar fetch hg::$ABC bd623dea939349b06a47d5dce064255e5f1d9ec1
From hg::.*/push.t/abc (re)
* branch hg/revs/bd623dea939349b06a47d5dce064255e5f1d9ec1 -> FETCH_HEAD
$ git -C abc-shallow push -f --dry-run origin 687e015f9f646bb19797d991f2f53087297fbe14:refs/heads/branches/default/tip
To hg::.*/push.t/repo (re)
* [new branch] 687e015f9f646bb19797d991f2f53087297fbe14 -> branches/default/tip
$ git -C abc-shallow push -f origin 687e015f9f646bb19797d991f2f53087297fbe14:refs/heads/branches/default/tip
remote: adding changesets
remote: adding manifests
Expand All @@ -234,6 +295,9 @@ Phase and cinnabar.data tests.
From ../def-git
* branch 62326f34fea5b80510f57599da9fd6e5997c0ca4 -> FETCH_HEAD

$ git -c cinnabar.data=never -C xyz-git push --dry-run origin 8b86a58578d5270969543e287634e3a2f122a338:refs/heads/branches/default/tip
To hg::.*/push.t/xyz (re)
* [new branch] 8b86a58578d5270969543e287634e3a2f122a338 -> branches/default/tip
$ git -c cinnabar.data=never -C xyz-git push origin 8b86a58578d5270969543e287634e3a2f122a338:refs/heads/branches/default/tip
remote: adding changesets
remote: adding manifests
Expand All @@ -249,6 +313,9 @@ Phase and cinnabar.data tests.
$ git -C xyz-git cinnabar rollback --candidates
2836e453f32b1ecccd3acca412f75b07c88176bf (current)

$ git -c cinnabar.data=phase -C xyz-git push --dry-run origin d04f6df4abe2870ceb759263ee6aaa9241c4f93c:refs/heads/branches/default/tip
To hg::.*/push.t/xyz (re)
8b86a58..d04f6df d04f6df4abe2870ceb759263ee6aaa9241c4f93c -> branches/default/tip
$ git -c cinnabar.data=phase -C xyz-git push origin d04f6df4abe2870ceb759263ee6aaa9241c4f93c:refs/heads/branches/default/tip
remote: adding changesets
remote: adding manifests
Expand All @@ -268,6 +335,9 @@ Server is publishing, so metadata was stored.
> publish = False
> EOF

$ git -c cinnabar.data=phase -C xyz-git push --dry-run origin 687e015f9f646bb19797d991f2f53087297fbe14:refs/heads/branches/default/tip
To hg::.*/push.t/xyz (re)
d04f6df..687e015 687e015f9f646bb19797d991f2f53087297fbe14 -> branches/default/tip
$ git -c cinnabar.data=phase -C xyz-git push origin 687e015f9f646bb19797d991f2f53087297fbe14:refs/heads/branches/default/tip
remote: adding changesets
remote: adding manifests
Expand All @@ -289,6 +359,11 @@ Server is now non-publishing, so metadata is unchanged.
8b8194eefb69ec89edc35dafb965311fe48c49d0
2836e453f32b1ecccd3acca412f75b07c88176bf

$ git -c cinnabar.data=always -C xyz-git push -f --dry-run origin 7ca6a3c32ec0dbcbcd155b2be6e2f4505012c273:refs/heads/branches/default/tip
\r (no-eol) (esc)
WARNING Pushing a new root
To hg::.*/push.t/xyz (re)
+ 687e015...7ca6a3c 7ca6a3c32ec0dbcbcd155b2be6e2f4505012c273 -> branches/default/tip (forced update)
$ git -c cinnabar.data=always -C xyz-git push -f origin 7ca6a3c32ec0dbcbcd155b2be6e2f4505012c273:refs/heads/branches/default/tip
\r (no-eol) (esc)
WARNING Pushing a new root
Expand Down Expand Up @@ -318,6 +393,9 @@ Pushing a root to a new non-publishing repo should work.
From ../xyz-git
* branch 687e015f9f646bb19797d991f2f53087297fbe14 -> FETCH_HEAD

$ git -c cinnabar.data=phase -C uvw-git push --dry-run origin 687e015f9f646bb19797d991f2f53087297fbe14:refs/heads/branches/default/tip
To hg::.*/push.t/uvw (re)
* [new branch] 687e015f9f646bb19797d991f2f53087297fbe14 -> branches/default/tip
$ git -c cinnabar.data=phase -C uvw-git push origin 687e015f9f646bb19797d991f2f53087297fbe14:refs/heads/branches/default/tip
remote: adding changesets
remote: adding manifests
Expand Down Expand Up @@ -352,6 +430,9 @@ We won't be able to push without first pulling something, so fetch the first com
2: draft
$ hg --config extensions.strip= -R $UVW strip -r 2 --no-backup

$ git -c cinnabar.data=phase -C uvw-git push --dry-run origin 687e015f9f646bb19797d991f2f53087297fbe14:refs/heads/branches/default/tip
To hg::.*/push.t/uvw (re)
* [new branch] 687e015f9f646bb19797d991f2f53087297fbe14 -> branches/default/tip
$ git -c cinnabar.data=phase -C uvw-git push origin 687e015f9f646bb19797d991f2f53087297fbe14:refs/heads/branches/default/tip
remote: adding changesets
remote: adding manifests
Expand All @@ -371,6 +452,9 @@ Test the git_commit experimental feature.
$ rm -rf $REPO/.hg
$ hg init $REPO
$ git -C abc-git cinnabar rollback 0000000000000000000000000000000000000000
$ git -C abc-git push --dry-run origin 8b86a58578d5270969543e287634e3a2f122a338:refs/heads/branches/default/tip
To hg::.*/push.t/repo (re)
* [new branch] 8b86a58578d5270969543e287634e3a2f122a338 -> branches/default/tip
$ git -C abc-git push origin 8b86a58578d5270969543e287634e3a2f122a338:refs/heads/branches/default/tip
remote: adding changesets
remote: adding manifests
Expand All @@ -379,6 +463,9 @@ Test the git_commit experimental feature.
To hg::.*/push.t/repo (re)
* [new branch] 8b86a58578d5270969543e287634e3a2f122a338 -> branches/default/tip

$ git -c cinnabar.experiments=git_commit -C abc-git push --dry-run origin 687e015f9f646bb19797d991f2f53087297fbe14:branches/default/tip
To hg::.*/push.t/repo (re)
8b86a58..687e015 687e015f9f646bb19797d991f2f53087297fbe14 -> branches/default/tip
$ git -c cinnabar.experiments=git_commit -C abc-git push origin 687e015f9f646bb19797d991f2f53087297fbe14:branches/default/tip
remote: adding changesets
remote: adding manifests
Expand Down

0 comments on commit b62e036

Please sign in to comment.