djlint / djLint

✨ HTML Template Linter and Formatter. Django - Jinja - Nunjucks - Handlebars - GoLang
https://djLint.com
GNU General Public License v3.0
686 stars 84 forks source link

[BUG] [Linter] djLint never finds files inside a Git worktree #790

Open mmulvanny opened 10 months ago

mmulvanny commented 10 months ago

System Info

Issue

When running inside a Git worktree, djLint always says No files to check!. In the same repository checked out conventionally, or if the worktree is copied outside its parent Git repository, it works as expected.

How To Reproduce

  1. Create a Git repository and commit an HTML file to a branch.
  2. Run djlint .. It works normally.
  3. Clone that repository with --bare.
  4. Run git worktree add <branch name> and cd into the branch.
  5. Run djlint .. Even though the file is in the current directory, it doen't find it.

Example console session

Success in conventional repository:

(venv) michael@aquinas /tmp $ git init repo
Initialized empty Git repository in /tmp/repo/.git/
(venv) michael@aquinas /tmp $ cd repo/
(venv) michael@aquinas /tmp/repo $ echo '<HTML>' > file.html
(venv) michael@aquinas /tmp/repo $ git add file.html 
(venv) michael@aquinas /tmp/repo $ git commit -m 'Add file'
[master (root-commit) c3aadcb] Add file
 1 file changed, 1 insertion(+)
 create mode 100644 file.html
(venv) michael@aquinas /tmp/repo $ djlint ./

Linting 1/1 files ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 00:00    

file.html
─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
H005 1:0 Html tag should have lang attribute. <HTML>
H007 1:0 <!DOCTYPE ... > should be present before the html tag. <HTML
H025 1:0 Tag seems to be an orphan. <HTML>
H009 1:1 Tag names should be lowercase. HTML

Linted 1 file, found 4 errors.

Failure in worktree:

(venv) michael@aquinas /tmp/repo $ cd ..
(venv) michael@aquinas /tmp $ git clone repo --bare
Cloning into bare repository 'repo.git'...
done.
(venv) michael@aquinas /tmp $ cd repo.git/
(venv) michael@aquinas /tmp/repo.git $ git worktree add master
Preparing worktree (checking out 'master')
HEAD is now at c3aadcb Add file
(venv) michael@aquinas /tmp/repo.git $ cd master/
(venv) michael@aquinas /tmp/repo.git/master $ ls
file.html
(venv) michael@aquinas /tmp/repo.git/master $ cat file.html 
<HTML>
(venv) michael@aquinas /tmp/repo.git/master $ djlint ./
No files to check! 😢

Success if the worktree is copied outside:

(venv) michael@aquinas /tmp/repo.git/master $ cd ..
(venv) michael@aquinas /tmp/repo.git $ cp master/ -r ..
(venv) michael@aquinas /tmp/repo.git $ cd /tmp/master/
(venv) michael@aquinas /tmp/master $ djlint .

Linting 1/1 files ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 00:00    

file.html
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
H005 1:0 Html tag should have lang attribute. <HTML>
H007 1:0 <!DOCTYPE ... > should be present before the html tag. <HTML
H025 1:0 Tag seems to be an orphan. <HTML>
H009 1:1 Tag names should be lowercase. HTML

Linted 1 file, found 4 errors.

(venv) michael@aquinas /tmp/master $ 

Contents of .djlintrc/pyproject.toml [tool.djlint]

N/A, issue is reproducible on a fresh install in a nearly-blank repo.

welcome[bot] commented 10 months ago

Thanks for opening your first issue here!