Repository: fzakaria/nix-auto-follow

Issue:
Support git flake type
When checking an input like ``nixpkgs.url = "git+https://github.com/SuperSandro2000/nixpkgs.git?shallow=1&ref=nixos-unstable";`` the following error occurs:

```
Traceback (most recent call last):
  File "/nix/store/bw8y4yyjwlz01gvi50q2zzaaqwpg0iig-nix-auto-follow/bin/.auto-follow-wrapped", line 9, in <module>
    sys.exit(start())
             ^^^^^^^
  File "/nix/store/bw8y4yyjwlz01gvi50q2zzaaqwpg0iig-nix-auto-follow/lib/python3.11/site-packages/nix_auto_follow/cli.py", line 207, in start
    if not check_lock_file(LockFile.from_dict(flake_lock_json)):
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/bw8y4yyjwlz01gvi50q2zzaaqwpg0iig-nix-auto-follow/lib/python3.11/site-packages/nix_auto_follow/cli.py", line 116, in check_lock_file
    f"Please add '{key}.url = \"{flake_lock.nodes[ref].get_url()}\"' or '{other_key}.url = \"{flake_lock.nodes[other_ref].get_url()}'"  # noqa: E501
                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/bw8y4yyjwlz01gvi50q2zzaaqwpg0iig-nix-auto-follow/lib/python3.11/site-packages/nix_auto_follow/cli.py", line 60, in get_url
    raise ValueError(f"Unknown type {original['type']}")
ValueError: Unknown type git
```

Discussion:
@fzakaria: Thanks for the report.
Do you want to try the PR?

I wrote some tests so I feel pretty confident but you running it will be best signal.

Solution patch:
diff --git a/src/nix_auto_follow/cli.py b/src/nix_auto_follow/cli.py
index d07da12..7a353cb 100644
--- a/src/nix_auto_follow/cli.py
+++ b/src/nix_auto_follow/cli.py
@@ -3,6 +3,7 @@
 import sys
 from dataclasses import dataclass, field
 from typing import Any, TextIO
+from urllib.parse import urlencode
 
 
 @dataclass
@@ -48,6 +49,17 @@ def get_url(self) -> str:
         rev_or_ref = next((x for x in [rev, ref] if x), "")
 
         match original["type"]:
+            case "git":
+                base_url = f"git+{original['url']}"
+                filtered_params = {
+                    k: (1 if v is True else 0 if v is False else v)
+                    for k, v in original.items()
+                    if k in ["rev", "ref", "submodules", "shallow"]
+                    and v not in (None, "")
+                }
+                query_string = urlencode(filtered_params)
+                full_url = f"{base_url}?{query_string}" if query_string else base_url
+                return full_url
             case "github":
                 return f"github:{original['owner']}/{original['repo']}{rev_or_ref}"
             case "gitlab":


Test patch:
diff --git a/tests/test_cli.py b/tests/test_cli.py
index 1951b08..9ed657f 100644
--- a/tests/test_cli.py
+++ b/tests/test_cli.py
@@ -67,6 +67,54 @@
             ),
             "nixpkgs/nixos-unstable/23.11",
         ),
+        (
+            Node.from_dict(
+                {
+                    "original": {
+                        "type": "git",
+                        "url": "https://github.com/kaeeraa/ayugram-desktop",
+                    }
+                }
+            ),
+            "git+https://github.com/kaeeraa/ayugram-desktop",
+        ),
+        (
+            Node.from_dict(
+                {
+                    "original": {
+                        "type": "git",
+                        "submodules": True,
+                        "url": "https://github.com/kaeeraa/ayugram-desktop",
+                    }
+                }
+            ),
+            "git+https://github.com/kaeeraa/ayugram-desktop?submodules=1",
+        ),
+        (
+            Node.from_dict(
+                {
+                    "original": {
+                        "type": "git",
+                        "shallow": True,
+                        "url": "ssh://git@github.com/mslxl/scripts.git",
+                    }
+                }
+            ),
+            "git+ssh://git@github.com/mslxl/scripts.git?shallow=1",
+        ),
+        (
+            Node.from_dict(
+                {
+                    "original": {
+                        "type": "git",
+                        "ref": "main",
+                        "shallow": True,
+                        "url": "ssh://git@gitlab.com/akibahmed/sops-secrects.git",
+                    }
+                }
+            ),
+            "git+ssh://git@gitlab.com/akibahmed/sops-secrects.git?ref=main&shallow=1",
+        ),
     ],
 )
 def test_get_url_for_node(node: Node, expected_url: str) -> None: