git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* Push force-with-lease with multi-URL remote
@ 2019-07-27 16:54 Christopher Head
  2019-07-27 17:46 ` Junio C Hamano
  2019-07-29 10:20 ` Jeff King
  0 siblings, 2 replies; 12+ messages in thread
From: Christopher Head @ 2019-07-27 16:54 UTC (permalink / raw)
  To: git

[-- Attachment #1: Type: text/plain, Size: 1164 bytes --]

Hi folks,
When a single remote has multiple push URLs, Git’s force-with-lease
logic appears to be:

For each URL:
1. Read refs/heads/mybranch (call this commit X)
2. Read refs/remotes/myremote/mybranch (call this commit Y)
3. Send to the URL an atomic compare-and-swap, replacing Y with X.
4. If step 3 succeeded, change refs/remotes/myremote/mybranch to X.

This means that, assuming both URLs start out identical, the second URL
will always fail because refs/remots/myremote/mybranch has been updated
from Y to X, and therefore the second compare-and-swap fails. I can’t
imagine any situation in which this behaviour is actually useful.

This is what I would expect:

1. Read refs/heads/mybranch (call this commit X)
2. Read refs/remotes/myremote/mybranch (call this commit Y)
3. For each URL:
3a. Send to the URL an atomic compare-and-swap, replacing Y with X.
4. If any (or maybe all) of the CAS operations in 3a succeeded, change
refs/remotes/myremote/mybranch to X.

Thoughts? Does anyone have a use case for the existing behaviour? I
have attached a shell script which constructs some repos and
demonstrates the situation.

Thanks!
-- 
Christopher Head

[-- Attachment #2: test --]
[-- Type: application/octet-stream, Size: 521 bytes --]

#!/bin/bash

set -e

# Create remote1, remote2, local.
git init --bare remote1
git init --bare remote2
git init local
cd local
git remote add origin ../remote1
git remote set-url --push origin ../remote1
git remote set-url --push --add origin ../remote2

# Add commit A and push.
echo 'hello world' > test.txt
git add test.txt
git commit -m 'Commit A'
git push -u origin master

# Amend to commit B.
echo 'goodbye world' > test.txt
git add test.txt
git commit --amend --no-edit

# Force-push.
git push --force-with-lease

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2019-07-29 22:29 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-27 16:54 Push force-with-lease with multi-URL remote Christopher Head
2019-07-27 17:46 ` Junio C Hamano
2019-07-27 18:15   ` Christopher Head
2019-07-27 20:57     ` Junio C Hamano
2019-07-27 21:43       ` Christopher Head
2019-07-29  5:19         ` Junio C Hamano
2019-07-29 10:20 ` Jeff King
2019-07-29 13:33   ` Junio C Hamano
2019-07-29 13:47     ` Christopher Head
2019-07-29 19:20     ` Jeff King
2019-07-29 21:44       ` Junio C Hamano
2019-07-29 22:29         ` Jeff King

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).