CanExecuteGitDiff checks if git diff can be executed in the current directory. It returns an error if the current directory is not a git repository or if git diff cannot be executed.
(ctx context.Context)
| 175 | // CanExecuteGitDiff checks if git diff can be executed in the current directory. |
| 176 | // It returns an error if the current directory is not a git repository or if git diff cannot be executed. |
| 177 | func (c *Command) CanExecuteGitDiff(ctx context.Context) error { |
| 178 | output, err := c.checkGitRepository(ctx).Output() |
| 179 | if err != nil { |
| 180 | return errors.New("not a git repository (or any of the parent directories)") |
| 181 | } |
| 182 | |
| 183 | if strings.TrimSpace(string(output)) != "true" { |
| 184 | return errors.New("not inside a git working tree") |
| 185 | } |
| 186 | |
| 187 | return nil |
| 188 | } |
| 189 | |
| 190 | // Diff compares the differences between two sets of data. |
| 191 | // It returns a string representing the differences and an error. |