Skip to main content

Don’t keep writing .venv to the .git/info/exclude file; once is fine

ID
af407fd
date
2023-12-12 10:58:09+00:00
author
Alex Chan <alex@alexwlchan.net>
parent
11d5438
message
Don't keep writing `.venv` to the .git/info/exclude file; once is fine
changed files
1 file, 8 additions, 1 deletion

Changed files

fish_functions/venv.fish (1566) → fish_functions/venv.fish (1812)

diff --git a/fish_functions/venv.fish b/fish_functions/venv.fish
index 2d0e234..40e8a81 100644
--- a/fish_functions/venv.fish
+++ b/fish_functions/venv.fish
@@ -7,8 +7,15 @@ function venv
     echo "Creating virtual environment in "(pwd)"/.venv"
     python3 -m venv .venv --upgrade-deps
 
+    # Append .venv to the Git exclude file, but only if it's not
+    # already there.
     if test -e .git
-        echo .venv >>.git/info/exclude
+        set exclude_file ".git/info/exclude"
+        set line_to_append ".venv"
+
+        if not grep -q -x $line_to_append $exclude_file
+            echo $line_to_append >> $exclude_file
+        end
     end
 
     source .venv/bin/activate.fish