Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions gitcmds/gitcmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
22 changes: 17 additions & 5 deletions internal/systrun/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"os"
"os/exec"
"path/filepath"
"strconv"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions sys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
Loading