gw 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 97fd7885b19967d3259100bd934f123b9b51300e66e9f9960dc7b516fb218185
4
+ data.tar.gz: c55173aebd6cdba63d0cb2e9d8e49f7dd62c3d1478ff4cf990c6f66ac5401728
5
+ SHA512:
6
+ metadata.gz: 54f924ad6fe0ca52c802b9b7f321d3192571936f70cebda02415722163e720a6ee1c15cb22bf6182d74c47561180ef4f21efc27f1c6a47f97afc55ec162d7ecf
7
+ data.tar.gz: 27e19d825d7f8088946c9e691eec73464bb8b1e2403ae5a0206f034b5b07bf488b70c6450e8a53f658718e054a1b4b5134347b16735d1f77e8596fd8f6db0b89
@@ -0,0 +1,29 @@
1
+ name: Ruby
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+
8
+ pull_request:
9
+
10
+ jobs:
11
+ build:
12
+ runs-on: ubuntu-latest
13
+ name: Ruby ${{ matrix.ruby }}
14
+ strategy:
15
+ matrix:
16
+ ruby:
17
+ - '3.4.8'
18
+
19
+ steps:
20
+ - uses: actions/checkout@v4
21
+ with:
22
+ persist-credentials: false
23
+ - name: Set up Ruby
24
+ uses: ruby/setup-ruby@v1
25
+ with:
26
+ ruby-version: ${{ matrix.ruby }}
27
+ bundler-cache: true
28
+ - name: Run the default task
29
+ run: bundle exec rake
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,8 @@
1
+ AllCops:
2
+ TargetRubyVersion: 3.2
3
+
4
+ Style/StringLiterals:
5
+ EnforcedStyle: double_quotes
6
+
7
+ Style/StringLiteralsInInterpolation:
8
+ EnforcedStyle: double_quotes
data/AGENTS.md ADDED
@@ -0,0 +1,178 @@
1
+ # gw - Git Worktree Manager
2
+
3
+ ## Project Overview
4
+
5
+ `gw` is a Ruby-based CLI tool for managing git worktrees using the bare repository pattern with a convention-over-configuration approach.
6
+
7
+ ## Design Philosophy
8
+
9
+ ### Convention over Configuration (Rails-like)
10
+
11
+ - **Directory Structure Convention**: Fixed `core/` and `tree/` directories
12
+ - **Environment Management**: Uses `direnv` with repository-level `.env` files
13
+ - **No File Copying**: Individual `.env` files placed at `tree/{repo-name}/.env` level
14
+ - **Multi-Repository Management**: Cross-repository worktree management from anywhere
15
+
16
+ ### Directory Structure
17
+
18
+ ```
19
+ ~/Repository/ # Default workspace (configurable)
20
+ core/ # Bare repositories (fixed name)
21
+ tools/ # bare repository
22
+ frontend/ # bare repository
23
+ tree/ # Worktrees (fixed name)
24
+ tools/
25
+ .env # Repository-level config (managed by user)
26
+ .envrc # direnv config (managed by user)
27
+ main/ # worktree
28
+ feature-1/ # worktree
29
+ frontend/
30
+ .env
31
+ main/
32
+ ui-redesign/
33
+ ```
34
+
35
+ ## Core Features
36
+
37
+ ### 1. Repository Management
38
+ - Clone repositories as bare with custom names
39
+ - GitHub integration via Octokit (not dependent on `gh` CLI)
40
+ - Support for organization namespace collision (e.g., `org1/app` vs `org2/app`)
41
+
42
+ ### 2. Worktree Operations
43
+ - Add worktrees with automatic branch creation
44
+ - Remove worktrees
45
+ - List all worktrees across repositories
46
+ - Navigate to worktrees: `cd $(gw go tools/feature-1)`
47
+ - Repository-scoped operations: `gw add tools/feature-1`
48
+
49
+ ### 3. Configuration Management
50
+ - Default workspace: `~/Repository`
51
+ - Workspace location configurable via `~/.config/gw/config.yml`
52
+ - GitHub token hierarchy: `gh auth token` → `GITHUB_TOKEN` env var → config file
53
+
54
+ ### 4. GitHub Integration
55
+ - Token priority:
56
+ 1. `gh auth token` (if `gh` command available)
57
+ 2. `GITHUB_TOKEN` environment variable
58
+ 3. `~/.config/gw/config.yml` setting
59
+ 4. Error with helpful message
60
+
61
+ ## Command Reference
62
+
63
+ ```bash
64
+ # Initialize workspace
65
+ gw init
66
+
67
+ # Clone repository
68
+ gw repo clone aileron-inc/tools
69
+ gw repo clone org/app --name org-app # Custom name to avoid collision
70
+
71
+ # Add worktree (auto-creates branch if not exists)
72
+ gw add tools/feature-1
73
+
74
+ # Remove worktree
75
+ gw remove tools/feature-1
76
+ gw rm tools/feature-1 # Alias
77
+
78
+ # List worktrees
79
+ gw list # All repositories
80
+ gw list tools # Specific repository
81
+
82
+ # Navigate to worktree
83
+ cd $(gw go tools/feature-1)
84
+
85
+ # Configuration
86
+ gw config get workspace
87
+ gw config set workspace ~/my-workspace
88
+ gw config set github_token ghp_xxxxx
89
+ ```
90
+
91
+ ## Implementation Guidelines
92
+
93
+ ### Code Structure
94
+
95
+ ```
96
+ lib/gw/
97
+ version.rb # Version constant
98
+ errors.rb # Error classes
99
+ config.rb # Configuration management
100
+ github.rb # GitHub API integration (Octokit)
101
+ repository.rb # Repository operations (bare repos)
102
+ worktree.rb # Worktree operations
103
+ cli.rb # Command-line interface
104
+ ```
105
+
106
+ ### Design Patterns
107
+
108
+ 1. **Class Methods for Operations**: Use class methods for primary operations (e.g., `Repository.clone`, `Worktree.add`)
109
+ 2. **Instance for State**: Use instances to hold state (e.g., `Repository` instance has `name`, `bare_path`)
110
+ 3. **Simple Error Handling**: Raise specific errors, catch in CLI layer
111
+ 4. **No Heavy Dependencies**: Keep dependencies minimal (only Octokit for GitHub API)
112
+
113
+ ### Key Decisions
114
+
115
+ - **No bare repository auto-creation of main branch**: Keep operations explicit
116
+ - **Auto-create branches on `gw add`**: If branch doesn't exist, create from default branch
117
+ - **No file copying hooks**: Use direnv convention instead
118
+ - **No editor/AI integration yet**: Focus on core worktree management first (can add later)
119
+
120
+ ## Future Enhancements (Not in MVP)
121
+
122
+ - `gw editor <repo>/<branch>` - Open editor (like gtr)
123
+ - `gw ai <repo>/<branch>` - Start AI tool (like gtr)
124
+ - `gw run <repo>/<branch> <command>` - Run command in worktree
125
+ - `gw status` - Show git status across all worktrees
126
+ - `gw prune` - Clean up stale worktrees
127
+
128
+ ## Development Notes
129
+
130
+ ### Dependencies
131
+
132
+ - `octokit` (~> 9.0) - GitHub API client
133
+ - No dependency on `gh` CLI (optional for token retrieval)
134
+
135
+ ### Testing Strategy
136
+
137
+ - Manual testing for MVP
138
+ - Future: RSpec for unit tests
139
+ - Integration tests for git operations
140
+
141
+ ### RuboCop
142
+
143
+ - Some warnings acceptable for rapid development
144
+ - Focus on functionality over style compliance initially
145
+ - Clean up in refinement phase
146
+
147
+ ## Differences from Similar Tools
148
+
149
+ ### vs git-worktree-runner (gtr)
150
+
151
+ | Feature | gtr | gw |
152
+ |---------|-----|-----|
153
+ | Scope | Single repository | Multi-repository |
154
+ | Operation | From within repo | From anywhere |
155
+ | Config files | Auto-copy | direnv convention |
156
+ | Hooks | Post-create, etc. | None (keep simple) |
157
+ | GitHub | None | Octokit integration |
158
+ | Philosophy | Configuration | Convention |
159
+
160
+ ### vs Manual git worktree
161
+
162
+ - Higher-level abstractions
163
+ - Multi-repository management
164
+ - GitHub integration
165
+ - Consistent directory structure
166
+ - Simplified commands
167
+
168
+ ## Contributing Guidelines
169
+
170
+ 1. Keep it simple - convention over configuration
171
+ 2. No feature creep - focus on core worktree management
172
+ 3. Follow existing patterns (see `kc-rb` for reference)
173
+ 4. Test manually before committing
174
+ 5. Document new commands in this file
175
+
176
+ ## License
177
+
178
+ MIT License (same as parent project)
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2025-12-28
4
+
5
+ - Initial release
@@ -0,0 +1,132 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our
6
+ community a harassment-free experience for everyone, regardless of age, body
7
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
8
+ identity and expression, level of experience, education, socio-economic status,
9
+ nationality, personal appearance, race, caste, color, religion, or sexual
10
+ identity and orientation.
11
+
12
+ We pledge to act and interact in ways that contribute to an open, welcoming,
13
+ diverse, inclusive, and healthy community.
14
+
15
+ ## Our Standards
16
+
17
+ Examples of behavior that contributes to a positive environment for our
18
+ community include:
19
+
20
+ * Demonstrating empathy and kindness toward other people
21
+ * Being respectful of differing opinions, viewpoints, and experiences
22
+ * Giving and gracefully accepting constructive feedback
23
+ * Accepting responsibility and apologizing to those affected by our mistakes,
24
+ and learning from the experience
25
+ * Focusing on what is best not just for us as individuals, but for the overall
26
+ community
27
+
28
+ Examples of unacceptable behavior include:
29
+
30
+ * The use of sexualized language or imagery, and sexual attention or advances of
31
+ any kind
32
+ * Trolling, insulting or derogatory comments, and personal or political attacks
33
+ * Public or private harassment
34
+ * Publishing others' private information, such as a physical or email address,
35
+ without their explicit permission
36
+ * Other conduct which could reasonably be considered inappropriate in a
37
+ professional setting
38
+
39
+ ## Enforcement Responsibilities
40
+
41
+ Community leaders are responsible for clarifying and enforcing our standards of
42
+ acceptable behavior and will take appropriate and fair corrective action in
43
+ response to any behavior that they deem inappropriate, threatening, offensive,
44
+ or harmful.
45
+
46
+ Community leaders have the right and responsibility to remove, edit, or reject
47
+ comments, commits, code, wiki edits, issues, and other contributions that are
48
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
49
+ decisions when appropriate.
50
+
51
+ ## Scope
52
+
53
+ This Code of Conduct applies within all community spaces, and also applies when
54
+ an individual is officially representing the community in public spaces.
55
+ Examples of representing our community include using an official email address,
56
+ posting via an official social media account, or acting as an appointed
57
+ representative at an online or offline event.
58
+
59
+ ## Enforcement
60
+
61
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
62
+ reported to the community leaders responsible for enforcement at
63
+ [INSERT CONTACT METHOD].
64
+ All complaints will be reviewed and investigated promptly and fairly.
65
+
66
+ All community leaders are obligated to respect the privacy and security of the
67
+ reporter of any incident.
68
+
69
+ ## Enforcement Guidelines
70
+
71
+ Community leaders will follow these Community Impact Guidelines in determining
72
+ the consequences for any action they deem in violation of this Code of Conduct:
73
+
74
+ ### 1. Correction
75
+
76
+ **Community Impact**: Use of inappropriate language or other behavior deemed
77
+ unprofessional or unwelcome in the community.
78
+
79
+ **Consequence**: A private, written warning from community leaders, providing
80
+ clarity around the nature of the violation and an explanation of why the
81
+ behavior was inappropriate. A public apology may be requested.
82
+
83
+ ### 2. Warning
84
+
85
+ **Community Impact**: A violation through a single incident or series of
86
+ actions.
87
+
88
+ **Consequence**: A warning with consequences for continued behavior. No
89
+ interaction with the people involved, including unsolicited interaction with
90
+ those enforcing the Code of Conduct, for a specified period of time. This
91
+ includes avoiding interactions in community spaces as well as external channels
92
+ like social media. Violating these terms may lead to a temporary or permanent
93
+ ban.
94
+
95
+ ### 3. Temporary Ban
96
+
97
+ **Community Impact**: A serious violation of community standards, including
98
+ sustained inappropriate behavior.
99
+
100
+ **Consequence**: A temporary ban from any sort of interaction or public
101
+ communication with the community for a specified period of time. No public or
102
+ private interaction with the people involved, including unsolicited interaction
103
+ with those enforcing the Code of Conduct, is allowed during this period.
104
+ Violating these terms may lead to a permanent ban.
105
+
106
+ ### 4. Permanent Ban
107
+
108
+ **Community Impact**: Demonstrating a pattern of violation of community
109
+ standards, including sustained inappropriate behavior, harassment of an
110
+ individual, or aggression toward or disparagement of classes of individuals.
111
+
112
+ **Consequence**: A permanent ban from any sort of public interaction within the
113
+ community.
114
+
115
+ ## Attribution
116
+
117
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118
+ version 2.1, available at
119
+ [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
120
+
121
+ Community Impact Guidelines were inspired by
122
+ [Mozilla's code of conduct enforcement ladder][Mozilla CoC].
123
+
124
+ For answers to common questions about this code of conduct, see the FAQ at
125
+ [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
126
+ [https://www.contributor-covenant.org/translations][translations].
127
+
128
+ [homepage]: https://www.contributor-covenant.org
129
+ [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
130
+ [Mozilla CoC]: https://github.com/mozilla/diversity
131
+ [FAQ]: https://www.contributor-covenant.org/faq
132
+ [translations]: https://www.contributor-covenant.org/translations
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in gw.gemspec
6
+ gemspec
7
+
8
+ gem "irb"
9
+ gem "rake", "~> 13.0"
10
+
11
+ gem "rspec", "~> 3.0"
12
+
13
+ gem "rubocop", "~> 1.21"
data/Gemfile.lock ADDED
@@ -0,0 +1,109 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ gw (0.1.0)
5
+ octokit (~> 9.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ addressable (2.8.8)
11
+ public_suffix (>= 2.0.2, < 8.0)
12
+ ast (2.4.3)
13
+ date (3.5.1)
14
+ diff-lcs (1.6.2)
15
+ erb (6.0.1)
16
+ faraday (2.14.0)
17
+ faraday-net_http (>= 2.0, < 3.5)
18
+ json
19
+ logger
20
+ faraday-net_http (3.4.2)
21
+ net-http (~> 0.5)
22
+ io-console (0.8.2)
23
+ irb (1.16.0)
24
+ pp (>= 0.6.0)
25
+ rdoc (>= 4.0.0)
26
+ reline (>= 0.4.2)
27
+ json (2.18.0)
28
+ language_server-protocol (3.17.0.5)
29
+ lint_roller (1.1.0)
30
+ logger (1.7.0)
31
+ net-http (0.9.1)
32
+ uri (>= 0.11.1)
33
+ octokit (9.2.0)
34
+ faraday (>= 1, < 3)
35
+ sawyer (~> 0.9)
36
+ parallel (1.27.0)
37
+ parser (3.3.10.0)
38
+ ast (~> 2.4.1)
39
+ racc
40
+ pp (0.6.3)
41
+ prettyprint
42
+ prettyprint (0.2.0)
43
+ prism (1.7.0)
44
+ psych (5.3.1)
45
+ date
46
+ stringio
47
+ public_suffix (7.0.0)
48
+ racc (1.8.1)
49
+ rainbow (3.1.1)
50
+ rake (13.3.1)
51
+ rdoc (7.0.3)
52
+ erb
53
+ psych (>= 4.0.0)
54
+ tsort
55
+ regexp_parser (2.11.3)
56
+ reline (0.6.3)
57
+ io-console (~> 0.5)
58
+ rspec (3.13.2)
59
+ rspec-core (~> 3.13.0)
60
+ rspec-expectations (~> 3.13.0)
61
+ rspec-mocks (~> 3.13.0)
62
+ rspec-core (3.13.6)
63
+ rspec-support (~> 3.13.0)
64
+ rspec-expectations (3.13.5)
65
+ diff-lcs (>= 1.2.0, < 2.0)
66
+ rspec-support (~> 3.13.0)
67
+ rspec-mocks (3.13.7)
68
+ diff-lcs (>= 1.2.0, < 2.0)
69
+ rspec-support (~> 3.13.0)
70
+ rspec-support (3.13.6)
71
+ rubocop (1.82.1)
72
+ json (~> 2.3)
73
+ language_server-protocol (~> 3.17.0.2)
74
+ lint_roller (~> 1.1.0)
75
+ parallel (~> 1.10)
76
+ parser (>= 3.3.0.2)
77
+ rainbow (>= 2.2.2, < 4.0)
78
+ regexp_parser (>= 2.9.3, < 3.0)
79
+ rubocop-ast (>= 1.48.0, < 2.0)
80
+ ruby-progressbar (~> 1.7)
81
+ unicode-display_width (>= 2.4.0, < 4.0)
82
+ rubocop-ast (1.49.0)
83
+ parser (>= 3.3.7.2)
84
+ prism (~> 1.7)
85
+ ruby-progressbar (1.13.0)
86
+ sawyer (0.9.3)
87
+ addressable (>= 2.3.5)
88
+ faraday (>= 0.17.3, < 3)
89
+ stringio (3.2.0)
90
+ tsort (0.2.0)
91
+ unicode-display_width (3.2.0)
92
+ unicode-emoji (~> 4.1)
93
+ unicode-emoji (4.2.0)
94
+ uri (1.1.1)
95
+
96
+ PLATFORMS
97
+ arm64-darwin-25
98
+ ruby
99
+
100
+ DEPENDENCIES
101
+ bundler
102
+ gw!
103
+ irb
104
+ rake (~> 13.0, >= 0)
105
+ rspec (~> 3.0)
106
+ rubocop (~> 1.21)
107
+
108
+ BUNDLED WITH
109
+ 2.7.2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 AILERON
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # Gw
2
+
3
+ TODO: Delete this and the text below, and describe your gem
4
+
5
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/gw`. To experiment with that code, run `bin/console` for an interactive prompt.
6
+
7
+ ## Installation
8
+
9
+ TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
10
+
11
+ Install the gem and add to the application's Gemfile by executing:
12
+
13
+ ```bash
14
+ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
15
+ ```
16
+
17
+ If bundler is not being used to manage dependencies, install the gem by executing:
18
+
19
+ ```bash
20
+ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/gw. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/gw/blob/main/CODE_OF_CONDUCT.md).
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
40
+
41
+ ## Code of Conduct
42
+
43
+ Everyone interacting in the Gw project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/gw/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
data/bin/console ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "gw"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ require "irb"
11
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/exe/gw ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'gw'
4
+
5
+ Gw::CLI.start(ARGV)
data/gw.gemspec ADDED
@@ -0,0 +1,36 @@
1
+ lib = File.expand_path("lib", __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "gw/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "gw"
7
+ spec.version = Gw::VERSION
8
+ spec.authors = ["AILERON"]
9
+ spec.email = ["masa@aileron.cc"]
10
+
11
+ spec.summary = "Git worktree manager with bare repository pattern"
12
+ spec.description = "A CLI tool to manage git worktrees using bare repository pattern (core/ and tree/ structure)"
13
+ spec.homepage = "https://github.com/aileron-inc/tools"
14
+ spec.license = "MIT"
15
+
16
+ if spec.respond_to?(:metadata)
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = "https://github.com/aileron-inc/tools"
19
+ else
20
+ raise "RubyGems 2.0 or newer is required to protect against " \
21
+ "public gem pushes."
22
+ end
23
+
24
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
25
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ end
27
+ spec.bindir = "exe"
28
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
29
+ spec.require_paths = ["lib"]
30
+
31
+ spec.add_dependency "octokit", "~> 9.0"
32
+
33
+ spec.add_development_dependency "bundler"
34
+ spec.add_development_dependency "rake"
35
+ spec.add_development_dependency "rspec", "~> 3.0"
36
+ end
data/lib/gw/cli.rb ADDED
@@ -0,0 +1,258 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Gw
4
+ class CLI
5
+ def self.start(argv)
6
+ new(argv).run
7
+ end
8
+
9
+ def initialize(argv)
10
+ @argv = argv
11
+ end
12
+
13
+ def run
14
+ command = @argv[0]
15
+
16
+ case command
17
+ when "init"
18
+ handle_init
19
+ when "repo"
20
+ handle_repo
21
+ when "add"
22
+ handle_add
23
+ when "remove", "rm"
24
+ handle_remove
25
+ when "list", "ls"
26
+ handle_list
27
+ when "go"
28
+ handle_go
29
+ when "config"
30
+ handle_config
31
+ else
32
+ show_usage
33
+ exit 1
34
+ end
35
+ rescue StandardError => e
36
+ puts "Error: #{e.message}"
37
+ exit 1
38
+ end
39
+
40
+ private
41
+
42
+ def handle_init
43
+ workspace = Config.workspace
44
+ core_dir = Config.core_dir
45
+ tree_dir = Config.tree_dir
46
+
47
+ FileUtils.mkdir_p(core_dir)
48
+ FileUtils.mkdir_p(tree_dir)
49
+
50
+ puts "Initialized gw workspace at #{workspace}"
51
+ puts " core: #{core_dir}"
52
+ puts " tree: #{tree_dir}"
53
+ end
54
+
55
+ def handle_repo
56
+ subcommand = @argv[1]
57
+
58
+ case subcommand
59
+ when "clone"
60
+ handle_repo_clone
61
+ else
62
+ puts "Usage: gw repo clone <owner/repo> [--name <custom-name>]"
63
+ exit 1
64
+ end
65
+ end
66
+
67
+ def handle_repo_clone
68
+ full_name = @argv[2]
69
+ custom_name = nil
70
+
71
+ # Parse --name option
72
+ custom_name = @argv[4] if @argv[3] == "--name" && @argv[4]
73
+
74
+ unless full_name
75
+ puts "Error: repository name is required"
76
+ puts "Usage: gw repo clone <owner/repo> [--name <custom-name>]"
77
+ exit 1
78
+ end
79
+
80
+ repo = Repository.clone(full_name, custom_name: custom_name)
81
+ puts "Successfully cloned #{full_name} as '#{repo.name}'"
82
+ puts " bare: #{repo.bare_path}"
83
+ puts " tree: #{repo.tree_dir}"
84
+ end
85
+
86
+ def handle_add
87
+ target = @argv[1]
88
+
89
+ unless target
90
+ puts "Error: target is required"
91
+ puts "Usage: gw add <repo-name>/<branch>"
92
+ exit 1
93
+ end
94
+
95
+ # Parse repo-name/branch
96
+ parts = target.split("/")
97
+ if parts.length != 2
98
+ puts "Error: invalid format. Use: <repo-name>/<branch>"
99
+ exit 1
100
+ end
101
+
102
+ repo_name, branch = parts
103
+
104
+ worktree = Worktree.add(repo_name, branch)
105
+ puts "Successfully created worktree '#{branch}' for #{repo_name}"
106
+ puts " path: #{worktree.path}"
107
+ end
108
+
109
+ def handle_remove
110
+ target = @argv[1]
111
+
112
+ unless target
113
+ puts "Error: target is required"
114
+ puts "Usage: gw remove <repo-name>/<branch>"
115
+ exit 1
116
+ end
117
+
118
+ # Parse repo-name/branch
119
+ parts = target.split("/")
120
+ if parts.length != 2
121
+ puts "Error: invalid format. Use: <repo-name>/<branch>"
122
+ exit 1
123
+ end
124
+
125
+ repo_name, branch = parts
126
+
127
+ Worktree.remove(repo_name, branch)
128
+ puts "Successfully removed worktree '#{branch}' for #{repo_name}"
129
+ end
130
+
131
+ def handle_list
132
+ filter = @argv[1]
133
+
134
+ repos = if filter
135
+ [Repository.find(filter)]
136
+ else
137
+ Repository.list
138
+ end
139
+
140
+ if repos.empty?
141
+ puts "No repositories found"
142
+ return
143
+ end
144
+
145
+ # Collect all worktrees with repo/branch format
146
+ all_worktrees = []
147
+ repos.each do |repo|
148
+ worktrees = repo.worktrees
149
+ if worktrees.empty?
150
+ all_worktrees << { repo: repo.name, branch: "(no worktrees)", path: "" }
151
+ else
152
+ worktrees.each do |wt|
153
+ all_worktrees << { repo: repo.name, branch: wt.branch, path: wt.path }
154
+ end
155
+ end
156
+ end
157
+
158
+ # Calculate column widths
159
+ max_combined = all_worktrees.map { |wt| "#{wt[:repo]}/#{wt[:branch]}".length }.max || 0
160
+ combined_width = [max_combined + 2, 30].max
161
+
162
+ puts "#{"WORKTREE".ljust(combined_width)}PATH"
163
+ all_worktrees.each do |wt|
164
+ if wt[:branch] == "(no worktrees)"
165
+ puts "#{wt[:repo].ljust(combined_width)}#{wt[:branch]}"
166
+ else
167
+ combined = "#{wt[:repo]}/#{wt[:branch]}"
168
+ puts "#{combined.ljust(combined_width)}#{wt[:path]}"
169
+ end
170
+ end
171
+ end
172
+
173
+ def handle_go
174
+ target = @argv[1]
175
+
176
+ unless target
177
+ puts "Error: target is required"
178
+ puts "Usage: gw go <repo>/<branch>"
179
+ exit 1
180
+ end
181
+
182
+ # Parse repo-name/branch
183
+ parts = target.split("/")
184
+ if parts.length != 2
185
+ puts "Error: invalid format. Use: <repo>/<branch>"
186
+ exit 1
187
+ end
188
+
189
+ repo_name, branch = parts
190
+
191
+ # Find repository and worktree
192
+ repo = Repository.find(repo_name)
193
+ worktree = Worktree.new(repo, branch)
194
+
195
+ unless worktree.exist?
196
+ puts "Error: Worktree '#{branch}' not found for #{repo_name}"
197
+ exit 1
198
+ end
199
+
200
+ # Output path only (for cd command)
201
+ puts worktree.path
202
+ end
203
+
204
+ def handle_config
205
+ subcommand = @argv[1]
206
+ key = @argv[2]
207
+ value = @argv[3]
208
+
209
+ case subcommand
210
+ when "get"
211
+ unless key
212
+ puts "Error: key is required"
213
+ puts "Usage: gw config get <key>"
214
+ exit 1
215
+ end
216
+ result = Config.get(key)
217
+ puts result if result
218
+ when "set"
219
+ unless key && value
220
+ puts "Error: key and value are required"
221
+ puts "Usage: gw config set <key> <value>"
222
+ exit 1
223
+ end
224
+ Config.set(key, value)
225
+ puts "Successfully set #{key} = #{value}"
226
+ else
227
+ puts "Usage: gw config {get|set} <key> [value]"
228
+ exit 1
229
+ end
230
+ end
231
+
232
+ def show_usage
233
+ puts <<~USAGE
234
+ Usage:
235
+ gw init Initialize gw workspace
236
+ gw repo clone <owner/repo> Clone repository
237
+ gw repo clone <owner/repo> --name <name> Clone with custom name
238
+ gw add <repo>/<branch> Add worktree
239
+ gw remove <repo>/<branch> Remove worktree
240
+ gw list [repo] List worktrees
241
+ gw go <repo>/<branch> Print worktree path
242
+ gw config get <key> Get config value
243
+ gw config set <key> <value> Set config value
244
+
245
+ Examples:
246
+ gw init
247
+ gw repo clone aileron-inc/tools
248
+ gw repo clone org/app --name custom-app
249
+ gw add tools/feature-1
250
+ gw list
251
+ gw list tools
252
+ cd $(gw go tools/feature-1)
253
+ gw remove tools/feature-1
254
+ gw config set workspace ~/my-workspace
255
+ USAGE
256
+ end
257
+ end
258
+ end
data/lib/gw/config.rb ADDED
@@ -0,0 +1,73 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "yaml"
4
+ require "fileutils"
5
+
6
+ module Gw
7
+ class Config
8
+ CONFIG_DIR = File.expand_path("~/.config/gw")
9
+ CONFIG_FILE = File.join(CONFIG_DIR, "config.yml")
10
+ DEFAULT_WORKSPACE = File.expand_path("~/Repository")
11
+
12
+ class << self
13
+ def load
14
+ return default_config unless File.exist?(CONFIG_FILE)
15
+
16
+ YAML.load_file(CONFIG_FILE) || default_config
17
+ rescue StandardError => e
18
+ raise ConfigError, "Failed to load config: #{e.message}"
19
+ end
20
+
21
+ def save(config)
22
+ FileUtils.mkdir_p(CONFIG_DIR)
23
+ File.write(CONFIG_FILE, YAML.dump(config))
24
+ rescue StandardError => e
25
+ raise ConfigError, "Failed to save config: #{e.message}"
26
+ end
27
+
28
+ def get(key)
29
+ load[key]
30
+ end
31
+
32
+ def set(key, value)
33
+ config = load
34
+ config[key] = value
35
+ save(config)
36
+ end
37
+
38
+ def workspace
39
+ get("workspace") || DEFAULT_WORKSPACE
40
+ end
41
+
42
+ def core_dir
43
+ File.join(workspace, "core")
44
+ end
45
+
46
+ def tree_dir
47
+ File.join(workspace, "tree")
48
+ end
49
+
50
+ def editor
51
+ get("editor") || "cursor"
52
+ end
53
+
54
+ def ai
55
+ get("ai") || "claude"
56
+ end
57
+
58
+ def github_token
59
+ get("github_token")
60
+ end
61
+
62
+ private
63
+
64
+ def default_config
65
+ {
66
+ "workspace" => DEFAULT_WORKSPACE,
67
+ "editor" => "cursor",
68
+ "ai" => "claude"
69
+ }
70
+ end
71
+ end
72
+ end
73
+ end
data/lib/gw/errors.rb ADDED
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Gw
4
+ class Error < StandardError; end
5
+
6
+ class TokenNotFoundError < Error; end
7
+ class RepositoryNotFoundError < Error; end
8
+ class WorktreeAlreadyExistsError < Error; end
9
+ class BranchNotFoundError < Error; end
10
+ class ConfigError < Error; end
11
+ end
data/lib/gw/github.rb ADDED
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "octokit"
4
+
5
+ module Gw
6
+ class GitHub
7
+ class << self
8
+ def token
9
+ # 1. gh auth token (if gh is available)
10
+ if system("which gh > /dev/null 2>&1")
11
+ gh_token = `gh auth token 2>/dev/null`.strip
12
+ return gh_token unless gh_token.empty?
13
+ end
14
+
15
+ # 2. Environment variable
16
+ return ENV["GITHUB_TOKEN"] if ENV["GITHUB_TOKEN"]
17
+
18
+ # 3. Config file
19
+ config_token = Config.github_token
20
+ return config_token if config_token
21
+
22
+ # 4. Error
23
+ raise TokenNotFoundError, <<~MSG
24
+ GitHub token not found. Please use one of:
25
+ 1. gh auth login (recommended)
26
+ 2. export GITHUB_TOKEN=your_token
27
+ 3. gw config set github_token your_token
28
+ MSG
29
+ end
30
+
31
+ def client
32
+ @client ||= Octokit::Client.new(access_token: token)
33
+ end
34
+
35
+ def repository(full_name)
36
+ client.repository(full_name)
37
+ end
38
+
39
+ def default_branch(full_name)
40
+ repo = repository(full_name)
41
+ repo.default_branch
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,78 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "fileutils"
4
+
5
+ module Gw
6
+ class Repository
7
+ attr_reader :name, :full_name, :bare_path
8
+
9
+ def initialize(name, full_name = nil)
10
+ @name = name
11
+ @full_name = full_name
12
+ @bare_path = File.join(Config.core_dir, name)
13
+ end
14
+
15
+ def self.clone(full_name, custom_name: nil)
16
+ repo_name = custom_name || full_name.split("/").last
17
+ repo = new(repo_name, full_name)
18
+
19
+ raise Error, "Repository '#{repo_name}' already exists" if repo.exist?
20
+
21
+ FileUtils.mkdir_p(Config.core_dir)
22
+
23
+ # Clone as bare repository
24
+ clone_url = GitHub.repository(full_name).clone_url
25
+ success = system("git clone --bare #{clone_url} #{repo.bare_path}")
26
+
27
+ raise Error, "Failed to clone repository" unless success
28
+
29
+ # Create tree directory for this repo
30
+ FileUtils.mkdir_p(File.join(Config.tree_dir, repo_name))
31
+
32
+ repo
33
+ end
34
+
35
+ def self.list
36
+ return [] unless Dir.exist?(Config.core_dir)
37
+
38
+ Dir.children(Config.core_dir).map do |name|
39
+ new(name)
40
+ end.select(&:exist?)
41
+ end
42
+
43
+ def self.find(name)
44
+ repo = new(name)
45
+ raise RepositoryNotFoundError, "Repository '#{name}' not found" unless repo.exist?
46
+
47
+ repo
48
+ end
49
+
50
+ def exist?
51
+ Dir.exist?(bare_path) && File.exist?(File.join(bare_path, "HEAD"))
52
+ end
53
+
54
+ def tree_dir
55
+ File.join(Config.tree_dir, name)
56
+ end
57
+
58
+ def worktrees
59
+ Worktree.list(self)
60
+ end
61
+
62
+ def default_branch
63
+ return @default_branch if @default_branch
64
+
65
+ # Try to get from GitHub if full_name is available
66
+ if full_name
67
+ @default_branch = GitHub.default_branch(full_name)
68
+ else
69
+ # Fallback: read from bare repository
70
+ head_file = File.join(bare_path, "HEAD")
71
+ content = File.read(head_file).strip
72
+ @default_branch = content.match(%r{ref: refs/heads/(.+)})&.[](1) || "main"
73
+ end
74
+
75
+ @default_branch
76
+ end
77
+ end
78
+ end
data/lib/gw/version.rb ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Gw
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Gw
4
+ class Worktree
5
+ attr_reader :repository, :branch, :path
6
+
7
+ def initialize(repository, branch, path = nil)
8
+ @repository = repository
9
+ @branch = branch
10
+ @path = path || File.join(repository.tree_dir, branch)
11
+ end
12
+
13
+ def self.add(repo_name, branch)
14
+ repo = Repository.find(repo_name)
15
+ worktree = new(repo, branch)
16
+
17
+ raise WorktreeAlreadyExistsError, "Worktree '#{branch}' already exists" if worktree.exist?
18
+
19
+ # Check if branch exists (locally or remotely)
20
+ branch_exists = system("git -C #{repo.bare_path} show-ref --verify --quiet refs/heads/#{branch}") ||
21
+ system("git -C #{repo.bare_path} show-ref --verify --quiet refs/remotes/origin/#{branch}")
22
+
23
+ if branch_exists
24
+ # Branch exists, checkout
25
+ success = system("git -C #{repo.bare_path} worktree add #{worktree.path} #{branch}")
26
+ else
27
+ # Branch doesn't exist, create from default branch
28
+ default_branch = repo.default_branch
29
+ puts "Branch '#{branch}' not found. Creating from '#{default_branch}'..."
30
+ success = system("git -C #{repo.bare_path} worktree add -b #{branch} #{worktree.path} #{default_branch}")
31
+ end
32
+
33
+ raise Error, "Failed to create worktree" unless success
34
+
35
+ worktree
36
+ end
37
+
38
+ def self.remove(repo_name, branch, force: false)
39
+ repo = Repository.find(repo_name)
40
+ worktree = new(repo, branch)
41
+
42
+ raise Error, "Worktree '#{branch}' not found" unless worktree.exist?
43
+
44
+ # Remove worktree
45
+ force_flag = force ? "--force" : ""
46
+ success = system("git -C #{repo.bare_path} worktree remove #{force_flag} #{worktree.path}")
47
+
48
+ raise Error, "Failed to remove worktree" unless success
49
+
50
+ worktree
51
+ end
52
+
53
+ def self.list(repository)
54
+ return [] unless Dir.exist?(repository.tree_dir)
55
+
56
+ Dir.children(repository.tree_dir).map do |branch|
57
+ new(repository, branch)
58
+ end.select(&:exist?)
59
+ end
60
+
61
+ def exist?
62
+ Dir.exist?(path) && File.exist?(File.join(path, ".git"))
63
+ end
64
+ end
65
+ end
data/lib/gw.rb ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "gw/version"
4
+ require_relative "gw/errors"
5
+ require_relative "gw/config"
6
+ require_relative "gw/github"
7
+ require_relative "gw/repository"
8
+ require_relative "gw/worktree"
9
+ require_relative "gw/cli"
10
+
11
+ module Gw
12
+ end
data/sig/gw.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Gw
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,125 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gw
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - AILERON
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: octokit
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '9.0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '9.0'
26
+ - !ruby/object:Gem::Dependency
27
+ name: bundler
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ - !ruby/object:Gem::Dependency
41
+ name: rake
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ type: :development
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ - !ruby/object:Gem::Dependency
55
+ name: rspec
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '3.0'
61
+ type: :development
62
+ prerelease: false
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '3.0'
68
+ description: A CLI tool to manage git worktrees using bare repository pattern (core/
69
+ and tree/ structure)
70
+ email:
71
+ - masa@aileron.cc
72
+ executables:
73
+ - gw
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".github/workflows/main.yml"
78
+ - ".gitignore"
79
+ - ".rspec"
80
+ - ".rubocop.yml"
81
+ - AGENTS.md
82
+ - CHANGELOG.md
83
+ - CODE_OF_CONDUCT.md
84
+ - Gemfile
85
+ - Gemfile.lock
86
+ - LICENSE.txt
87
+ - README.md
88
+ - Rakefile
89
+ - bin/console
90
+ - bin/setup
91
+ - exe/gw
92
+ - gw.gemspec
93
+ - lib/gw.rb
94
+ - lib/gw/cli.rb
95
+ - lib/gw/config.rb
96
+ - lib/gw/errors.rb
97
+ - lib/gw/github.rb
98
+ - lib/gw/repository.rb
99
+ - lib/gw/version.rb
100
+ - lib/gw/worktree.rb
101
+ - sig/gw.rbs
102
+ homepage: https://github.com/aileron-inc/tools
103
+ licenses:
104
+ - MIT
105
+ metadata:
106
+ homepage_uri: https://github.com/aileron-inc/tools
107
+ source_code_uri: https://github.com/aileron-inc/tools
108
+ rdoc_options: []
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ requirements: []
122
+ rubygems_version: 3.6.9
123
+ specification_version: 4
124
+ summary: Git worktree manager with bare repository pattern
125
+ test_files: []