klaussilveira / gitlist

An elegant and modern git repository viewer
https://gitlist.org/
BSD 3-Clause "New" or "Revised" License
2.92k stars 517 forks source link

Openening a file containing the name of a branch or tag throws a CommandException #929

Open ziebelje opened 1 year ago

ziebelje commented 1 year ago

Error: request.CRITICAL: Uncaught PHP Exception GitList\SCM\Exception\CommandException: "/usr/bin/git show ia:D/js/component/triage.js" at /data/www/gitlist/src/SCM/System/Git/CommandLine.php line 320 {"exception":"[object] (GitList\\SCM\\Exception\\CommandException(code: 0): /usr/bin/git show ia:D/js/component/triage.js at /data/www/gitlist/src/SCM/System/Git/CommandLine.php:320)"} []

I have a repository that contains a branch named "ia". When browsing HEAD on GitList, I open the file "js/component/text.js". Among other things, GitList generates and executes the following command to get the contents of the file:

/usr/bin/git show HEAD:js/component/text.js

This works fine. I now try to open the file "js/component/triage.js". Among other things, GitList generates and executes the following command to get the contents of the file:

/usr/bin/git show ia:D/js/component/triage.js

Clearly this is wrong. I traced this down to the Repository/Commitish.php constructor. Specifically, it is changing $this->hash to the name of the rev (a branch named "ia" in this case) and ultimately getting set incorrectly.

I don't fully understand the purpose of this code, but reproduced this issue on several filenames containing the string "ia" in them. Confirmed that removing this branch fixed the issue.