Skip to content
Open
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
1 change: 1 addition & 0 deletions container/cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ func main() {
v1.Post("/git/checkout/:org/:repo", gitHandler.CheckoutRepository)
v1.Get("/git/status", gitHandler.GetStatus)
v1.Get("/git/worktrees", gitHandler.ListWorktrees)
v1.Post("/git/worktrees", gitHandler.CreateWorktree)
v1.Delete("/git/worktrees/:id", gitHandler.DeleteWorktree)
v1.Post("/git/worktrees/:id/sync", gitHandler.SyncWorktree)
v1.Get("/git/worktrees/:id/sync/check", gitHandler.CheckSyncConflicts)
Expand Down
60 changes: 60 additions & 0 deletions container/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,38 @@ const docTemplate = `{
}
}
}
},
"post": {
"description": "Creates a new worktree from a branch, commit, or existing worktree",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"git"
],
"summary": "Create a new worktree",
"parameters": [
{
"description": "Worktree creation request",
"name": "request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/github_com_vanpelt_catnip_internal_models.WorktreeCreateRequest"
}
}
],
"responses": {
"201": {
"description": "Created",
"schema": {
"$ref": "#/definitions/github_com_vanpelt_catnip_internal_models.Worktree"
}
}
}
}
},
"/v1/git/worktrees/{id}": {
Expand Down Expand Up @@ -1413,6 +1445,13 @@ const docTemplate = `{
"type": "string",
"example": "feature/api-docs"
},
"child_worktree_ids": {
"description": "Child worktree IDs created from this worktree",
"type": "array",
"items": {
"type": "string"
}
},
"commit_count": {
"description": "Number of commits ahead of the divergence point (CommitHash)",
"type": "integer",
Expand Down Expand Up @@ -1453,6 +1492,10 @@ const docTemplate = `{
"type": "string",
"example": "feature-api-docs"
},
"parent_worktree_id": {
"description": "Parent worktree ID if created from another worktree",
"type": "string"
},
"path": {
"description": "Absolute path to the worktree directory",
"type": "string",
Expand Down Expand Up @@ -1485,6 +1528,23 @@ const docTemplate = `{
}
}
},
"github_com_vanpelt_catnip_internal_models.WorktreeCreateRequest": {
"type": "object",
"properties": {
"name": {
"description": "User-friendly name (optional, generated if empty)",
"type": "string"
},
"source": {
"description": "Branch name, commit hash, or worktree ID",
"type": "string"
},
"source_type": {
"description": "\"branch\", \"commit\", or \"worktree\"",
"type": "string"
}
}
},
"github_com_vanpelt_catnip_internal_services.ServiceInfo": {
"type": "object",
"properties": {
Expand Down
60 changes: 60 additions & 0 deletions container/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,38 @@
}
}
}
},
"post": {
"description": "Creates a new worktree from a branch, commit, or existing worktree",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"git"
],
"summary": "Create a new worktree",
"parameters": [
{
"description": "Worktree creation request",
"name": "request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/github_com_vanpelt_catnip_internal_models.WorktreeCreateRequest"
}
}
],
"responses": {
"201": {
"description": "Created",
"schema": {
"$ref": "#/definitions/github_com_vanpelt_catnip_internal_models.Worktree"
}
}
}
}
},
"/v1/git/worktrees/{id}": {
Expand Down Expand Up @@ -1410,6 +1442,13 @@
"type": "string",
"example": "feature/api-docs"
},
"child_worktree_ids": {
"description": "Child worktree IDs created from this worktree",
"type": "array",
"items": {
"type": "string"
}
},
"commit_count": {
"description": "Number of commits ahead of the divergence point (CommitHash)",
"type": "integer",
Expand Down Expand Up @@ -1450,6 +1489,10 @@
"type": "string",
"example": "feature-api-docs"
},
"parent_worktree_id": {
"description": "Parent worktree ID if created from another worktree",
"type": "string"
},
"path": {
"description": "Absolute path to the worktree directory",
"type": "string",
Expand Down Expand Up @@ -1482,6 +1525,23 @@
}
}
},
"github_com_vanpelt_catnip_internal_models.WorktreeCreateRequest": {
"type": "object",
"properties": {
"name": {
"description": "User-friendly name (optional, generated if empty)",
"type": "string"
},
"source": {
"description": "Branch name, commit hash, or worktree ID",
"type": "string"
},
"source_type": {
"description": "\"branch\", \"commit\", or \"worktree\"",
"type": "string"
}
}
},
"github_com_vanpelt_catnip_internal_services.ServiceInfo": {
"type": "object",
"properties": {
Expand Down
41 changes: 41 additions & 0 deletions container/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,11 @@ definitions:
description: Current git branch name in this worktree
example: feature/api-docs
type: string
child_worktree_ids:
description: Child worktree IDs created from this worktree
items:
type: string
type: array
commit_count:
description: Number of commits ahead of the divergence point (CommitHash)
example: 3
Expand Down Expand Up @@ -369,6 +374,9 @@ definitions:
description: User-friendly name for this worktree (e.g., 'vectorize-quasar')
example: feature-api-docs
type: string
parent_worktree_id:
description: Parent worktree ID if created from another worktree
type: string
path:
description: Absolute path to the worktree directory
example: /workspace/worktrees/feature-api-docs
Expand All @@ -391,6 +399,18 @@ definitions:
example: main
type: string
type: object
github_com_vanpelt_catnip_internal_models.WorktreeCreateRequest:
properties:
name:
description: User-friendly name (optional, generated if empty)
type: string
source:
description: Branch name, commit hash, or worktree ID
type: string
source_type:
description: '"branch", "commit", or "worktree"'
type: string
type: object
github_com_vanpelt_catnip_internal_services.ServiceInfo:
properties:
command:
Expand Down Expand Up @@ -933,6 +953,27 @@ paths:
summary: List all worktrees
tags:
- git
post:
consumes:
- application/json
description: Creates a new worktree from a branch, commit, or existing worktree
parameters:
- description: Worktree creation request
in: body
name: request
required: true
schema:
$ref: '#/definitions/github_com_vanpelt_catnip_internal_models.WorktreeCreateRequest'
produces:
- application/json
responses:
"201":
description: Created
schema:
$ref: '#/definitions/github_com_vanpelt_catnip_internal_models.Worktree'
summary: Create a new worktree
tags:
- git
/v1/git/worktrees/{id}:
delete:
description: Removes a worktree from the repository
Expand Down
4 changes: 2 additions & 2 deletions container/internal/assets/embedded.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func GetEmbeddedAssets() fs.FS {
// Assets not embedded (likely development build)
return nil
}

assets, err := fs.Sub(embeddedAssets, "dist")
if err != nil {
// This shouldn't happen if ReadDir succeeded above
Expand All @@ -29,4 +29,4 @@ func GetEmbeddedAssets() fs.FS {
func HasEmbeddedAssets() bool {
_, err := embeddedAssets.ReadDir("dist")
return err == nil
}
}
10 changes: 5 additions & 5 deletions container/internal/cmd/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,13 @@ func runWithLogging(args []string) error {

// Set up the command
command := exec.Command(args[0], args[1:]...)

// Create pipes for stdout and stderr
stdout, err := command.StdoutPipe()
if err != nil {
return fmt.Errorf("failed to create stdout pipe: %w", err)
}

stderr, err := command.StderrPipe()
if err != nil {
return fmt.Errorf("failed to create stderr pipe: %w", err)
Expand All @@ -114,7 +114,7 @@ func runWithLogging(args []string) error {
scanner := bufio.NewScanner(stdout)
for scanner.Scan() {
line := scanner.Text()
fmt.Println(line) // Print to console
fmt.Println(line) // Print to console
if _, err := fmt.Fprintln(file, line); err != nil {
fmt.Fprintf(os.Stderr, "Error writing to log file: %v\n", err)
}
Expand All @@ -125,7 +125,7 @@ func runWithLogging(args []string) error {
scanner := bufio.NewScanner(stderr)
for scanner.Scan() {
line := scanner.Text()
fmt.Fprintln(os.Stderr, line) // Print to console stderr
fmt.Fprintln(os.Stderr, line) // Print to console stderr
if _, err := fmt.Fprintln(file, line); err != nil {
fmt.Fprintf(os.Stderr, "Error writing to log file: %v\n", err)
}
Expand Down Expand Up @@ -156,4 +156,4 @@ func runWithLogging(args []string) error {

func init() {
rootCmd.AddCommand(logsCmd)
}
}
22 changes: 11 additions & 11 deletions container/internal/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ func Execute() {

func init() {
rootCmd.CompletionOptions.DisableDefaultCmd = true

// Add version command
rootCmd.AddCommand(versionCmd)

// Set custom help function to use Glow for beautiful markdown rendering
rootCmd.SetHelpFunc(func(cmd *cobra.Command, args []string) {
renderMarkdownHelp(cmd)
Expand Down Expand Up @@ -91,7 +91,7 @@ var versionCmd = &cobra.Command{
func renderMarkdownHelp(cmd *cobra.Command) {
// Create the help content
var helpContent strings.Builder

// Add the long description if available
if cmd.Long != "" {
helpContent.WriteString(cmd.Long)
Expand All @@ -100,13 +100,13 @@ func renderMarkdownHelp(cmd *cobra.Command) {
helpContent.WriteString("# " + cmd.Short)
helpContent.WriteString("\n\n")
}

// Add usage
helpContent.WriteString("## 📖 Usage\n\n")
helpContent.WriteString("```bash\n")
helpContent.WriteString(cmd.UseLine())
helpContent.WriteString("\n```\n\n")

// Add available commands
if cmd.HasAvailableSubCommands() {
helpContent.WriteString("## 🔧 Available Commands\n\n")
Expand All @@ -117,7 +117,7 @@ func renderMarkdownHelp(cmd *cobra.Command) {
}
helpContent.WriteString("\n")
}

// Add flags
if cmd.HasAvailableFlags() {
helpContent.WriteString("## ⚙️ Flags\n\n")
Expand All @@ -128,7 +128,7 @@ func renderMarkdownHelp(cmd *cobra.Command) {
helpContent.WriteString("```\n\n")
}
}

// Add global flags if this is a subcommand
if cmd.HasParent() && cmd.InheritedFlags().HasFlags() {
helpContent.WriteString("## 🌐 Global Flags\n\n")
Expand All @@ -139,7 +139,7 @@ func renderMarkdownHelp(cmd *cobra.Command) {
helpContent.WriteString("```\n\n")
}
}

// Render with glamour
renderer, err := glamour.NewTermRenderer(
glamour.WithAutoStyle(),
Expand All @@ -150,13 +150,13 @@ func renderMarkdownHelp(cmd *cobra.Command) {
_ = cmd.Help()
return
}

rendered, err := renderer.Render(helpContent.String())
if err != nil {
// Fallback to default help if rendering fails
_ = cmd.Help()
return
}

fmt.Print(rendered)
}
}
Loading
Loading