Exec uses git to lookup the blame of a file, given the supplied options
(ctx context.Context, filePath string, options *Options)
| 166 | |
| 167 | // Exec uses git to lookup the blame of a file, given the supplied options |
| 168 | func Exec(ctx context.Context, filePath string, options *Options) (Result, error) { |
| 169 | gitPath, err := exec.LookPath("git") |
| 170 | if err != nil { |
| 171 | return nil, fmt.Errorf("could not find git: %w", err) |
| 172 | } |
| 173 | |
| 174 | args := options.argsFromOptions(filePath) |
| 175 | |
| 176 | cmd := exec.CommandContext(ctx, gitPath, args...) |
| 177 | cmd.Dir = options.Directory |
| 178 | |
| 179 | stdout, err := cmd.StdoutPipe() |
| 180 | if err != nil { |
| 181 | return nil, err |
| 182 | } |
| 183 | |
| 184 | if err := cmd.Start(); err != nil { |
| 185 | return nil, err |
| 186 | } |
| 187 | |
| 188 | res, err := parsePorcelain(stdout) |
| 189 | if err != nil { |
| 190 | return nil, err |
| 191 | } |
| 192 | |
| 193 | if err := cmd.Wait(); err != nil { |
| 194 | return nil, err |
| 195 | } |
| 196 | |
| 197 | return res, nil |
| 198 | } |
no test coverage detected