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

bootstrap submodule sync overwrites local changes #103485

Closed
Aaron1011 opened this issue Oct 24, 2022 · 12 comments · Fixed by #104865
Closed

bootstrap submodule sync overwrites local changes #103485

Aaron1011 opened this issue Oct 24, 2022 · 12 comments · Fixed by #104865
Assignees
Labels
A-contributor-roadblock Area: Makes things more difficult for new contributors to rust itself E-medium Call for participation: Medium difficulty. Experience needed to fix: Intermediate. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-infra Relevant to the infrastructure team, which will review and decide on the PR/issue.

Comments

@Aaron1011
Copy link
Member

Aaron1011 commented Oct 24, 2022

When bootstrap updates a submodule, it performs a hard reset, discarding all local changes:

rust/src/bootstrap/lib.rs

Lines 631 to 632 in 1481fd9

self.run(Command::new("git").args(&["reset", "-q", "--hard"]).current_dir(&absolute_path));
self.run(Command::new("git").args(&["clean", "-qdfx"]).current_dir(absolute_path));

This was a nasty surprise when I was editing my local src/llvm-project, and then did a git pull and ./x.py build.
Fortunately, I only had some extra debugging prints added, but there was no indication that my local changes would be overwritten.

We should require explicit confirmation before potentially deleting local changes like this.

@Aaron1011 Aaron1011 added T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-infra Relevant to the infrastructure team, which will review and decide on the PR/issue. A-contributor-roadblock Area: Makes things more difficult for new contributors to rust itself labels Oct 24, 2022
@chenyukang
Copy link
Member

There is an option in config.toml:
Automatic submodule handling can still be disabled with build.submodules = false.

We'd better get confirmation if there is no explicit config parameter get from config.toml?

@nagisa
Copy link
Member

nagisa commented Oct 28, 2022

This has been a frequent source of surprises for me as well going back all the way to the addition of x.py. More generally I feel it is important that we figure out what the out-of-the-box experience is tailored for – the developers or people building rustc for distribution. Today this is a mixed bag.

@jyn514 jyn514 added the E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. label Oct 28, 2022
@jyn514
Copy link
Member

jyn514 commented Oct 28, 2022

I think a simple fix would be to use git stash + git apply to save changes before doing a hard reset; if that causes issues for some reason, we can remove all the --force flags so that we don't overwrite local changes and give a hard error instead.

@dotdot0
Copy link
Contributor

dotdot0 commented Oct 31, 2022

Can I work on this issue? Though I need Some guidance I am new to the project

@jyn514 jyn514 added E-medium Call for participation: Medium difficulty. Experience needed to fix: Intermediate. and removed E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. labels Oct 31, 2022
@jyn514
Copy link
Member

jyn514 commented Oct 31, 2022

@pratushrai0309 first, reproduce the original issue so you can be sure your changes are having an effect. Then modify the git commands linked in the original post (#103485 (comment)) to add git stash save before and git stash apply after. If that saves your changes then your work is done and you can open a PR; otherwise you'll have to do some experimenting with git to see what works.

@dotdot0
Copy link
Contributor

dotdot0 commented Oct 31, 2022

So what exactly I should do to reproduce the original Issue. This is my first time contributing to the compiler.

@dotdot0
Copy link
Contributor

dotdot0 commented Oct 31, 2022

@rustbot claim

@dotdot0
Copy link
Contributor

dotdot0 commented Oct 31, 2022

That's what I have done

        self.run(Command::new("git").args(&["stash", "save"]).current_dir(&absolute_path));
        self.run(Command::new("git").args(&["stash", "apply"]).current_dir(&absolute_path));
        self.run(Command::new("git").args(&["reset", "-q", "--hard"]).current_dir(&absolute_path));
        self.run(Command::new("git").args(&["clean", "-qdfx"]).current_dir(absolute_path));

@vincenzopalazzo
Copy link
Member

@pratushrai0309 Maybe a Zulip thread is a better place to show your result and receive more feedback on the solution

@chenyukang
Copy link
Member

chenyukang commented Nov 1, 2022

@pratushrai0309
I think git stash apply will restore the prvious local changes, so if we want to get previous changes, it should added at the ending.

@dotdot0
Copy link
Contributor

dotdot0 commented Nov 1, 2022

@pratushrai0309 I think git stash apply will restore the prvious local changes, so if we want to get previous changes, it should added at the ending.

Yeah! It was a mistake thanks for pointing out

@dotdot0
Copy link
Contributor

dotdot0 commented Nov 1, 2022

I have done the intended changes and opened a PR #103810 .
Can someone please review it?

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 E-medium Call for participation: Medium difficulty. Experience needed to fix: Intermediate. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-infra Relevant to the infrastructure team, which will review and decide on the PR/issue.
Projects
None yet
6 participants