🐛 Put the committed Cargo.lock back before an update moves the tree
A user's build rewrites Cargo.lock: cargo adds the metal2vulkan git sources the committed lock leaves out. A changed lock then stops both ways an update moves the checkout: reims-ctl's channel switch (git switch) and the script's git pull --ff-only, as soon as the target changes the lock too. The update failed with "commit or set aside its local changes". The lock is the build's to write, so nothing is lost: reims-ctl's switch and install-ctl.sh --update check the committed one out before they move, and the next build writes it again. The switch test now has branches whose locks differ and a clone whose lock the build rewrote.
This commit is contained in:
1 parent
c03936edfc
commit
c099dd5a4d
2 files changed
+22
-8
No files matched your search
@@ -90,7 +90,8 @@ pub fn update(channel: Option<Channel>) -> Result<()> {
|
||||
/// where it tracks none). A branch the checkout lacks is made tracking the remote's, and one
|
||||
/// that tracks nothing is set to track it, so the script's pull moves it on. git tracks only a
|
||||
/// branch the remote's fetch refspecs cover, which a single-branch clone's do not: the branch is
|
||||
/// added to them there.
|
||||
/// added to them there. The committed Cargo.lock goes back first: the build writes it again, and
|
||||
/// git refuses to switch over a changed file the branches differ in.
|
||||
fn switch(repo: &Path, c: Channel) -> Result<()> {
|
||||
let branch = c.branch();
|
||||
if !repo.join(".git").exists() {
|
||||
@@ -127,6 +128,7 @@ fn switch(repo: &Path, c: Channel) -> Result<()> {
|
||||
&["fetch", &remote, &format!("+{src}:refs/remotes/{upstream}")],
|
||||
)
|
||||
.with_context(|| format!("fetch {branch} from {remote}"))?;
|
||||
git(repo, &["checkout", "-q", "HEAD", "--", "Cargo.lock"])?;
|
||||
let have = git_output(repo, &["rev-parse", "--verify", "-q", &src]);
|
||||
if have.is_none() {
|
||||
git(repo, &["switch", "--track", "-c", branch, &upstream])
|
||||
@@ -204,12 +206,14 @@ mod tests {
|
||||
run(&origin, &["init", "-q", "-b", "master"]);
|
||||
run(&origin, &["config", "user.name", "t"]);
|
||||
run(&origin, &["config", "user.email", "t@t"]);
|
||||
run(&origin, &["commit", "-q", "--allow-empty", "-m", "stable"]);
|
||||
// The branches' locks differ, as a pull of a lock change finds them.
|
||||
let lock = |dir: &Path, s: &str| std::fs::write(dir.join("Cargo.lock"), s).unwrap();
|
||||
lock(&origin, "stable");
|
||||
run(&origin, &["add", "Cargo.lock"]);
|
||||
run(&origin, &["commit", "-q", "-m", "stable"]);
|
||||
run(&origin, &["switch", "-q", "-c", "development"]);
|
||||
run(
|
||||
&origin,
|
||||
&["commit", "-q", "--allow-empty", "-m", "development"],
|
||||
);
|
||||
lock(&origin, "development");
|
||||
run(&origin, &["commit", "-q", "-a", "-m", "development"]);
|
||||
run(&origin, &["switch", "-q", "master"]);
|
||||
// A single-branch clone, whose fetches keep only master.
|
||||
run(
|
||||
@@ -224,9 +228,15 @@ mod tests {
|
||||
"clone",
|
||||
],
|
||||
);
|
||||
// The build rewrote the clone's lock.
|
||||
lock(&clone, "built");
|
||||
|
||||
switch(&clone, Channel::Development).unwrap();
|
||||
assert_eq!(current_branch(&clone).as_deref(), Some("development"));
|
||||
assert_eq!(
|
||||
std::fs::read_to_string(clone.join("Cargo.lock")).unwrap(),
|
||||
"development"
|
||||
);
|
||||
assert_eq!(
|
||||
git_output(&clone, &["rev-parse", "--abbrev-ref", "@{u}"]).as_deref(),
|
||||
Some("origin/development")
|
||||
|
||||
@@ -27,8 +27,8 @@
|
||||
# (crates/reims-ctl/src/reims_util.rs).
|
||||
#
|
||||
# --yes install what is missing without asking (rustup with -y too)
|
||||
# --update pull this checkout first (git pull --ff-only); reims-ctl update
|
||||
# runs this
|
||||
# --update pull this checkout first (git pull --ff-only), putting back the
|
||||
# committed Cargo.lock the build rewrote; reims-ctl update runs this
|
||||
# --skip-qemu install reims-ctl alone, keeping the installed QEMU
|
||||
#
|
||||
# Environment: CARGO_TARGET_DIR, the library's build (default the checkout's
|
||||
@@ -101,6 +101,10 @@ mkdir -p "$DATA" "$CACHE"
|
||||
if [[ $UPDATE == 1 ]]; then
|
||||
say "Pulling $ROOT"
|
||||
if git -C "$ROOT" rev-parse --abbrev-ref --symbolic-full-name '@{u}' >/dev/null 2>&1; then
|
||||
# The build writes Cargo.lock again (cargo adds the git sources the
|
||||
# committed lock leaves out), and a changed lock stops a pull that changes
|
||||
# it too: the committed one goes back first.
|
||||
git -C "$ROOT" checkout -q HEAD -- Cargo.lock
|
||||
git -C "$ROOT" pull --ff-only || die "git pull --ff-only failed: the checkout has local commits or changes; update it yourself, then run $0"
|
||||
else
|
||||
warn "the checkout's branch tracks no remote branch: building it as it is"
|
||||
|
||||
Reference in new issue
Block a user