checkWorkflowFileStatus checks if a workflow file has local modifications, staged changes, or unpushed commits
(workflowPath string)
| 549 | |
| 550 | // checkWorkflowFileStatus checks if a workflow file has local modifications, staged changes, or unpushed commits |
| 551 | func checkWorkflowFileStatus(workflowPath string) (*WorkflowFileStatus, error) { |
| 552 | gitLog.Printf("Checking status for workflow file: %s", workflowPath) |
| 553 | |
| 554 | status := &WorkflowFileStatus{} |
| 555 | |
| 556 | // Check if we're in a git repository |
| 557 | if !isGitRepo() { |
| 558 | gitLog.Print("Not in a git repository") |
| 559 | return status, nil |
| 560 | } |
| 561 | |
| 562 | // Get the absolute path relative to git root |
| 563 | gitRoot, err := gitutil.FindGitRoot() |
| 564 | if err != nil { |
| 565 | gitLog.Printf("Failed to find git root: %v", err) |
| 566 | return status, nil // Not in a git repository, return empty status |
| 567 | } |
| 568 | |
| 569 | // Make path relative to git root if it's absolute |
| 570 | var relPath string |
| 571 | if filepath.IsAbs(workflowPath) { |
| 572 | var err error |
| 573 | relPath, err = filepath.Rel(gitRoot, workflowPath) |
| 574 | if err != nil { |
| 575 | gitLog.Printf("Failed to make path relative: %v", err) |
| 576 | relPath = workflowPath |
| 577 | } |
| 578 | } else { |
| 579 | relPath = workflowPath |
| 580 | } |
| 581 | |
| 582 | gitLog.Printf("Checking git status for: %s", relPath) |
| 583 | |
| 584 | // Check for modified or staged changes using git status --porcelain |
| 585 | cmd := exec.Command("git", "-C", gitRoot, "status", "--porcelain", relPath) |
| 586 | output, err := cmd.Output() |
| 587 | if err != nil { |
| 588 | gitLog.Printf("Failed to check git status: %v", err) |
| 589 | return status, nil // Ignore error, return empty status |
| 590 | } |
| 591 | |
| 592 | statusOutput := string(output) // Don't trim - the leading space is significant! |
| 593 | if len(statusOutput) > 0 { |
| 594 | gitLog.Printf("Git status output: %q", statusOutput) |
| 595 | // Parse the status line (format: XY filename) |
| 596 | // X = index (staged) status, Y = working tree (unstaged) status |
| 597 | // The format is exactly 2 characters followed by a space and then the filename |
| 598 | if len(statusOutput) >= 2 { |
| 599 | stagedStatus := statusOutput[0] |
| 600 | unstagedStatus := statusOutput[1] |
| 601 | |
| 602 | // Check if file is staged (first character is not space or ?) |
| 603 | if stagedStatus != ' ' && stagedStatus != '?' { |
| 604 | status.IsStaged = true |
| 605 | gitLog.Print("File has staged changes") |
| 606 | } |
| 607 | |
| 608 | // Check if file is modified in working tree (second character is M or other modification indicators) |