|
5 | 5 |
|
6 | 6 | "github.com/github/gh-stack/internal/config" |
7 | 7 | "github.com/github/gh-stack/internal/git" |
8 | | - "github.com/github/gh-stack/internal/stack" |
9 | 8 | "github.com/spf13/cobra" |
10 | 9 | ) |
11 | 10 |
|
@@ -60,10 +59,12 @@ func BottomCmd(cfg *config.Config) *cobra.Command { |
60 | 59 | } |
61 | 60 |
|
62 | 61 | func runNavigate(cfg *config.Config, delta int) error { |
63 | | - s, currentBranch, err := loadCurrentStack(cfg) |
| 62 | + result, err := loadStack(cfg, "") |
64 | 63 | if err != nil { |
65 | 64 | return nil |
66 | 65 | } |
| 66 | + s := result.Stack |
| 67 | + currentBranch := result.CurrentBranch |
67 | 68 |
|
68 | 69 | idx := s.IndexOf(currentBranch) |
69 | 70 | if idx < 0 { |
@@ -181,11 +182,12 @@ func runNavigate(cfg *config.Config, delta int) error { |
181 | 182 | } |
182 | 183 |
|
183 | 184 | func runNavigateToEnd(cfg *config.Config, top bool) error { |
184 | | - s, currentBranch, err := loadCurrentStack(cfg) |
| 185 | + result, err := loadStack(cfg, "") |
185 | 186 | if err != nil { |
186 | | - cfg.Errorf("failed to load current stack: %s", err) |
187 | 187 | return nil |
188 | 188 | } |
| 189 | + s := result.Stack |
| 190 | + currentBranch := result.CurrentBranch |
189 | 191 |
|
190 | 192 | if len(s.Branches) == 0 { |
191 | 193 | cfg.Errorf("stack has no branches") |
@@ -226,51 +228,6 @@ func runNavigateToEnd(cfg *config.Config, top bool) error { |
226 | 228 | return nil |
227 | 229 | } |
228 | 230 |
|
229 | | -func loadCurrentStack(cfg *config.Config) (*stack.Stack, string, error) { |
230 | | - gitDir, err := git.GitDir() |
231 | | - if err != nil { |
232 | | - errMsg := "not a git repository" |
233 | | - cfg.Errorf("%s", errMsg) |
234 | | - return nil, "", fmt.Errorf("%s", errMsg) |
235 | | - } |
236 | | - |
237 | | - sf, err := stack.Load(gitDir) |
238 | | - if err != nil { |
239 | | - errMsg := fmt.Sprintf("failed to load stack state: %s", err) |
240 | | - cfg.Errorf("%s", errMsg) |
241 | | - return nil, "", fmt.Errorf("%s", errMsg) |
242 | | - } |
243 | | - |
244 | | - currentBranch, err := git.CurrentBranch() |
245 | | - if err != nil { |
246 | | - errMsg := fmt.Sprintf("failed to get current branch: %s", err) |
247 | | - cfg.Errorf("%s", errMsg) |
248 | | - return nil, "", fmt.Errorf("%s", errMsg) |
249 | | - } |
250 | | - |
251 | | - s, err := resolveStack(sf, currentBranch, cfg) |
252 | | - if err != nil { |
253 | | - cfg.Errorf("%s", err) |
254 | | - return nil, "", err |
255 | | - } |
256 | | - if s == nil { |
257 | | - errMsg := fmt.Sprintf("current branch %q is not part of a stack", currentBranch) |
258 | | - cfg.Errorf("current branch %q is not part of a stack", currentBranch) |
259 | | - cfg.Printf("Checkout an existing stack using %s or create a new stack using %s", cfg.ColorCyan("gh stack checkout"), cfg.ColorCyan("gh stack init")) |
260 | | - return nil, "", fmt.Errorf("%s", errMsg) |
261 | | - } |
262 | | - |
263 | | - // Re-read current branch in case disambiguation caused a checkout |
264 | | - currentBranch, err = git.CurrentBranch() |
265 | | - if err != nil { |
266 | | - errMsg := fmt.Sprintf("failed to get current branch: %s", err) |
267 | | - cfg.Errorf("%s", errMsg) |
268 | | - return nil, "", fmt.Errorf("%s", errMsg) |
269 | | - } |
270 | | - |
271 | | - return s, currentBranch, nil |
272 | | -} |
273 | | - |
274 | 231 | func plural(n int, singular, pluralForm string) string { |
275 | 232 | if n == 1 { |
276 | 233 | return singular |
|
0 commit comments