| 68 | } |
| 69 | |
| 70 | func (r *Runner) LocalForRepository(ctx context.Context, repo string) (*Runner, error) { |
| 71 | for _, key := range []string{ |
| 72 | "GIT_DIR", "GIT_COMMON_DIR", "GIT_WORK_TREE", "GIT_IMPLICIT_WORK_TREE", "GIT_INDEX_FILE", |
| 73 | "GIT_OBJECT_DIRECTORY", "GIT_ALTERNATE_OBJECT_DIRECTORIES", "GIT_NAMESPACE", "GIT_CONFIG", "GIT_CONFIG_PARAMETERS", |
| 74 | "GIT_ATTR_SOURCE", "GIT_ATTR_NOSYSTEM", "GIT_LITERAL_PATHSPECS", "GIT_GLOB_PATHSPECS", "GIT_NOGLOB_PATHSPECS", "GIT_ICASE_PATHSPECS", |
| 75 | "GIT_REPLACE_REF_BASE", "GIT_NO_REPLACE_OBJECTS", "GIT_GRAFT_FILE", "GIT_SHALLOW_FILE", |
| 76 | } { |
| 77 | if _, set := os.LookupEnv(key); set { |
| 78 | return nil, &UnsupportedViewError{key} |
| 79 | } |
| 80 | } |
| 81 | if count := os.Getenv("GIT_CONFIG_COUNT"); count != "" && count != "0" { |
| 82 | return nil, &UnsupportedViewError{"GIT_CONFIG_COUNT"} |
| 83 | } |
| 84 | absolute, err := filepath.Abs(repo) |
| 85 | if err != nil { |
| 86 | return nil, err |
| 87 | } |
| 88 | if r != nil && r.configuredRepo == absolute { |
| 89 | return r, nil |
| 90 | } |
| 91 | local := &Runner{sem: r.LocalOnly().sem, localOnly: true, configuredRepo: absolute, configArgs: []string{"-c", "core.fsmonitor=false", "-c", "log.showSignature=false"}} |
| 92 | keys, err := local.Output(ctx, repo, "config", "--null", "--name-only", "--list") |
| 93 | if err != nil { |
| 94 | return nil, err |
| 95 | } |
| 96 | seen := map[string]bool{} |
| 97 | for key := range strings.SplitSeq(string(keys), "\x00") { |
| 98 | index := strings.LastIndexByte(key, '.') |
| 99 | if !strings.HasPrefix(key, "filter.") || index <= len("filter.") { |
| 100 | continue |
| 101 | } |
| 102 | driver := key[:index] |
| 103 | switch key[index+1:] { |
| 104 | case "process", "clean", "smudge": |
| 105 | default: |
| 106 | continue |
| 107 | } |
| 108 | if strings.ContainsAny(driver, "=\r\n") { |
| 109 | return nil, fmt.Errorf("unsupported Git filter configuration") |
| 110 | } |
| 111 | if !seen[driver] { |
| 112 | seen[driver] = true |
| 113 | for _, setting := range []string{".process=", ".clean=", ".smudge=", ".required=true"} { |
| 114 | local.configArgs = append(local.configArgs, "-c", driver+setting) |
| 115 | } |
| 116 | } |
| 117 | } |
| 118 | return local, nil |
| 119 | } |
| 120 | |
| 121 | func (r *Runner) command(ctx context.Context, repoDir string, args ...string) *exec.Cmd { |
| 122 | if len(r.configArgs) > 0 { |