From c0aa72b053a42f7443d4293fa55b79addbdec1d1 Mon Sep 17 00:00:00 2001 From: KBolashev Date: Thu, 16 Feb 2023 11:29:04 +0200 Subject: [PATCH 1/2] Handle files with colons in WalkGitLog --- modules/git/log_name_status.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/modules/git/log_name_status.go b/modules/git/log_name_status.go index fe3b6598d7d8a..8f04884b57151 100644 --- a/modules/git/log_name_status.go +++ b/modules/git/log_name_status.go @@ -56,6 +56,12 @@ func LogNameStatusRepo(ctx context.Context, repository, head, treepath string, p } else if treepath != "" { files = append(files, treepath) } + // Escape colons at the start of filenames, because `git log -- :filename` returns nothing + for i, file := range files { + if strings.HasPrefix(file, ":") { + files[i] = "\\" + file + } + } cmd.AddDashesAndList(files...) go func() { From e5edcc1177ffab48cfcde0b87d837724ca7efe56 Mon Sep 17 00:00:00 2001 From: KBolashev Date: Sat, 18 Feb 2023 20:51:35 +0200 Subject: [PATCH 2/2] Change to use the :(literal) magic instead of escaping --- modules/git/log_name_status.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/modules/git/log_name_status.go b/modules/git/log_name_status.go index 8f04884b57151..70f6ef9dbb9e6 100644 --- a/modules/git/log_name_status.go +++ b/modules/git/log_name_status.go @@ -56,11 +56,9 @@ func LogNameStatusRepo(ctx context.Context, repository, head, treepath string, p } else if treepath != "" { files = append(files, treepath) } - // Escape colons at the start of filenames, because `git log -- :filename` returns nothing + // Use the :(literal) pathspec magic to handle edge cases with files named like ":file.txt" or "*.jpg" for i, file := range files { - if strings.HasPrefix(file, ":") { - files[i] = "\\" + file - } + files[i] = ":(literal)" + file } cmd.AddDashesAndList(files...)