LoadRepo is a pre-run function that load the repository for use in a command
(env *Env)
| 16 | |
| 17 | // LoadRepo is a pre-run function that load the repository for use in a command |
| 18 | func LoadRepo(env *Env) func(*cobra.Command, []string) error { |
| 19 | return func(cmd *cobra.Command, args []string) error { |
| 20 | cwd, err := os.Getwd() |
| 21 | if err != nil { |
| 22 | return fmt.Errorf("unable to get the current working directory: %q", err) |
| 23 | } |
| 24 | |
| 25 | // Note: we are not loading clocks here because we assume that LoadRepo is only used |
| 26 | // when we don't manipulate entities, or as a child call of LoadBackend which will |
| 27 | // read all clocks anyway. |
| 28 | env.Repo, err = repository.OpenGoGitRepo(cwd, gitBugNamespace, nil) |
| 29 | if err == repository.ErrNotARepo { |
| 30 | return fmt.Errorf("%s must be run from within a git Repo", RootCommandName) |
| 31 | } |
| 32 | if err != nil { |
| 33 | return err |
| 34 | } |
| 35 | |
| 36 | return nil |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | // LoadRepoEnsureUser is the same as LoadRepo, but also ensure that the user has configured |
| 41 | // an identity. Use this pre-run function when an error after using the configured user won't |
no test coverage detected