aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGiteabot <teabot@gitea.io>2024-04-22 21:55:01 +0800
committerGitHub <noreply@github.com>2024-04-22 13:55:01 +0000
commit706fc596a03c91893097c0237b67a3ae585edb6a (patch)
tree27520ce4b4ce79728aca2a825ee86fef8efa5acb
parent4aba4f8dc31fbd74c5f797b51c71b0bbda36af05 (diff)
downloadgitea-706fc596a03c91893097c0237b67a3ae585edb6a.tar.gz
gitea-706fc596a03c91893097c0237b67a3ae585edb6a.zip
Use correct hash for "git update-index" (#30626) (#30634)
Backport #30626 by @wxiaoguang Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
-rw-r--r--services/repository/files/temp_repo.go13
1 files changed, 8 insertions, 5 deletions
diff --git a/services/repository/files/temp_repo.go b/services/repository/files/temp_repo.go
index 9fcd335c55..d70b1e8d54 100644
--- a/services/repository/files/temp_repo.go
+++ b/services/repository/files/temp_repo.go
@@ -136,14 +136,18 @@ func (t *TemporaryUploadRepository) LsFiles(filenames ...string) ([]string, erro
// RemoveFilesFromIndex removes the given files from the index
func (t *TemporaryUploadRepository) RemoveFilesFromIndex(filenames ...string) error {
+ objFmt, err := t.gitRepo.GetObjectFormat()
+ if err != nil {
+ return fmt.Errorf("unable to get object format for temporary repo: %q, error: %w", t.repo.FullName(), err)
+ }
stdOut := new(bytes.Buffer)
stdErr := new(bytes.Buffer)
stdIn := new(bytes.Buffer)
for _, file := range filenames {
if file != "" {
- stdIn.WriteString("0 0000000000000000000000000000000000000000\t")
- stdIn.WriteString(file)
- stdIn.WriteByte('\000')
+ // man git-update-index: input syntax (1): mode SP sha1 TAB path
+ // mode=0 means "remove from index", then hash part "does not matter as long as it is well formatted."
+ _, _ = fmt.Fprintf(stdIn, "0 %s\t%s\x00", objFmt.EmptyObjectID(), file)
}
}
@@ -154,8 +158,7 @@ func (t *TemporaryUploadRepository) RemoveFilesFromIndex(filenames ...string) er
Stdout: stdOut,
Stderr: stdErr,
}); err != nil {
- log.Error("Unable to update-index for temporary repo: %s (%s) Error: %v\nstdout: %s\nstderr: %s", t.repo.FullName(), t.basePath, err, stdOut.String(), stdErr.String())
- return fmt.Errorf("Unable to update-index for temporary repo: %s Error: %w\nstdout: %s\nstderr: %s", t.repo.FullName(), err, stdOut.String(), stdErr.String())
+ return fmt.Errorf("unable to update-index for temporary repo: %q, error: %w\nstdout: %s\nstderr: %s", t.repo.FullName(), err, stdOut.String(), stdErr.String())
}
return nil
}