Clean clean git repo.
(target, repoDir string)
| 316 | |
| 317 | // Clean clean git repo. |
| 318 | func Clean(target, repoDir string) error { |
| 319 | if !fileio.PathExists(repoDir) { |
| 320 | return errors.ErrDirNotExist |
| 321 | } |
| 322 | if !fileio.PathExists(filepath.Join(repoDir, ".git")) { |
| 323 | return errors.ErrNotGitDir |
| 324 | } |
| 325 | |
| 326 | var commands []string |
| 327 | commands = append(commands, "git reset --hard") |
| 328 | commands = append(commands, "git clean -ffdx") |
| 329 | |
| 330 | title := fmt.Sprintf("[clean %s]", target) |
| 331 | commandLine := strings.Join(commands, " && ") |
| 332 | executor := cmd.NewExecutor(title, commandLine) |
| 333 | executor.SetWorkDir(repoDir) |
| 334 | if output, err := executor.ExecuteOutputLive(); err != nil { |
| 335 | return fmt.Errorf("failed to clean '%s' -> %s -> %w", target, output, err) |
| 336 | } |
| 337 | |
| 338 | return nil |
| 339 | } |
| 340 | |
| 341 | // HardReset hard resets the repo to the given commit and cleans untracked files. |
| 342 | // If the commit is not available locally, it fetches from origin first. |
no test coverage detected