Skip to content

push: base new branch on latest upstream main#47

Open
RalfJung wants to merge 1 commit intorust-lang:mainfrom
RalfJung:push-on-latest
Open

push: base new branch on latest upstream main#47
RalfJung wants to merge 1 commit intorust-lang:mainfrom
RalfJung:push-on-latest

Conversation

@RalfJung
Copy link
Copy Markdown
Member

Fixes #46

I tested this by doing a Miri-push.
Cc @lnicola

Comment thread src/sync.rs
"push",
&user_upstream_url,
&format!("{base_upstream_sha}:refs/heads/{branch}"),
&format!("FETCH_HEAD:refs/heads/{branch}"),
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we rely on nothing else working on the same git repo concurrently as that could clobber FETCH_HEAD...

Copy link
Copy Markdown
Contributor

@tgross35 tgross35 Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not that it's the biggest concern, but you can be robust against this by replacing base_upstream_sha with the equivalent of the below rather than relying on FETCH_HEAD:

$ git ls-remote https://github.com/rust-lang/rust refs/heads/main
f676c20edd32321e9fa2781543d8970109707e30        refs/heads/main

(this is a fast operation unlike the fetch itself)

@tgross35
Copy link
Copy Markdown
Contributor

Maybe it's worth having a CLI argument to override the base? I think that with this change, running twice could get you two different results if r-l/r has an update in the meantime.

@RalfJung
Copy link
Copy Markdown
Member Author

I think that with this change, running twice could get you two different results if r-l/r has an update in the meantime.

The entire reason why we're doing this is that this is already the case. That's what caused this problem. That's what I tried to explain in #46.

@tgross35
Copy link
Copy Markdown
Contributor

Hm - I meant for the purpose of being able to rerun locally and use the same base within a small timescale to pull in a few new commits on top of the existing tree, without changing the history that I've already looked through and verified. Not typically long enough to run into the problem. But that's not overly useful so 🤷

Nothing is going to be completely robust against the race here if that operation isn't durable, unless we do something like fail the merge in CI if new changes happened while the subtree sync was in the queue.

@RalfJung
Copy link
Copy Markdown
Member Author

Yeah this assumes that pushes are totally ordered. Which seems like a reasonable requirement, subtrees should coordinate about who's doing syncs (or maybe we can even mostly automate them).

@RalfJung
Copy link
Copy Markdown
Member Author

I just tied to do another miri push sync with this and got an error:

Preparing https://github.com/RalfJung/rust...
+ cd "../rustc" && "git" "fetch" "https://github.com/RalfJung/rust" "miri"
+ cd "../rustc" && "git" "fetch" "https://github.com/rust-lang/rust"
+ cd "../rustc" && "git" "push" "https://github.com/RalfJung/rust" "FETCH_HEAD:refs/heads/miri"

Pushing changes...
+ cd "/home/r/src/rust/miri" && "git" "push" "http://localhost:42042/RalfJung/rust.git:rev(75dd959a3a40eb5b4574f8d2e23aa6efbeb33573:prefix=src/tools/miri):/src/tools/miri.git" "HEAD:miri"
Error: cannot perform push

Caused by:
    Command `cd "/home/r/src/rust/miri" && "git" "push" "http://localhost:42042/RalfJung/rust.git:rev(75dd959a3a40eb5b4574f8d2e23aa6efbeb33573:prefix=src/tools/miri):/src/tools/miri.git" "HEAD:miri"` failed with exit code Some(1). STDOUT:
    
    STDERR:
    To http://localhost:42042/RalfJung/rust.git:rev(75dd959a3a40eb5b4574f8d2e23aa6efbeb33573:prefix=src/tools/miri):/src/tools/miri.git
     ! [rejected]            HEAD -> miri (fetch first)
    error: failed to push some refs to 'http://localhost:42042/RalfJung/rust.git:rev(75dd959a3a40eb5b4574f8d2e23aa6efbeb33573:prefix=src/tools/miri):/src/tools/miri.git'
    hint: Updates were rejected because the remote contains work that you do not
    hint: have locally. This is usually caused by another repository pushing to
    hint: the same ref. If you want to integrate the remote changes, use
    hint: 'git pull' before pushing again.
    hint: See the 'Note about fast-forwards' in 'git push --help' for details.

@christian-schilling any idea what is happening here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

push should likely push to latest HEAD, not the commit recorded in rust-version

2 participants