From 023a48227ae40a122003cd71fe99a51af2bbf559 Mon Sep 17 00:00:00 2001 From: Alisher Nurmanov Date: Wed, 10 Sep 2025 10:18:12 +0500 Subject: [PATCH] bug/`file exists on disk but not in HEAD` on `qs u` --- gitcmds/gitcmds.go | 5 +++-- internal/systrun/impl.go | 22 +++++++++++++++++----- sys_test.go | 6 +++--- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/gitcmds/gitcmds.go b/gitcmds/gitcmds.go index 79945bb..2e9e408 100644 --- a/gitcmds/gitcmds.go +++ b/gitcmds/gitcmds.go @@ -347,9 +347,10 @@ func getFileSizeFromHEAD(wd, gitDir, fileName string) (int64, error) { if err != nil { return 0, fmt.Errorf("failed to compute relative path from repo root to working dir: %w", err) } - + // workaround for Windows paths + filePath := strings.ReplaceAll(filepath.Join(relativePath, fileName), "\\", "/") stdout, stderr, err := new(exec.PipedExec). - Command(git, "cat-file", "-s", fmt.Sprintf("HEAD:%s", filepath.Join(relativePath, fileName))). + Command(git, "cat-file", "-s", fmt.Sprintf("HEAD:%s", filePath)). WorkingDir(wd). RunToStrings() if err != nil { diff --git a/internal/systrun/impl.go b/internal/systrun/impl.go index f400a90..1c3c712 100644 --- a/internal/systrun/impl.go +++ b/internal/systrun/impl.go @@ -11,6 +11,7 @@ import ( "os" "os/exec" "path/filepath" + "strconv" "strings" "sync" "time" @@ -1101,24 +1102,35 @@ func (st *SystemTest) setSyncState( // - idFiles: list of file IDs to create (e.g., 1, 2, 3 for 1.txt, 2.txt, 3.txt) func commitFiles(wd string, needToCommit bool, headerOfFiles string, idFiles ...int) error { // Create 3 commits with different files - for _, id := range idFiles { + for i, id := range idFiles { fileName := fmt.Sprintf("%d.txt", id) - filePath := filepath.Join(wd, fileName) + // Create nested directories for each file based on its index + pathParts := make([]string, 0, i+3) + pathParts = append(pathParts, wd) + for j := 0; j <= i; j++ { + pathParts = append(pathParts, strconv.Itoa(j)) + } + pathParts = append(pathParts, fileName) + filePath := filepath.Join(pathParts...) + fileContent := strings.Builder{} if headerOfFiles != "" { fileContent.WriteString(headerOfFiles + "\n") } fileContent.WriteString(fmt.Sprintf("Content of file %d", id)) - + dirName := filepath.Dir(filePath) // Create the file + if err := os.MkdirAll(dirName, cloneRepoDirPerm); err != nil { + return fmt.Errorf("failed to create directories for %s: %w", fileName, err) + } if err := os.WriteFile(filePath, []byte(fileContent.String()), commitFilePerm); err != nil { return fmt.Errorf("failed to create file %s: %w", fileName, err) } // Add file to git - addCmd := exec.Command(git, changeDirFlag, wd, "add", fileName) + addCmd := exec.Command(git, changeDirFlag, wd, "add", filePath) if err := addCmd.Run(); err != nil { - return fmt.Errorf("failed to git add %s: %w", fileName, err) + return fmt.Errorf("failed to git add %s: %w", filePath, err) } if needToCommit { diff --git a/sys_test.go b/sys_test.go index 9756c6d..d5dc107 100644 --- a/sys_test.go +++ b/sys_test.go @@ -726,9 +726,9 @@ func TestQS(t *testing.T) { "Summary:", "Total positive delta: ", "Largest positive delta: ", - "1.txt", - "2.txt", - "3.txt", + "0/1.txt", + "0/1/2.txt", + "0/1/2/3.txt", }, NeedCollaboration: true, }