git-jump 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: 880531bf60be8fc8c6ec01873f77a37681d077384f7f7ad1f161a26b3644298c
4
+ data.tar.gz: 427e6a3ca62fcf5f073dc14fc74cf9fb6bb2e6e066888d491ac5643c7a44d2c7
5
+ SHA512:
6
+ metadata.gz: bb3594881a0ec21a4e449ae69f4ce7650fc0938ee076aabfedf8b09ad9bbd6d20ee4db34582cf9c4db853a7e97d85a8ce9f3d2c663ab4d3ea81d1f28687115c2
7
+ data.tar.gz: cd11e8e1ca1d54787e7ecc394ea6f4c8aaf409f0e135d68443e36816ce6bcd5e37a6c67a070c277ec6305582ece96954fbc2e4b626f5be4bc99979582b3aed4e
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2025-11-03
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/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 David Sáenz
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,355 @@
1
+ # Git::Jump
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/git-jump.svg)](https://rubygems.org/gems/git-jump)
4
+ [![CI](https://github.com/dsaenztagarro/git-jump/actions/workflows/main.yml/badge.svg)](https://github.com/dsaenztagarro/git-jump/actions)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
+ [![Ruby Version](https://img.shields.io/badge/ruby-%3E%3D%203.2-blue)](https://www.ruby-lang.org/)
7
+
8
+ A CLI tool for tracking and quickly switching between git branches across projects. Git::Jump automatically tracks your branch history and lets you jump between recently visited branches with ease.
9
+
10
+ ## Features
11
+
12
+ - **Automatic Branch Tracking**: Install a git hook to automatically track branches when you check them out
13
+ - **Manual Branch Management**: Add, list, and clear tracked branches
14
+ - **Quick Branch Switching**: Jump to the next branch or a specific branch by index
15
+ - **Smart Branch Ordering**: Branches are ordered by most recently visited
16
+ - **Project-Specific Tracking**: Separate branch history for each git repository
17
+ - **Configurable Keep Patterns**: Define which branches to keep when clearing (e.g., main, master, develop)
18
+ - **XDG Base Directory Support**: Configuration and data files follow XDG standards
19
+ - **Beautiful Terminal Output**: Colored output and formatted tables for easy reading
20
+
21
+ ## Installation
22
+
23
+ Install the gem by executing:
24
+
25
+ ```bash
26
+ gem install git-jump
27
+ ```
28
+
29
+ Or add it to your application's Gemfile:
30
+
31
+ ```bash
32
+ bundle add git-jump
33
+ ```
34
+
35
+ ## Quick Start
36
+
37
+ 1. Initialize the configuration file:
38
+ ```bash
39
+ git-jump setup
40
+ ```
41
+
42
+ 2. Navigate to a git repository and install the post-checkout hook:
43
+ ```bash
44
+ cd /path/to/your/repo
45
+ git-jump install
46
+ ```
47
+
48
+ 3. Now branches will be automatically tracked when you check them out! Or add branches manually:
49
+ ```bash
50
+ git-jump add feature/my-branch
51
+ ```
52
+
53
+ 4. List tracked branches:
54
+ ```bash
55
+ git-jump list
56
+ ```
57
+
58
+ 5. Jump to the next branch in the list:
59
+ ```bash
60
+ git-jump jump
61
+ ```
62
+
63
+ 6. Or jump to a specific branch by index:
64
+ ```bash
65
+ git-jump jump 3
66
+ ```
67
+
68
+ ## Usage
69
+
70
+ ### Commands
71
+
72
+ #### `git-jump setup`
73
+ Initialize the configuration file at `~/.config/git-jump/config.toml` (or `$XDG_CONFIG_HOME/git-jump/config.toml`).
74
+
75
+ ```bash
76
+ git-jump setup
77
+ ```
78
+
79
+ #### `git-jump install`
80
+ Install the post-checkout git hook in the current repository. This enables automatic branch tracking whenever you checkout a branch.
81
+
82
+ ```bash
83
+ cd /path/to/your/repo
84
+ git-jump install
85
+ ```
86
+
87
+ #### `git-jump add BRANCH`
88
+ Manually add a branch to tracking for the current project.
89
+
90
+ ```bash
91
+ git-jump add feature/my-branch
92
+ ```
93
+
94
+ #### `git-jump list`
95
+ List all tracked branches for the current project. Branches are displayed with an index number and sorted by most recently visited.
96
+
97
+ ```bash
98
+ git-jump list
99
+ ```
100
+
101
+ Output example:
102
+ ```
103
+ Tracked Branches
104
+ ────────────────
105
+ ┌─────┬────────────────┬──────────────┐
106
+ │ # │ Branch │ Last Visited │
107
+ ├─────┼────────────────┼──────────────┤
108
+ │ → 1 │ feature/auth │ just now │
109
+ │ 2 │ feature/api │ 2 hours ago │
110
+ │ 3 │ master │ 1 day ago │
111
+ └─────┴────────────────┴──────────────┘
112
+ ```
113
+
114
+ #### `git-jump jump [INDEX]`
115
+ Jump to the next branch in the list, or to a specific branch by index.
116
+
117
+ ```bash
118
+ # Jump to the next branch
119
+ git-jump jump
120
+
121
+ # Jump to branch at index 3
122
+ git-jump jump 3
123
+ ```
124
+
125
+ #### `git-jump clear`
126
+ Clear branches that don't match the keep patterns defined in your configuration. This is useful for cleaning up old feature branches while preserving important branches like main, master, etc.
127
+
128
+ ```bash
129
+ git-jump clear
130
+ ```
131
+
132
+ You'll be prompted to confirm before clearing.
133
+
134
+ #### `git-jump status`
135
+ Show the current status, configuration, and tracking statistics.
136
+
137
+ ```bash
138
+ git-jump status
139
+ ```
140
+
141
+ Output example:
142
+ ```
143
+ Git Jump Status
144
+ ───────────────
145
+ ℹ Project: my-project
146
+ ℹ Path: /Users/me/code/my-project
147
+ ℹ Current branch: feature/auth
148
+
149
+ Configuration
150
+ ─────────────
151
+ ℹ Config file: /Users/me/.config/git-jump/config.toml
152
+ ℹ Config exists: Yes
153
+ ℹ Database: /Users/me/.local/share/git-jump/branches.db
154
+ ℹ Max branches: 20
155
+ ℹ Auto-track: Enabled
156
+ ℹ Keep patterns: ^main$, ^master$, ^develop$, ^staging$
157
+
158
+ Hook Status
159
+ ───────────
160
+ ℹ Post-checkout hook: Installed
161
+
162
+ Tracking Statistics
163
+ ───────────────────
164
+ ℹ Total branches tracked: 5
165
+ ℹ Most recent: feature/auth
166
+ ```
167
+
168
+ #### `git-jump version`
169
+ Show the current version of git-jump.
170
+
171
+ ```bash
172
+ git-jump version
173
+ ```
174
+
175
+ ### Global Options
176
+
177
+ All commands support these global options:
178
+
179
+ - `--config PATH` or `-c PATH`: Use a custom configuration file
180
+ - `--quiet` or `-q`: Suppress output
181
+ - `--verbose` or `-v`: Enable verbose output
182
+
183
+ Example:
184
+ ```bash
185
+ git-jump --config ~/my-config.toml list
186
+ git-jump -q jump
187
+ git-jump -v status
188
+ ```
189
+
190
+ ## Configuration
191
+
192
+ Git::Jump uses a TOML configuration file located at `~/.config/git-jump/config.toml` (or `$XDG_CONFIG_HOME/git-jump/config.toml`).
193
+
194
+ Run `git-jump setup` to create the default configuration file.
195
+
196
+ ### Configuration Options
197
+
198
+ ```toml
199
+ [database]
200
+ # SQLite database location (defaults to XDG_DATA_HOME/git-jump/branches.db)
201
+ # You can use environment variables like $XDG_DATA_HOME or $HOME
202
+ path = "$XDG_DATA_HOME/git-jump/branches.db"
203
+
204
+ [tracking]
205
+ # Maximum number of branches to track per project
206
+ max_branches = 20
207
+
208
+ # Automatically track branches on checkout (via git hook)
209
+ auto_track = true
210
+
211
+ # Global branch patterns to always keep when clearing (regex patterns)
212
+ keep_patterns = ["^main$", "^master$", "^develop$", "^staging$"]
213
+
214
+ # Example project-specific configuration
215
+ # [[projects]]
216
+ # name = "my-project"
217
+ # path = "/path/to/my-project"
218
+ # keep_patterns = ["^main$", "^feature/.*$"]
219
+ ```
220
+
221
+ ### Keep Patterns
222
+
223
+ Keep patterns are regex patterns that define which branches should be preserved when running `git-jump clear`. By default, common main branches are kept:
224
+
225
+ - `^main$` - main branch
226
+ - `^master$` - master branch
227
+ - `^develop$` - develop branch
228
+ - `^staging$` - staging branch
229
+
230
+ You can customize these patterns globally or per-project in your configuration file.
231
+
232
+ ### XDG Base Directory Support
233
+
234
+ Git::Jump follows the XDG Base Directory Specification:
235
+
236
+ - **Configuration**: `$XDG_CONFIG_HOME/git-jump/config.toml` (defaults to `~/.config/git-jump/config.toml`)
237
+ - **Data**: `$XDG_DATA_HOME/git-jump/branches.db` (defaults to `~/.local/share/git-jump/branches.db`)
238
+ - **Cache**: `$XDG_CACHE_HOME/git-jump/` (defaults to `~/.cache/git-jump/`)
239
+
240
+ ## Usage Examples
241
+
242
+ ### Typical Workflow
243
+
244
+ ```bash
245
+ # First time setup
246
+ git-jump setup
247
+
248
+ # In your project directory
249
+ cd ~/code/my-project
250
+ git-jump install
251
+
252
+ # Work on different branches
253
+ git checkout feature/authentication
254
+ git checkout feature/api
255
+ git checkout feature/ui
256
+
257
+ # List your tracked branches
258
+ git-jump list
259
+ # Output:
260
+ # Tracked Branches
261
+ # ────────────────
262
+ # ┌─────┬─────────────────────────┬──────────────┐
263
+ # │ # │ Branch │ Last Visited │
264
+ # ├─────┼─────────────────────────┼──────────────┤
265
+ # │ → 1 │ feature/ui │ just now │
266
+ # │ 2 │ feature/api │ 5 minutes ago│
267
+ # │ 3 │ feature/authentication │ 10 minutes ago│
268
+ # └─────┴─────────────────────────┴──────────────┘
269
+
270
+ # Jump to the next branch (feature/api)
271
+ git-jump jump
272
+
273
+ # Jump to a specific branch by index
274
+ git-jump jump 3 # Switches to feature/authentication
275
+
276
+ # Clean up old feature branches (keeps main/master/develop/staging)
277
+ git-jump clear
278
+ ```
279
+
280
+ ### Working Across Multiple Projects
281
+
282
+ Git::Jump tracks branches per project, so you can use it across all your repositories:
283
+
284
+ ```bash
285
+ # Project A
286
+ cd ~/code/project-a
287
+ git-jump install
288
+ git checkout feature/new-ui
289
+ git checkout feature/refactor
290
+
291
+ # Project B
292
+ cd ~/code/project-b
293
+ git-jump install
294
+ git checkout bugfix/login
295
+ git checkout feature/dashboard
296
+
297
+ # Each project maintains its own branch history
298
+ cd ~/code/project-a
299
+ git-jump list # Shows only project-a branches
300
+
301
+ cd ~/code/project-b
302
+ git-jump list # Shows only project-b branches
303
+ ```
304
+
305
+ ### Using Custom Configuration
306
+
307
+ ```bash
308
+ # Use a custom config file
309
+ git-jump --config ~/my-custom-config.toml status
310
+
311
+ # Run commands quietly (no output)
312
+ git-jump -q jump
313
+
314
+ # Verbose output for debugging
315
+ git-jump -v add feature/new-feature
316
+ ```
317
+
318
+ ## How It Works
319
+
320
+ Git::Jump tracks your branch history in a SQLite database. Each time you check out a branch (with the hook installed) or manually add a branch, it's recorded in the database with:
321
+
322
+ - Project path and name
323
+ - Branch name
324
+ - Last visited timestamp
325
+ - Position in the branch list
326
+
327
+ Branches are automatically reordered based on when they were last visited, so the most recently used branches appear at the top of the list. This makes it easy to jump between branches you're actively working on.
328
+
329
+ When you run `git-jump jump`, it checks out the next branch in the list (or the branch at the specified index) and updates the last visited timestamp, moving it to the top of the list.
330
+
331
+ ### Post-Checkout Hook
332
+
333
+ When you run `git-jump install`, it creates a post-checkout hook in `.git/hooks/post-checkout` that automatically tracks branches when you check them out using `git checkout`. The hook is safe and will not interfere with existing hooks if you chain them properly.
334
+
335
+ ## Development
336
+
337
+ 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.
338
+
339
+ 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).
340
+
341
+ ## Contributing
342
+
343
+ Bug reports and pull requests are welcome on GitHub at https://github.com/dsaenzriv/git-jump. 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/dsaenzriv/git-jump/blob/master/CODE_OF_CONDUCT.md).
344
+
345
+ ## License
346
+
347
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
348
+
349
+ ## Code of Conduct
350
+
351
+ Everyone interacting in the Git::Jump project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/dsaenzriv/git-jump/blob/master/CODE_OF_CONDUCT.md).
352
+
353
+ ## Acknowledgments
354
+
355
+ Inspired by the need to quickly switch between feature branches during development. Architecture follows the modular design patterns from [dotsync](https://github.com/dotboris/dotsync).
data/Rakefile ADDED
@@ -0,0 +1,33 @@
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]
13
+
14
+ namespace :release do
15
+ desc "Tag git with the current GitJump::VERSION"
16
+ task :tag do
17
+ require_relative "lib/git_jump/version"
18
+ version = GitJump::VERSION
19
+ tag_name = "v#{version}"
20
+
21
+ # Check if tag already exists
22
+ if `git tag --list`.split.include?(tag_name)
23
+ puts "Tag #{tag_name} already exists."
24
+ exit(1)
25
+ end
26
+
27
+ puts "Tagging commit as #{tag_name}..."
28
+ sh "git tag -a #{tag_name} -m 'Release #{tag_name}'"
29
+ puts "Pushing tag #{tag_name} to origin..."
30
+ sh "git push origin #{tag_name}"
31
+ puts "Done!"
32
+ end
33
+ end
data/db/schema.rb ADDED
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "sqlite3"
4
+
5
+ def setup_database
6
+ db = SQLite3::Database.new File.join(Dir.home, ".git_jump.sqlite3")
7
+
8
+ db.execute <<-SQL
9
+ CREATE TABLE IF NOT EXISTS branches (
10
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
11
+ project_name TEXT NOT NULL,
12
+ branch_name TEXT NOT NULL,
13
+ created_at DATETIME DEFAULT CURRENT_TIMESTAMP
14
+ );
15
+ SQL
16
+
17
+ db
18
+ end
data/exe/git-jump ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ # Load only the minimal git_jump library
5
+ require_relative "../lib/git_jump"
6
+
7
+ # Lazy-load CLI when needed
8
+ require_relative "../lib/git_jump/cli"
9
+
10
+ GitJump::CLI.start(ARGV)
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GitJump
4
+ class Action
5
+ def initialize(repository_path)
6
+ @repository_path = repository_path
7
+ # @db = setup_database
8
+ end
9
+
10
+ def add(branch_name)
11
+ project_name = File.basename(Dir.pwd)
12
+
13
+ puts "GitJump::Action#add project_name: #{project_name}"
14
+
15
+ # @db.execute(
16
+ # 'INSERT INTO branches (project_name, branch_name) VALUES (?, ?)',
17
+ # [project_name, branch_name]
18
+ # )
19
+
20
+ puts "Branch '#{branch_name}' added for project '#{project_name}'"
21
+ end
22
+
23
+ def toggle
24
+ project_name = File.basename(Dir.pwd)
25
+
26
+ branches = @db.execute(
27
+ "SELECT branch_name FROM branches WHERE project_name = ?",
28
+ [project_name]
29
+ ).map(&:first)
30
+
31
+ if branches.empty?
32
+ puts "No branches found for project '#{project_name}'"
33
+ return
34
+ end
35
+
36
+ current_branch = `git branch --show-current`.strip
37
+ next_branch = branches[(branches.index(current_branch) || -1) + 1] || branches.first
38
+
39
+ system("git checkout #{next_branch}")
40
+ puts "Switched to branch '#{next_branch}'"
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "base"
4
+
5
+ module GitJump
6
+ module Actions
7
+ # Action to manually add a branch to tracking
8
+ class Add < Base
9
+ attr_reader :branch_name, :verify
10
+
11
+ def initialize(branch_name:, verify: true, **)
12
+ super(**)
13
+ @branch_name = branch_name
14
+ @verify = verify
15
+ end
16
+
17
+ def execute
18
+ if verify && !repository.branch_exists?(branch_name)
19
+ output.error("Branch '#{branch_name}' does not exist in repository")
20
+ return false
21
+ end
22
+
23
+ database.add_branch(project_id, branch_name)
24
+ output.success("Added branch '#{branch_name}' to tracking for #{repository.project_basename}")
25
+
26
+ # Check if we've exceeded max_branches
27
+ total = database.count_branches(project_id)
28
+ max = config.max_branches
29
+
30
+ output.warning("Project has #{total} branches (max: #{max}). Consider running 'git-jump clear'") if total > max
31
+
32
+ true
33
+ end
34
+ end
35
+ end
36
+ end