Skip to content

cmd/git-go-patch: enhance git-go-patch with robust patch application and streamlined interactive rebase workflow#281

Open
gdams wants to merge 4 commits intomainfrom
dev/gadams/gitgopatch
Open

cmd/git-go-patch: enhance git-go-patch with robust patch application and streamlined interactive rebase workflow#281
gdams wants to merge 4 commits intomainfrom
dev/gadams/gitgopatch

Conversation

@gdams
Copy link
Copy Markdown
Member

@gdams gdams commented Jul 10, 2025

This PR addresses issue microsoft/go#750 by significantly improving the patch application process and adding a new interactive shell mode for rebase operations.

Key Features:

Enhanced Patch Application

  • Automatic 3-way merge fallback: When patches fail to apply cleanly, automatically tries git am -3 for better conflict resolution
  • One-by-one patch processing: Applies patches individually with clear feedback on which patches succeed/fail
  • Improved error reporting: Shows exactly which patches need manual resolution

Streamlined Interactive Rebase Workflow

  • New -shell flag: git go-patch rebase -shell opens an interactive terminal session in the submodule
  • Cross-platform shell support: Works on Windows (cmd.exe/PowerShell) and Unix (bash/zsh/etc.)
  • Smart prompt indicators: Updates PS1 (Unix) or PROMPT (Windows) to show "(git-go-patch)" mode
  • Exit code control: Use exit 1 to skip automatic extraction, exit 0 for normal flow
  • Automatic extraction: Runs git go-patch extract internally when shell exits successfully
  • Safety protections: Prevents nested sessions and detects ongoing git operations (rebase/merge/cherry-pick)

Workflow Transformation

Before (manual 6-step process):

git go-patch apply
cd submodule
git rebase -i <commit>
# [manual work]
cd ..
git go-patch extract

After (2-step guided process):

git go-patch apply
git go-patch rebase -shell
# Interactive session with automatic extraction

@gdams gdams requested a review from a team as a code owner July 10, 2025 11:31
@gdams gdams changed the title cmd/git-go-patch: add rebase-interactive command for streamlined work… cmd/git-go-patch: add rebase-interactive command for streamlined workflow Jul 10, 2025
…flow

Adds a new `git go-patch rebase-interactive` command that provides an
automated workflow for patch file editing. This addresses issue #750
by combining the manual steps of rebase and extract into a guided process.

Features:
- Opens interactive terminal in submodule directory (no manual cd needed)
- Modifies PS1 prompt to show "(git-go-patch)" mode indicator
- Automatically runs `git go-patch extract` when terminal exits
- Supports --skip-extract flag for manual control
- Sets GIT_GO_PATCH_INTERACTIVE=1 environment variable
- Provides clear instructions for VS Code integration (`code .`)

This streamlines the previous 6-step manual workflow:
1. git go-patch apply
2. cd submodule
3. git rebase -i <base>
4. [manual work]
5. cd ..
6. git go-patch extract

Into a 2-step guided process:
1. git go-patch apply
2. git go-patch rebase-interactive

The nested terminal approach avoids confusion with clear visual indicators
while enabling complex rebase operations and IDE integration.

Fixes microsoft/go#750
@gdams gdams force-pushed the dev/gadams/gitgopatch branch from d01fc29 to 5b237c6 Compare July 10, 2025 11:35
@gdams gdams requested a review from dagood July 10, 2025 11:41
@gdams
Copy link
Copy Markdown
Member Author

gdams commented Jul 10, 2025

CC @dagood, I was playing around with this the other day and nearly created an identical issue to yours, have a play around with this and let me know what you think

Copy link
Copy Markdown
Member

@dagood dagood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some suggestions, also this includes a binary file that needs to be cleaned up.

@gdams gdams changed the title cmd/git-go-patch: add rebase-interactive command for streamlined workflow cmd/git-go-patch: enhance git-go-patch with robust patch application and streamlined interactive rebase workflow Jul 14, 2025
@gdams
Copy link
Copy Markdown
Member Author

gdams commented Jul 14, 2025

@dagood updated PTAL

@gdams gdams requested a review from dagood July 14, 2025 11:27
@gdams
Copy link
Copy Markdown
Member Author

gdams commented Jul 21, 2025

@dagood updated PTAL

@gdams gdams requested a review from dagood July 21, 2025 16:31
}

fmt.Printf("\n%s=== Press Enter to continue ===%s\n", "\033[1;33m", "\033[0m") // Yellow text
_, _ = fmt.Scanln() // Wait for user to press Enter
Copy link
Copy Markdown
Member

@dagood dagood Jul 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I (slightly) preferred git go-patch shell rather than tacking this onto rebase, but wasn't sure why... now I realize I don't think it's always useful to immediately run a rebase. It seems like it would only make sense to rebase immediately if you're using edit/break and other rebase commands directly, but I rarely do that. I rebase after I've poked around and figured out what I want to do, and probably integrate some new commits back into the sequence of patches.

Or maybe I only have a new patch to add, no rebase at all.

Splitting it out simplifies each command and removes the reason to have this "just press enter" step.

git go-patch shell could accept git go-patch shell -rebase as a way to keep this functionality (which I could see being useful depending on what kind of patches you're doing), but in a more flexible way.

An -apply flag would also fit in, that way.

if userShell == "" {
userShell = "/bin/bash" // Default Unix shell
}
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

File issue about PowerShell support (on Windows and on Linux)?

The shell prompt is automatically updated to show `(git-go-patch)` to indicate you're in the interactive mode:
* Unix shells: Updates the `PS1` environment variable
* Windows Command Prompt: Updates the `PROMPT` environment variable
* Powershell is not currently supported
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also doesn't work if on Linux if using PROMPT_COMMAND because it overwrites PS1 all the time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants