Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x.py breaks submodule state when run in a pre-commit hook from a worktree #77620

Closed
jyn514 opened this issue Oct 6, 2020 · 4 comments
Closed
Labels
A-contributor-roadblock Area: Makes things more difficult for new contributors to rust itself C-bug Category: This is a bug. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)

Comments

@jyn514
Copy link
Member

jyn514 commented Oct 6, 2020

This has been around for a while but #76356 will exacerbate the issue.

Steps to replicate:

$ head -n 3  .git/hooks/pre-commit
#!/usr/bin/env bash
cd "$(git rev-parse --show-toplevel)"
./x.py test tidy --bless
$ git worktree add ~/rustc-worktree
Preparing worktree (new branch 'rustc-worktree')
Updating files: 100% (25306/25306), done.
HEAD is now at 8932bb68755 tmp
$ cd ~/rustc-worktree
$ git commit
# spends a long time cloning submodules
extracting /home/joshua/rustc-worktree/build/cache/2020-07-12/rustfmt-nightly-x86_64-unknown-linux-gnu.tar.gz
error: failed to read `/home/joshua/rustc-worktree/src/tools/miri/cargo-miri/Cargo.toml`

Caused by:
  No such file or directory (os error 2)
failed to run: /home/joshua/rustc-worktree/build/x86_64-unknown-linux-gnu/stage0/bin/cargo build --manifest-path /home/joshua/rustc-worktree/src/bootstrap/Cargo.toml
Build completed unsuccessfully in 0:04:52
$ git status
Refresh index: 100% (25306/25306), done.
On branch rustc-worktree
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
  (commit or discard the untracked or modified content in submodules)
	modified:   library/backtrace (modified content, untracked content)
	modified:   library/stdarch (modified content, untracked content)
	modified:   src/doc/book (modified content, untracked content)
	modified:   src/doc/edition-guide (modified content, untracked content)
	modified:   src/doc/embedded-book (modified content, untracked content)
	modified:   src/doc/nomicon (modified content, untracked content)
	modified:   src/doc/reference (modified content, untracked content)
	modified:   src/doc/rust-by-example (modified content, untracked content)
	modified:   src/doc/rustc-dev-guide (modified content, untracked content)
	modified:   src/llvm-project (modified content, untracked content)
	modified:   src/tools/cargo (modified content, untracked content)
	modified:   src/tools/miri (modified content, untracked content)
	modified:   src/tools/rls (modified content, untracked content)
	modified:   src/tools/rust-analyzer (modified content, untracked content)
	modified:   src/tools/rust-installer (modified content, untracked content)
	modified:   src/tools/rustfmt (modified content, untracked content)

no changes added to commit (use "git add" and/or "git commit -a")
@jyn514 jyn514 added T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) C-bug Category: This is a bug. A-contributor-roadblock Area: Makes things more difficult for new contributors to rust itself labels Oct 6, 2020
@jyn514
Copy link
Member Author

jyn514 commented Oct 6, 2020

Breakage
$ cd library/backtrace
$ git status
HEAD detached at 4083a90
Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
	deleted:    .github/workflows/main.yml
	modified:   .gitignore
	modified:   .gitmodules
	modified:   Cargo.toml
	modified:   LICENSE-APACHE
	modified:   LICENSE-MIT
	modified:   README.md
	deleted:    benches/benchmarks.rs
	deleted:    ci/android-ndk.sh
	deleted:    ci/android-sdk.sh
	deleted:    ci/docker/aarch64-linux-android/Dockerfile
	deleted:    ci/docker/aarch64-unknown-linux-gnu/Dockerfile
	deleted:    ci/docker/arm-linux-androideabi/Dockerfile
	deleted:    ci/docker/arm-unknown-linux-gnueabihf/Dockerfile
	deleted:    ci/docker/armv7-linux-androideabi/Dockerfile
	deleted:    ci/docker/armv7-unknown-linux-gnueabihf/Dockerfile
	deleted:    ci/docker/i586-unknown-linux-gnu/Dockerfile
	deleted:    ci/docker/i686-linux-android/Dockerfile
	deleted:    ci/docker/i686-unknown-linux-gnu/Dockerfile
	deleted:    ci/docker/powerpc64-unknown-linux-gnu/Dockerfile
	deleted:    ci/docker/x86_64-linux-android/Dockerfile
	deleted:    ci/docker/x86_64-pc-windows-gnu/Dockerfile
	deleted:    ci/docker/x86_64-unknown-linux-gnu/Dockerfile
	deleted:    ci/docker/x86_64-unknown-linux-musl/Dockerfile
	deleted:    ci/run-docker.sh
	deleted:    ci/run.sh
	deleted:    ci/runtest-android.rs
	deleted:    crates/as-if-std/Cargo.toml
	deleted:    crates/as-if-std/build.rs
	deleted:    crates/as-if-std/src/lib.rs
	deleted:    crates/backtrace-sys/Cargo.toml
	deleted:    crates/backtrace-sys/LICENSE-APACHE
	deleted:    crates/backtrace-sys/LICENSE-MIT
	deleted:    crates/backtrace-sys/build.rs
	deleted:    crates/backtrace-sys/src/android-api.c
	deleted:    crates/backtrace-sys/src/lib.rs
	deleted:    crates/cpp_smoke_test/Cargo.toml
	deleted:    crates/cpp_smoke_test/build.rs
	deleted:    crates/cpp_smoke_test/cpp/trampoline.cpp
	deleted:    crates/cpp_smoke_test/src/lib.rs
	deleted:    crates/cpp_smoke_test/tests/smoke.rs
	deleted:    crates/dylib-dep/Cargo.toml
	deleted:    crates/dylib-dep/src/lib.rs
	deleted:    crates/line-tables-only/Cargo.toml
	deleted:    crates/line-tables-only/build.rs
	deleted:    crates/line-tables-only/src/callback.c
	deleted:    crates/line-tables-only/src/lib.rs
	deleted:    crates/macos_frames_test/Cargo.toml
	deleted:    crates/macos_frames_test/src/lib.rs
	deleted:    crates/macos_frames_test/tests/main.rs
	deleted:    crates/without_debuginfo/Cargo.toml
	deleted:    crates/without_debuginfo/src/lib.rs
	deleted:    crates/without_debuginfo/tests/smoke.rs
	deleted:    examples/backtrace.rs
	deleted:    examples/raw.rs
	deleted:    src/backtrace/dbghelp.rs
	deleted:    src/backtrace/libunwind.rs
	deleted:    src/backtrace/mod.rs
	deleted:    src/backtrace/noop.rs
	deleted:    src/capture.rs
	deleted:    src/dbghelp.rs
	deleted:    src/lib.rs
	deleted:    src/print.rs
	deleted:    src/print/fuchsia.rs
	deleted:    src/symbolize/dbghelp.rs
	deleted:    src/symbolize/gimli.rs
	deleted:    src/symbolize/gimli/coff.rs
	deleted:    src/symbolize/gimli/elf.rs
	deleted:    src/symbolize/gimli/macho.rs
	deleted:    src/symbolize/gimli/mmap_fake.rs
	deleted:    src/symbolize/gimli/mmap_unix.rs
	deleted:    src/symbolize/gimli/mmap_windows.rs
	deleted:    src/symbolize/gimli/stash.rs
	deleted:    src/symbolize/libbacktrace.rs
	deleted:    src/symbolize/mod.rs
	deleted:    src/symbolize/noop.rs
	deleted:    src/types.rs
	deleted:    src/windows.rs
	deleted:    tests/accuracy/auxiliary.rs
	deleted:    tests/accuracy/main.rs
	deleted:    tests/concurrent-panics.rs
	deleted:    tests/long_fn_name.rs
	deleted:    tests/skip_inner_frames.rs
	deleted:    tests/smoke.rs

Untracked files:
  (use "git add <file>..." to include in what will be committed)
	.gitattributes
	.github/ISSUE_TEMPLATE/
	.github/workflows/ci.yml
	.mailmap
	CODE_OF_CONDUCT.md
	CONTRIBUTING.md
	COPYRIGHT
	Cargo.lock
	RELEASES.md
	compiler/
	config.toml.example
	configure
	library/
	rustfmt.toml
	src/README.md
	src/bootstrap/
	src/build_helper/
	src/ci/
	src/doc/
	src/etc/
	src/librustdoc/
	src/stage0.txt
	src/test/
	src/tools/
	src/version
	triagebot.toml
	x.py

@ecstatic-morse
Copy link
Contributor

I've had unset=GIT_DIR at the beginning of my pre-push hook for a while. This seems to work around the problem. No idea what the root cause is.

@jyn514
Copy link
Member Author

jyn514 commented Oct 7, 2020

Here's a script that will fix it if it does happen:

git diff --name-only | while read dir; do cd $dir && git checkout -f HEAD && git clean -d -f && cd -; done

jyn514 added a commit to jyn514/rust that referenced this issue Oct 7, 2020
bors added a commit to rust-lang-ci/rust that referenced this issue Oct 8, 2020
Unset GIT_DIR in pre-commit hook

Works around rust-lang#77620. This won't help any other hooks you write manually, but hopefully people won't feel the need to do that now there's an 'official' one.

r? `@Mark-Simulacrum`
cc `@caass`
@jyn514
Copy link
Member Author

jyn514 commented Feb 3, 2023

I'm going to chalk this up to git weirdness and close the issue until we run into more trouble.

@jyn514 jyn514 closed this as completed Feb 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-contributor-roadblock Area: Makes things more difficult for new contributors to rust itself C-bug Category: This is a bug. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)
Projects
None yet
Development

No branches or pull requests

2 participants