|
6 | 6 | "os" |
7 | 7 | "os/signal" |
8 | 8 | "os/user" |
| 9 | + "path/filepath" |
9 | 10 | "strings" |
10 | 11 | "syscall" |
11 | 12 | "time" |
@@ -74,6 +75,9 @@ const ( |
74 | 75 | _partVcsStgTop = "vcs_git_stg_top" |
75 | 76 | _partVcsStgDirty = "vcs_git_stg_dirty" |
76 | 77 |
|
| 78 | + _partVcsGitRebaseOp = "vcs_git_rebase_op" |
| 79 | + _partVcsGitRebaseLeft = "vcs_git_rebase_op_left" |
| 80 | + |
77 | 81 | _partVcsGitIdxTotal = "vcs_git_idx_total" |
78 | 82 | _partVcsGitIdxIncluded = "vcs_git_idx_incl" |
79 | 83 | _partVcsGitIdxExcluded = "vcs_git_idx_excl" |
@@ -273,24 +277,43 @@ func cmdQueryRun(_ *cobra.Command, _ []string) error { |
273 | 277 | printPart(_partVcs, "git") |
274 | 278 | } else { |
275 | 279 | return nil |
| 280 | + |
276 | 281 | } |
277 | 282 |
|
| 283 | + gitDir, _ := stringExec("git", "rev-parse", "--path-format=absolute", "--git-dir") |
| 284 | + |
278 | 285 | subTasks.Go(func(ctx context.Context) error { |
279 | | - if branch, err := stringExec("git", "branch", "--show-current"); err == nil { |
280 | | - branch = trim(branch) |
281 | | - if len(branch) > 0 { |
282 | | - printPart(_partVcsBranch, trim(branch)) |
283 | | - return nil |
| 286 | + |
| 287 | + |
| 288 | + |
| 289 | + headRef := "" |
| 290 | + if cherryHeadB, _ := os.ReadFile(filepath.Join(gitDir, "CHERRY_PICK_HEAD")); len(cherryHeadB) > 0 { |
| 291 | + headRef = trim(string(cherryHeadB)) |
| 292 | + printPart(_partVcsGitRebaseOp, "cherry") |
| 293 | + } else if mergeHeadB, _ := os.ReadFile(filepath.Join(gitDir, "MERGE_HEAD")); len(mergeHeadB) > 0 { |
| 294 | + headRef = trim(string(mergeHeadB)) |
| 295 | + printPart(_partVcsGitRebaseOp, "merge") |
| 296 | + } else if rebaseHeadB, _ := os.ReadFile(filepath.Join(gitDir, "rebase-merge", "orig-head")); len(rebaseHeadB) > 0 { |
| 297 | + headRef = trim(string(rebaseHeadB)) |
| 298 | + printPart(_partVcsGitRebaseOp, "rebase") |
| 299 | + |
| 300 | + actionsLeftB, _ := os.ReadFile(filepath.Join(gitDir, "rebase-merge", "git-rebase-todo")) |
| 301 | + actionsLeft := trim(string(actionsLeftB)) |
| 302 | + if len(actionsLeftB) == 0 { |
| 303 | + printPart(_partVcsGitRebaseLeft, 1) |
| 304 | + } else { |
| 305 | + printPart(_partVcsGitRebaseLeft, len(strings.Split(string(actionsLeft), "\n"))+1) |
284 | 306 | } |
285 | 307 | } |
286 | 308 |
|
287 | | - if branch, err := stringExec("git", "name-rev", "--name-only", "HEAD"); err == nil { |
288 | | - branch = trim(branch) |
289 | | - if len(branch) > 0 { |
290 | | - printPart(_partVcsBranch, trim(branch)) |
291 | | - return nil |
292 | | - } |
| 309 | + branch := "" |
| 310 | + |
| 311 | + if len(headRef) != 0 { |
| 312 | + branch, _ = stringExec("git", "name-rev", "--name-only", headRef) |
| 313 | + } else { |
| 314 | + branch, _ = stringExec("git", "branch", "--show-current") |
293 | 315 | } |
| 316 | + printPart(_partVcsBranch, branch) |
294 | 317 |
|
295 | 318 | return nil |
296 | 319 | }) |
|
0 commit comments