git » git-arr » commit 736d8be

Fix symlink writing when the second branch has no new commits

author Alberto Bertogli
2025-07-14 00:42:37 UTC
committer Alberto Bertogli
2025-07-14 00:46:14 UTC
parent 107b149b8d6bacd62a7290c4e1de55e280e861b6

Fix symlink writing when the second branch has no new commits

In commit 52862dd6cddabb0d0f8137a0518406e9c8dfd855 we introduced a bug:
if a branch contains no _new_ commits (meaning we already saw them when
processing a previous branch), then we assume it has zero commits and we
don't generate a commit index.

That is a bug, since we need to generate the commit index regardless.

It would manifest as an exception when creating the index.html symlink:

```
.out//r/git-arr/b/main/index.html -> 0.html
Traceback (most recent call last):
  File "/home/alb/devel/git-arr/git-arr/./git-arr", line 586, in <module>
    main()
    ~~~~^^
  File "/home/alb/devel/git-arr/git-arr/./git-arr", line 580, in main
    generate(output=opts.output, only=opts.only)
    ~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/alb/devel/git-arr/git-arr/./git-arr", line 520, in generate
    link(
    ~~~~^
        from_path="r/%s/b/%s/index.html" % (r.name, bn),
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        to_path="0.html",
        ^^^^^^^^^^^^^^^^^
    )
    ^
  File "/home/alb/devel/git-arr/git-arr/./git-arr", line 401, in link
    os.symlink(to_path, from_path)
    ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: '0.html' -> '.out//r/git-arr/b/main/index.html'
```

This patch fixes the bug by correctly counting the commits, regardless of
whether they are written or skipped.

git-arr +1 -1

diff --git a/git-arr b/git-arr
index 70bffd4..f89aa74 100755
--- a/git-arr
+++ b/git-arr
@@ -473,6 +473,7 @@ def generate(output: str, only=None):
                 limit=r.info.commits_per_page * r.info.max_pages,
             )
             for cid in commit_ids:
+                commit_count += 1
                 if cid in commits_written:
                     continue
                 commits_written.add(cid)
@@ -484,7 +485,6 @@ def generate(output: str, only=None):
                     write_to(
                         "r/%s/c/%s.patch" % (r.name, cid), patch, (r, cid)
                     )
-                commit_count += 1
 
             # To avoid regenerating files that have not changed, we will
             # instruct write_to() to set their mtime to the branch's committer