-
-
Notifications
You must be signed in to change notification settings - Fork 51
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
Fix updating pins on crates which track Alire-generated files #1788
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
1469174
Fix updating pins on crates which track Alire-generated files
Seb-MCaw 587a1b2
Require user confirmation before discarding changes
Seb-MCaw f33e470
Merge branch 'master' into fix/update-dirty-pin
Seb-MCaw 668319f
Make confirmation prompt depend on location of dirty files
Seb-MCaw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
""" | ||
Check updating a branch pin when 'config/*' files are tracked. | ||
""" | ||
|
||
|
||
import os | ||
import re | ||
import subprocess | ||
|
||
from drivers.alr import run_alr, alr_pin, init_local_crate | ||
from drivers.asserts import assert_match, assert_in_file, assert_not_substring | ||
from drivers.helpers import git_branch, git_commit_file, init_git_repo | ||
|
||
|
||
# Create crate yyy, with git tracking the 'config/*' files | ||
init_local_crate("yyy") | ||
yyy_path = os.getcwd() | ||
with open(".gitignore") as f: | ||
gitignore_content = f.read() | ||
gitignore_content = gitignore_content.replace("/config/\n", "") | ||
with open(".gitignore", "w") as f: | ||
f.write(gitignore_content) | ||
init_git_repo(".") | ||
default_branch = git_branch() | ||
os.chdir("..") | ||
|
||
# Create and build another crate, with yyy's default branch added as a pin | ||
init_local_crate() | ||
xxx_path = os.getcwd() | ||
alr_pin("yyy", url=f"git+file:{yyy_path}", branch=default_branch) | ||
run_alr("build") | ||
|
||
# Verify that the cached copy of yyy has a dirty repo (due to changes to the | ||
# 'config/*' files) | ||
cached_yyy_path = os.path.join(xxx_path, "alire", "cache", "pins", "yyy") | ||
os.chdir(cached_yyy_path) | ||
p = subprocess.run(["git", "status"], capture_output=True) | ||
p.check_returncode() | ||
assert_match(r".*modified:\s*config/yyy_config\.gpr", p.stdout.decode()) | ||
|
||
# Add commits to yyy's default branch, including a change to a file in 'config/' | ||
os.chdir(yyy_path) | ||
git_commit_file( | ||
"Change_config", "config/yyy_config.gpr", "This is a new addition\n", "a" | ||
) | ||
git_commit_file("Add_test_file", "test_file", "This is a new file\n") | ||
|
||
# Check that the dirty repo doesn't prevent updating the pin (subject to user | ||
# confirmation) | ||
os.chdir(xxx_path) | ||
p = run_alr("update") | ||
assert_match( | ||
( | ||
".*Do you want to discard local uncommitted changes in '" | ||
rf"{re.escape(cached_yyy_path)}'\?" | ||
".*These changes were probably generated by Alire, so select 'Yes' " | ||
r"unless you made them yourself\." | ||
), | ||
p.out | ||
) | ||
|
||
# Check that the update was successful | ||
assert_in_file(os.path.join(cached_yyy_path, "test_file"), "This is a new file") | ||
|
||
# Reset the cached clone by only one commit and repeat the above. This time the | ||
# update should work without user confirmation, as there will be no conflict | ||
# (only 'test_file' needs to be updated). | ||
os.chdir(cached_yyy_path) | ||
p = subprocess.run(["git", "reset", "--hard", "HEAD~"]).check_returncode() | ||
os.chdir(xxx_path) | ||
run_alr("build") | ||
os.chdir(cached_yyy_path) | ||
p = subprocess.run(["git", "status"], capture_output=True) | ||
p.check_returncode() | ||
assert_match(r".*modified:\s*config/yyy_config\.gpr", p.stdout.decode()) | ||
os.chdir(xxx_path) | ||
p = run_alr("update") | ||
assert_not_substring("Do you want to discard local uncommitted changes", p.out) | ||
assert_in_file(os.path.join(cached_yyy_path, "test_file"), "This is a new file") | ||
|
||
|
||
print('SUCCESS') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
driver: python-script | ||
indexes: | ||
compiler_only_index: {} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't feel comfortable with telling the user it is probably OK to go ahead. What about:
Print something like "The update will overwrite these changed files in pinned crate blah:" and the output of
git status
.If changes are confined to
alire/
orconfig/
, say something like "changes affect Alire autogenerated files that are safe to overwrite" and default to Yes.Else, say something like "changes affect user files, are you sure?" and default to No.
If detecting 2) is too complex, just say that changes within
alire
andconfig
are OK to ignore and to make sure there are no other changes.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My concern with going down this route was that the file location is only a rough heuristic for the source of the changes; changes made by
actions
like e.g. Alire'sversion_patcher
will be categorised as "user files", while conversely users might make manual changes to the files inconfig/
which would then be confidently asserted as "safe to overwrite".In particular, defaulting to
No
means thatalr -n update
will fail whenactions
change "user files", which may require workarounds in non-interactive use cases like CI pipelines.I'm happy to implement as requested, but just checking you've considered these drawbacks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Usually what we (I) have done in the past is always default to Yes when
--force
is applied, so we could do the same here.Editions inside
config
are normally overwritten (without warning in the normal use case!) anyway, so the only problem I can see here is having a disabled configuration but still usingconfig
for manual files, or extra files in there, which certainly could happen, as misguided as it sounds (to me)... We operate under the assumption thatconfig/*
is fair game, and we could narrow it even more to the actual files Alire is generating only. Still, it seems to me a corner case not meriting complicating life for the regular case, and the warning when interactive will happen anyway.For actions touching user files under version control, I normally would want to review those, no matter that I didn't do the edition manually (e.g., something like
version_patcher
), although I haven't encountered this situation in actual development (changes byversion_patcher
don't go into VC), so again to me the warning as suggested is legit.As for CI uses, I expect that's not the regular situation in which a user is editing several crates via pins for which changes are to be preserved. Again, I have not seen this happening (pins suggest a temporary situation anyway).
In the end, this has never happened to me, so if you encountered the situation, you may have a better grasp of the actual user expectations. We can also ping @Fabien-Chouteau for a third opinion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, that all sounds good. The only occasion I've encountered this is the linked issue, so the possibility of users making their own changes is entirely speculative.
I'll make the default
Yes
if--force
ed, and otherwise implement as suggested above.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sound like a good compromise to me 👍