-
-
Notifications
You must be signed in to change notification settings - Fork 227
fix(vcs): git checkout after clone must contains -- .
#2151
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
Conversation
… telling Git where to write out.
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.
Thanks for fixing this bug, @kamontat ! 🙏 Would you mind adding a test case?
|
@sisp I actually cannot reproduce on linux machine. The problem seem to occurred only on MacOS. Here I tried on gitpod (follow CONTRIBUTING.md). It checkout correctly. However, I do same thing on MacOS. It doesn't work. Because of this I don't think test will help anything as it always pass when test on linux machine. I added anyway tho. |
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 problem if the error only occurs on macOS, as our CI workflows run on macOS, Linux, and Windows. But it would be good to know whether the new test fails in our macOS CI workflow without the fix. Could you temporarily push only the test case without the fix to verify this? Afterwards, if the test fails, re-add the fix to check that it makes the test pass.
tests/test_vcs.py
Outdated
| @pytest.mark.impure | ||
| def test_local_dirty_clone() -> None: | ||
| tmp = clone("https://github.com/copier-org/autopretty.git") | ||
| assert tmp | ||
| assert Path(tmp, "copier.yml").exists() | ||
|
|
||
| with local.cwd(tmp): | ||
| Path("unknown.txt").write_text("hello world") | ||
| Path("README.md").write_text("override string!!") | ||
|
|
||
| with pytest.warns(DirtyLocalWarning): | ||
| local_tmp = clone(tmp) | ||
|
|
||
| assert local_tmp | ||
| assert Path(local_tmp, "unknown.txt").exists() | ||
| assert Path(local_tmp, "README.md").exists() | ||
| assert Path(local_tmp, "copier.yaml").exists() | ||
| shutil.rmtree(local_tmp, ignore_errors=True) | ||
|
|
||
|
|
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.
Instead of cloning a remote repo, which makes the test impure, could you build a local repo instead? For example something like this (untested):
def test_local_dirty_clone(tmp_path_factory: pytest.TempPathFactory) -> None:
src = map(tmp_path_factory.mktemp, ("src",))
build_file_tree({src / "foo.txt": "bar"})
git_save(src)
build_file_tree({src / "foo.txt": "baz", src / "hello.txt": "world"})
with pytest.warns(DirtyLocalWarning):
tmp = clone(src)
assert tmp
assert Path(tmp, "foo.txt").exists()
assert Path(tmp, "foo.txt").read_text() == "baz"
assert Path(tmp, "hello.txt").exists()
assert Path(tmp, "hello.txt").read_text() == "world"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.
@sisp I revert the fixes. Please trigger CI.
|
btw: those 2 commits were create from gitpod website so it not signed. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #2151 +/- ##
==========================================
- Coverage 97.91% 97.73% -0.19%
==========================================
Files 55 55
Lines 5949 6088 +139
==========================================
+ Hits 5825 5950 +125
- Misses 124 138 +14
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Odd, the test case is passing on CI macOS although the fix is commented out. So, the test case doesn't seem to reproduce the problem correctly. Does the test fail on your local macOS? |
|
@sisp I cannot find why, but when I run Here is example I ran on my local machine: Please ignore the error, I need to force to error so I can view print() result. The output directory from tests can be checkout correctly. However when I run copy command on dirty repository, It didn't copy template correctly. Which after I remove dirtiness, the template is back to correct again. Note: The red box is the print() output from _vcs#clone() function I added to verify if parameter is the same. #!/usr/bin/env bash
## script.sh /path/to/template
## Expected ls -la result to contains more than .git directory
set -e
INPUT="$1"
OUTPUT="$(mktemp -d)"
rm -rf $OUTPUT
set -x
git="/usr/bin/git"
$git clone --no-checkout "$INPUT" "$OUTPUT"
cd "$OUTPUT"
$git --git-dir=.git --work-tree=$INPUT add -A
$git --git-dir=.git --work-tree=$INPUT commit -m "Copier automated commit for draft changes" --no-verify --no-gpg-sign
$git checkout -f HEAD
ls -laNot sure if matter or not, but I have 2 git installed on my machine which I tested both of them have same issue. |
|
@sisp Do you need any help from me? I would love get this merge because I have to manually update copier code every time I install it. |
|
@kamontat Sorry for the delay. I was hoping we'd find a way to test this on the macOS runner. I find it a little suspicious why running the Copier CLI is producing this error for you while the test isn't. 🤔 In the test suite, we're configuring an isolated Git config to avoid side effects from the global/system Git config. I wonder whether this might explain the difference on your machine. Not sure whether the test suite will run properly, but could you try commenting out the |
Signed-off-by: Kamontat Chantrachirathumrong <[email protected]>
|
@sisp You right, now I able to reproduce failed test when |
|
Tests on macOS and Windows are failing now – great! 🎉 Thanks for figuring this out! 🙇 You can enable the fix now, and when the tests pass, we can merge it. |
|
@sisp Applied hopefully the ci will pass. Thank you for your help. |
|
Now, several other tests are failing. 🤔 |
Any suggestion? |
|
How about disabling |
|
@sisp I need So it will be...
|
|
Not sure if we're talking about the same approach – I might have expressed my suggestion badly. This is what I meant: We could disable Line 190 in 1e16b65
like this: _clone()
+git("-C", location, "config", "--local", "core.fsmonitor", "false")Thinking about it some more, perhaps it might be even better to disable -git("checkout", "-f", ref or "HEAD")
+git("-c", "core.fsmonitor=false", "checkout", "-f", ref or "HEAD")WDYT? |
|
@sisp Oh, I see. I updated code to overrides |
Signed-off-by: Kamontat Chantrachirathumrong <[email protected]>
|
Looks like this is working. 👍 Could you add an inline comment above that line with a link to this issue, so we'll remember why the |
Signed-off-by: Kamontat Chantrachirathumrong <[email protected]>
@sisp Added |
Signed-off-by: Kamontat Chantrachirathumrong <[email protected]>
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.
Thanks for discovering and fixing this bug, @kamontat! 🙏 I'm glad we could pin down the root cause, find a proper fix, and have it properly tested to avoid regression in the future. 🎉
Without
-- .on the end cause git to not checkout latest changes from .git directory.[fixes #1887]