Skip to content

Commit 1b9d699

Browse files
committed
File list for sparse-checkout must be prefix with /
Otherwise, they would match all files with the same name under subdirectories.
1 parent f67dd1b commit 1b9d699

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

models/pull.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
package models
66

77
import (
8+
"bufio"
9+
"bytes"
810
"fmt"
911
"io/ioutil"
1012
"os"
@@ -346,7 +348,14 @@ func getDiffTree(repoPath, baseBranch, headBranch string) (string, error) {
346348
if err != nil {
347349
return "", err
348350
}
349-
return list, nil
351+
352+
// Prefixing '/' for each entry, otherwise all files with the same name in subdirectories would be matched.
353+
out := bytes.Buffer{}
354+
scanner := bufio.NewScanner(strings.NewReader(list))
355+
for scanner.Scan() {
356+
fmt.Fprintf(&out, "/%s\n", scanner.Text())
357+
}
358+
return out.String(), nil
350359
}
351360

352361
// Merge merges pull request to base repository.

0 commit comments

Comments
 (0)