diff options
author | Kirill Bolashev <111061261+kbolashev@users.noreply.github.com> | 2023-03-16 18:03:04 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-16 11:03:04 -0500 |
commit | 49389456687a923c1809df8d6eb5ce72c30404f0 (patch) | |
tree | c17a898f90dc178df8234ea95476cee9e498a650 /modules | |
parent | 39d3711f3036db42d7ddf73dbdb125be611bcbba (diff) | |
download | gitea-49389456687a923c1809df8d6eb5ce72c30404f0.tar.gz gitea-49389456687a923c1809df8d6eb5ce72c30404f0.zip |
Handle files starting with colons in WalkGitLog (#22935)
Currently gitea shows no commit information for files starting with a
colon.
[I set up a minimal repro repository that reproduces this error once
it's migrated on gitea](https://github.com/kbolashev/colon-test)
<img width="1209" alt="image"
src="https://user-images.githubusercontent.com/111061261/219326625-0e6d3a86-8b58-4d67-bc24-8a78963f36b9.png">
This is happening because the filenames piped to the `git log` command
are written as is, and it doesn't work when you have a colon at the
start of the filename, and you need to escape it.
You can test it locally, if you do
```
mkdir repo
git init
touch :file
git add . && git commit -m "Add file with colon"
git log -- :file
```
git log returns nothing. However, if you do `git log -- "\:file"`, it
will show the commit with the file change.
This PR escapes the starting colons in paths in the `LogNameStatusRepo`
function, making gitea return commit info about the file with the bad
filename.
<img width="1209" alt="image"
src="https://user-images.githubusercontent.com/111061261/219328299-46451246-4006-45e3-89b1-c244635ded23.png">
This error shows up only with files starting with colon, anywhere else
in filename is ok. Dashes at the beginning also seem to be working.
I don't know gitea internals well enough to know where else this error
can pop up, so I'm keeping this PR small as suggested by your
contributor guide
Diffstat (limited to 'modules')
-rw-r--r-- | modules/git/log_name_status.go | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/modules/git/log_name_status.go b/modules/git/log_name_status.go index fe3b6598d7..70f6ef9dbb 100644 --- a/modules/git/log_name_status.go +++ b/modules/git/log_name_status.go @@ -56,6 +56,10 @@ func LogNameStatusRepo(ctx context.Context, repository, head, treepath string, p } else if treepath != "" { files = append(files, treepath) } + // Use the :(literal) pathspec magic to handle edge cases with files named like ":file.txt" or "*.jpg" + for i, file := range files { + files[i] = ":(literal)" + file + } cmd.AddDashesAndList(files...) go func() { |