| 1142 | } |
| 1143 | |
| 1144 | func listDirAllFilesViaGitForHost(owner, repo, ref, dirPath, host string) ([]string, error) { |
| 1145 | remoteLog.Printf("Git fallback for listing all dir files: %s/%s@%s (path: %s)", owner, repo, ref, dirPath) |
| 1146 | |
| 1147 | tmpDir, err := getOrCreateListRepoClone(owner, repo, ref, host) |
| 1148 | if err != nil { |
| 1149 | return nil, err |
| 1150 | } |
| 1151 | |
| 1152 | lsTreeCmd := exec.Command("git", "-C", tmpDir, "ls-tree", "-r", "--name-only", "HEAD", dirPath+"/") |
| 1153 | lsTreeOutput, err := lsTreeCmd.CombinedOutput() |
| 1154 | if err != nil { |
| 1155 | remoteLog.Printf("Failed to list dir files: %s", string(lsTreeOutput)) |
| 1156 | return nil, fmt.Errorf("failed to list dir files: %w", err) |
| 1157 | } |
| 1158 | |
| 1159 | lines := strings.Split(strings.TrimSpace(string(lsTreeOutput)), "\n") |
| 1160 | var files []string |
| 1161 | for _, line := range lines { |
| 1162 | line = strings.TrimSpace(line) |
| 1163 | if line == "" { |
| 1164 | continue |
| 1165 | } |
| 1166 | // Only include direct children (no additional path separator after dirPath/) |
| 1167 | afterDirPath := strings.TrimPrefix(line, dirPath+"/") |
| 1168 | if !strings.Contains(afterDirPath, "/") && afterDirPath != "" { |
| 1169 | files = append(files, line) |
| 1170 | } |
| 1171 | } |
| 1172 | |
| 1173 | remoteLog.Printf("Found %d files in dir via git for %s/%s@%s (path: %s)", len(files), owner, repo, ref, dirPath) |
| 1174 | return files, nil |
| 1175 | } |
| 1176 | |
| 1177 | // listDirAllFilesViaPublicAPI lists files in a directory using an unauthenticated |
| 1178 | // call to the public GitHub API. Used as a last-resort fallback when both |