mirror of
https://github.com/nix-community/nix-direnv.git
synced 2025-12-19 07:21:18 +01:00
Merge pull request #271 from nix-community/empty_nixfile_fix
Don't track $nixfile if it is empty
This commit is contained in:
commit
32bf26a499
3 changed files with 24 additions and 8 deletions
7
direnvrc
7
direnvrc
|
|
@ -336,9 +336,10 @@ use_nix() {
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
# nixfile may be empty,
|
nix_direnv_watch_file "$HOME/.direnvrc" "$HOME/.config/direnv/direnvrc" ".envrc"
|
||||||
# but nix_direnv_watch_file checks for existence before adding to watches
|
if [ -f "$nixfile" ]; then
|
||||||
nix_direnv_watch_file "$HOME/.direnvrc" "$HOME/.config/direnv/direnvrc" .envrc "$nixfile"
|
nix_direnv_watch_file "$nixfile"
|
||||||
|
fi
|
||||||
|
|
||||||
local need_update=0
|
local need_update=0
|
||||||
local file=
|
local file=
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,11 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
from dataclasses import dataclass
|
|
||||||
import shutil
|
import shutil
|
||||||
|
import textwrap
|
||||||
|
from dataclasses import dataclass
|
||||||
|
from pathlib import Path
|
||||||
from tempfile import TemporaryDirectory
|
from tempfile import TemporaryDirectory
|
||||||
from typing import Iterator
|
from typing import Iterator
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
|
@ -21,12 +22,13 @@ class DirenvProject:
|
||||||
return self.dir / ".envrc"
|
return self.dir / ".envrc"
|
||||||
|
|
||||||
def setup_envrc(self, content: str) -> None:
|
def setup_envrc(self, content: str) -> None:
|
||||||
self.envrc.write_text(
|
text = textwrap.dedent(
|
||||||
f"""
|
f"""
|
||||||
source {self.nix_direnv}
|
source {self.nix_direnv}
|
||||||
{content}
|
{content}
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
self.envrc.write_text(text)
|
||||||
run(["direnv", "allow"], cwd=self.dir)
|
run(["direnv", "allow"], cwd=self.dir)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -33,5 +33,18 @@ def test_args(direnv_project: DirenvProject) -> None:
|
||||||
direnv_exec(direnv_project, "echo $SHOULD_BE_SET")
|
direnv_exec(direnv_project, "echo $SHOULD_BE_SET")
|
||||||
|
|
||||||
|
|
||||||
|
def test_no_files(direnv_project: DirenvProject) -> None:
|
||||||
|
direnv_project.setup_envrc("use nix -p hello")
|
||||||
|
out = run(
|
||||||
|
["direnv", "status"],
|
||||||
|
stderr=subprocess.PIPE,
|
||||||
|
stdout=subprocess.PIPE,
|
||||||
|
check=False,
|
||||||
|
cwd=direnv_project.dir,
|
||||||
|
)
|
||||||
|
assert out.returncode == 0
|
||||||
|
assert 'Loaded watch: "."' not in out.stdout
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue