aboutsummaryrefslogtreecommitdiffstats
path: root/commands/patch
diff options
context:
space:
mode:
authorKoni Marti <koni.marti@gmail.com>2023-11-24 16:03:10 +0100
committerRobin Jarry <robin@jarry.cc>2023-12-30 15:42:09 +0100
commitf8c9e7fff564667700c3dbc239d55db8fcd032a6 (patch)
tree2fbe2e87ed8e713e119aaadf0f2e317fb01d90fc /commands/patch
parentcfcab6c5c883a08afa3a56c11e4f48d9725be2a0 (diff)
downloadaerc-f8c9e7fff564667700c3dbc239d55db8fcd032a6.tar.gz
patch: implement worktree support
Implement worktree support for the patch management. Use ":patch apply -w <commit-ish> <tag>" to create a new worktree and apply the selected messages to it. The worktree is linked to repo in the current project. Internally, the worktree is stored as a new project. When this project is deleted with ":patch delete", the underlying linked worktree is removed as well. ":patch list" shows when a project is a worktree and to what project it is linked to. Worktrees enable the users to create a new copy of the repo at a given commit and apply patches without interrupting the current work in the base repo. Signed-off-by: Koni Marti <koni.marti@gmail.com> Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'commands/patch')
-rw-r--r--commands/patch/apply.go34
1 files changed, 23 insertions, 11 deletions
diff --git a/commands/patch/apply.go b/commands/patch/apply.go
index f9c74ec3..2806b7d1 100644
--- a/commands/patch/apply.go
+++ b/commands/patch/apply.go
@@ -15,8 +15,9 @@ import (
)
type Apply struct {
- Cmd string `opt:"-c"`
- Tag string `opt:"tag" required:"true" complete:"CompleteTag"`
+ Cmd string `opt:"-c"`
+ Worktree string `opt:"-w"`
+ Tag string `opt:"tag" required:"true" complete:"CompleteTag"`
}
func init() {
@@ -68,6 +69,8 @@ func (*Apply) CompleteTag(arg string) []string {
func (a Apply) Execute(args []string) error {
patch := a.Tag
+ worktree := a.Worktree
+ applyCmd := a.Cmd
m := pama.New()
p, err := m.CurrentProject()
@@ -76,6 +79,17 @@ func (a Apply) Execute(args []string) error {
}
log.Tracef("Current project: %v", p)
+ if worktree != "" {
+ p, err = m.CreateWorktree(p, worktree, patch)
+ if err != nil {
+ return err
+ }
+ err = m.SwitchProject(p.Name)
+ if err != nil {
+ log.Warnf("could not switch to worktree project: %v", err)
+ }
+ }
+
if models.Commits(p.Commits).HasTag(patch) {
return fmt.Errorf("Patch name '%s' already exists.", patch)
}
@@ -91,19 +105,17 @@ func (a Apply) Execute(args []string) error {
}
log.Tracef("HEAD commit before: %s", commit)
- applyCmd, err := m.ApplyCmd(p)
- if err != nil {
- return err
- }
-
- if a.Cmd != "" {
- applyCmd = a.Cmd
+ if applyCmd != "" {
rootFmt := "%r"
if strings.Contains(applyCmd, rootFmt) {
applyCmd = strings.ReplaceAll(applyCmd, rootFmt, p.Root)
}
- log.Infof("overwrite apply cmd by '%s'",
- applyCmd)
+ log.Infof("use custom apply command: %s", applyCmd)
+ } else {
+ applyCmd, err = m.ApplyCmd(p)
+ if err != nil {
+ return err
+ }
}
msgData := collectMessageData()