Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@kamontat
Copy link
Contributor

@kamontat kamontat commented May 16, 2025

Without -- . on the end cause git to not checkout latest changes from .git directory.

CleanShot 2025-05-16 at 16 27 55@2x

[fixes #1887]

Copy link
Member

@sisp sisp left a 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?

@kamontat
Copy link
Contributor Author

@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.
CleanShot 2025-06-11 at 15 33 21

However, I do same thing on MacOS. It doesn't work.
CleanShot 2025-06-11 at 15 33 39

Because of this I don't think test will help anything as it always pass when test on linux machine. I added anyway tho.

@kamontat kamontat requested a review from sisp June 18, 2025 09:09
Copy link
Member

@sisp sisp left a 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.

Comment on lines 91 to 110
@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)


Copy link
Member

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"

Copy link
Contributor Author

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.

@kamontat
Copy link
Contributor Author

btw: those 2 commits were create from gitpod website so it not signed.

@codecov
Copy link

codecov bot commented Jun 21, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.73%. Comparing base (3770a4d) to head (6d5b1e8).
⚠️ Report is 154 commits behind head on master.

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     
Flag Coverage Δ
unittests 97.73% <100.00%> (-0.19%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sisp
Copy link
Member

sisp commented Jun 22, 2025

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?

@kamontat
Copy link
Contributor Author

kamontat commented Jun 22, 2025

@sisp I cannot find why, but when I run clone() from test it always passed. It's not the case when I execute copier copy command.

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.

CleanShot 2025-06-22 at 17 05 29

The output directory from tests can be checkout correctly.

CleanShot 2025-06-22 at 17 05 39

However when I run copy command on dirty repository, It didn't copy template correctly.

CleanShot 2025-06-22 at 17 05 45

Which after I remove dirtiness, the template is back to correct again.

CleanShot 2025-06-22 at 17 12 54

Note: The red box is the print() output from _vcs#clone() function I added to verify if parameter is the same.
Note 2: I never work with python before, so now I just stuck. It seem to be some misconfigure between test environment and real environment.
Note 3: I create bash script to simulate the checkout command here

#!/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 -la

Not sure if matter or not, but I have 2 git installed on my machine which I tested both of them have same issue.

CleanShot 2025-06-22 at 17 20 32

@kamontat
Copy link
Contributor Author

@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.

@sisp
Copy link
Member

sisp commented Jul 21, 2025

@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 default_gitconfig fixture and running only your added test case?

Signed-off-by: Kamontat Chantrachirathumrong <[email protected]>
@kamontat
Copy link
Contributor Author

@sisp You right, now I able to reproduce failed test when core.fsmonitor is set to true. If you re-run the tests, it should fail now.

@sisp
Copy link
Member

sisp commented Jul 23, 2025

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.

@kamontat
Copy link
Contributor Author

kamontat commented Jul 23, 2025

@sisp Applied hopefully the ci will pass. Thank you for your help.

@sisp
Copy link
Member

sisp commented Jul 23, 2025

Now, several other tests are failing. 🤔

@kamontat
Copy link
Contributor Author

Now, several other tests are failing. 🤔

Any suggestion?

@sisp
Copy link
Member

sisp commented Jul 23, 2025

How about disabling core.fsmonitor in the local config of the cloned repository? IIUC, this feature isn't important for our use of Git.

@kamontat
Copy link
Contributor Author

@sisp I need core.fsmonitor on some of my project as it significantly improve on performance.
Is it ok, if I implement try-then-fallback if repo is not clone correctly?

So it will be...

  • First then without --, then check
  • If check failed, try again with --; then check
  • If check failed again, then return error

@sisp
Copy link
Member

sisp commented Jul 23, 2025

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 core.fsmonitor in Copier's internal template repository clone after

_clone()

like this:

 _clone()
+git("-C", location, "config", "--local", "core.fsmonitor", "false")

Thinking about it some more, perhaps it might be even better to disable core.fsmonitor only for the git checkout call like this:

-git("checkout", "-f", ref or "HEAD")
+git("-c", "core.fsmonitor=false", "checkout", "-f", ref or "HEAD")

WDYT?

@kamontat
Copy link
Contributor Author

kamontat commented Jul 24, 2025

@sisp Oh, I see. I updated code to overrides core.fsmonitor to false on checkout command. Please rerun the test, thank you.

@sisp
Copy link
Member

sisp commented Jul 24, 2025

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 core.fsmonitor=false setting is used there? Then, I think we can merge this PR. 🎉

Signed-off-by: Kamontat Chantrachirathumrong <[email protected]>
@kamontat
Copy link
Contributor Author

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 core.fsmonitor=false setting is used there? Then, I think we can merge this PR. 🎉

@sisp Added

Signed-off-by: Kamontat Chantrachirathumrong <[email protected]>
Copy link
Member

@sisp sisp left a 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. 🎉

@sisp sisp merged commit ec19e44 into copier-org:master Jul 24, 2025
20 of 21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

copier copy didn't copy my uncommit file even though I added -r HEAD option

2 participants