Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,4 @@ go.work.sum

.idea

# generated result of aictx itself
output.txt

.claude

/build
64 changes: 37 additions & 27 deletions cmd/git-back/main.go
Original file line number Diff line number Diff line change
@@ -1,44 +1,54 @@
package main

import (
"fmt"
"context"
"os"
"runtime/debug"
"os/signal"
"syscall"

"github.com/amberpixels/git-undo/cmd/shared"
"github.com/amberpixels/git-undo/internal/app"
"github.com/urfave/cli/v3"
)

// version is set by the build ldflags
// The default value is "dev+dirty" but it should never be used. In success path, it's always overwritten.
var version = "dev+dirty"
var versionSource = "hardcoded"

func main() {
var verbose, dryRun bool
for _, arg := range os.Args[1:] {
if arg == "-v" || arg == "--verbose" {
verbose = true
}
if arg == "--dry-run" {
dryRun = true
}
}
const (
appNameGitBack = "git-back"
)

// When running binary that was installed via `go install`, here we'll get the proper version
if bi, ok := debug.ReadBuildInfo(); ok && bi.Main.Version != "" {
version = bi.Main.Version
func main() {
// Create a context that can be cancelled with Ctrl+C
ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
defer cancel()

version, versionSource = app.HandleAppVersion(version, versionSource)

cmd := &cli.Command{
Name: appNameGitBack,
Usage: "Navigate back through git checkout/switch operations",
Flags: shared.CommonFlags(),
Action: func(ctx context.Context, c *cli.Command) error {
a := app.NewAppGitBack(version, versionSource)

if c.Bool("version") {
return a.HandleVersion(c.Bool("verbose"))
}

return a.Run(ctx, app.RunOptions{
Verbose: c.Bool("verbose"),
DryRun: c.Bool("dry-run"),
HookCommand: c.String("hook"),
ShowLog: c.Bool("log"),
Args: c.Args().Slice(),
})
},
}
application := app.NewAppGiBack(version, verbose, dryRun)

if err := application.Run(os.Args[1:]); err != nil {
_, _ = fmt.Fprintln(os.Stderr, redColor+appNameGitBack+" ❌: "+grayColor+err.Error()+resetColor)
os.Exit(1)
if err := cmd.Run(ctx, os.Args); err != nil {
app.HandleError(appNameGitBack, err)
}
}

const (
grayColor = "\033[90m"
redColor = "\033[31m"
resetColor = "\033[0m"

appNameGitBack = "git-back"
)
68 changes: 41 additions & 27 deletions cmd/git-undo/main.go
Original file line number Diff line number Diff line change
@@ -1,44 +1,58 @@
package main

import (
"fmt"
"context"
"os"
"runtime/debug"
"os/signal"
"syscall"

"github.com/amberpixels/git-undo/cmd/shared"
"github.com/amberpixels/git-undo/internal/app"
"github.com/urfave/cli/v3"
)

// version is set by the build ldflags
// The default value is "dev+dirty" but it should never be used. In success path, it's always overwritten.
var version = "dev+dirty"
var versionSource = "hardcoded"

func main() {
var verbose, dryRun bool
for _, arg := range os.Args[1:] {
if arg == "-v" || arg == "--verbose" {
verbose = true
}
if arg == "--dry-run" {
dryRun = true
}
}
const (
appNameGitUndo = "git-undo"
)

// When running binary that was installed via `go install`, here we'll get the proper version
if bi, ok := debug.ReadBuildInfo(); ok && bi.Main.Version != "" {
version = bi.Main.Version
func main() {
// Create a context that can be cancelled with Ctrl+C
ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
defer cancel()

version, versionSource = app.HandleAppVersion(version, versionSource)

cmd := &cli.Command{
Name: appNameGitUndo,
Usage: "Universal \"Ctrl + Z\" for Git commands",
DisableSliceFlagSeparator: true,
HideHelp: true,
Flags: shared.CommonFlags(),
Action: func(ctx context.Context, c *cli.Command) error {
application := app.NewAppGitUndo(version, versionSource)
if c.Bool("version") {
return application.HandleVersion(c.Bool("verbose"))
}

// Use the new structured approach with parsed options
opts := app.RunOptions{
Verbose: c.Bool("verbose"),
DryRun: c.Bool("dry-run"),
HookCommand: c.String("hook"),
ShowLog: c.Bool("log"),
Args: c.Args().Slice(),
}

return application.Run(ctx, opts)
},
}
application := app.NewAppGitUndo(version, verbose, dryRun)

if err := application.Run(os.Args[1:]); err != nil {
_, _ = fmt.Fprintln(os.Stderr, redColor+appNameGitUndo+" ❌: "+grayColor+err.Error()+resetColor)
os.Exit(1)
if err := cmd.Run(ctx, os.Args); err != nil {
app.HandleError(appNameGitUndo, err)
}
}

const (
grayColor = "\033[90m"
redColor = "\033[31m"
resetColor = "\033[0m"

appNameGitUndo = "git-undo"
)
37 changes: 37 additions & 0 deletions cmd/shared/flags.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package shared

import (
"github.com/urfave/cli/v3"
)

// CommonFlags returns the standard set of CLI flags used by both git-undo and git-back commands.
func CommonFlags() []cli.Flag {
return []cli.Flag{
&cli.BoolFlag{
Name: "help",
Aliases: []string{"h"},
Usage: "Show help",
},
&cli.BoolFlag{
Name: "verbose",
Aliases: []string{"v"},
Usage: "Enable verbose output",
},
&cli.BoolFlag{
Name: "dry-run",
Usage: "Show what would be executed without running commands",
},
&cli.BoolFlag{
Name: "version",
Usage: "Print the version",
},
&cli.StringFlag{
Name: "hook",
Usage: "Hook command for shell integration (internal use)",
},
&cli.BoolFlag{
Name: "log",
Usage: "Display the git-undo command log",
},
}
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ toolchain go1.24.3
require (
github.com/mattn/go-shellwords v1.0.12
github.com/stretchr/testify v1.10.0
github.com/urfave/cli/v3 v3.3.8
)

require (
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/urfave/cli/v3 v3.3.8 h1:BzolUExliMdet9NlJ/u4m5vHSotJ3PzEqSAZ1oPMa/E=
github.com/urfave/cli/v3 v3.3.8/go.mod h1:FJSKtM/9AiiTOJL4fJ6TbMUkxBXn7GO9guZqoZtpYpo=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
Expand Down
1 change: 0 additions & 1 deletion install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ install_dispatcher_into() {
log "Installing dispatcher script to: $DISPATCHER_FILE"

# Debug: Check if source file exists
echo "AAAA $DISPATCHER_SRC"
if [[ ! -f "$DISPATCHER_SRC" ]]; then
log_error "Source dispatcher script not found: $DISPATCHER_SRC"
log_error "DISPATCHER_SRC variable: '$DISPATCHER_SRC'"
Expand Down
Loading
Loading