| 152 | } |
| 153 | |
| 154 | func GetRoot() (_ string, err error) { |
| 155 | defer func() { |
| 156 | if err != nil { |
| 157 | err = fmt.Errorf("failed to get Git root directory: %w", err) |
| 158 | } |
| 159 | }() |
| 160 | |
| 161 | ctx, cancel := context.WithCancel(context.Background()) |
| 162 | defer cancel() |
| 163 | |
| 164 | subprocess, err := cmd.RunRevParseTopLevel(ctx) |
| 165 | if err != nil { |
| 166 | return "", err |
| 167 | } |
| 168 | |
| 169 | root, err := subprocess.StdoutText() |
| 170 | if err != nil { |
| 171 | return "", err |
| 172 | } |
| 173 | |
| 174 | err = subprocess.Wait() |
| 175 | if err != nil { |
| 176 | return "", err |
| 177 | } |
| 178 | |
| 179 | return root, nil |
| 180 | } |
| 181 | |
| 182 | // Returns all paths in the working tree under the given pathspecs. |
| 183 | func WorkingTreeFiles(pathspecs []string) (_ map[string]bool, err error) { |