ctree 0.5.4 → 0.5.5
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 +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +8 -8
- data/lib/ctree/cli.rb +0 -1
- data/lib/ctree/free.rb +30 -8
- data/lib/ctree/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8ef0c528d52a2d9fef65f64d67341972783baaaac2dec877a760fa0ac55f2359
|
|
4
|
+
data.tar.gz: b48b547b46a9c02e82ec6ebcf22d29e48338d617bc85a7e95f2a32ee773870ab
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4f92fea22adb1c0555d90954ebc36f5e256e83ad6f67921797fc3bd13730272f2790f860b0673d8839ea306c3b9deecbb9c696b6c2241cbcd28bcf2cf4e6e419
|
|
7
|
+
data.tar.gz: 389c6ebdbfa98c3cfc213c8a5320dece53e019adcab2b9aa0b5be9ce5c97b07fdf4a2affff06c41bfb1ad0d84f8873b69d4647a795dbe35d057b04864e90a5d3
|
data/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.5.5] - 2026-11-30
|
|
11
|
+
|
|
12
|
+
- Fixed `ctree free` creating a new placeholder branch from
|
|
13
|
+
the current HEAD instead of the default branch
|
|
14
|
+
|
|
10
15
|
## [0.5.4] - 2026-10-19
|
|
11
16
|
|
|
12
17
|
- Added a Rakefile for standard local build flow
|
data/README.md
CHANGED
|
@@ -193,17 +193,17 @@ Run **from inside a worktree** (no arguments). Resets the worktree to a free
|
|
|
193
193
|
placeholder branch so it can be reused. ctree:
|
|
194
194
|
|
|
195
195
|
1. Lists all local branches whose names start with the configured
|
|
196
|
-
|
|
196
|
+
`free_branch_prefix` (default `FREE-`).
|
|
197
197
|
2. Checks out the first available branch — one not currently checked out in
|
|
198
|
-
|
|
198
|
+
any worktree — sorted alphabetically.
|
|
199
199
|
3. If all free branches are occupied, creates the next sequential one,
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
200
|
+
filling gaps in the numeric sequence. For example, if `FREE-001` and
|
|
201
|
+
`FREE-003` both exist and are checked out, it creates and checks out
|
|
202
|
+
`FREE-002`. If no free branches exist at all, it creates `FREE-001`.
|
|
203
|
+
Numbers are zero-padded to at least 3 digits (`FREE-001`, `FREE-002`, …).
|
|
204
204
|
4. Rebases the checked-out branch onto the source repo's `master` (skipped
|
|
205
|
-
|
|
206
|
-
|
|
205
|
+
automatically if already up to date). Aborts and reports on conflict —
|
|
206
|
+
resolve manually and re-run `ctree rebase` from the worktree.
|
|
207
207
|
|
|
208
208
|
### env
|
|
209
209
|
|
data/lib/ctree/cli.rb
CHANGED
|
@@ -138,7 +138,6 @@ module Ctree
|
|
|
138
138
|
"FREE-"). If all are occupied, creates the next sequential one, filling gaps
|
|
139
139
|
(FREE-001 + FREE-003 occupied → creates FREE-002). The prefix is configurable
|
|
140
140
|
via free_branch_prefix in .ctree/config.yml.
|
|
141
|
-
|
|
142
141
|
HELP
|
|
143
142
|
"env" => <<~HELP,
|
|
144
143
|
Usage:
|
data/lib/ctree/free.rb
CHANGED
|
@@ -32,20 +32,25 @@ module Ctree
|
|
|
32
32
|
current_branch_out, _, cb_st = Sh.capture3("git", "-C", target_path.to_s, "rev-parse", "--abbrev-ref", "HEAD")
|
|
33
33
|
Log.die "could not resolve current branch" unless cb_st.success?
|
|
34
34
|
current_branch = current_branch_out.strip
|
|
35
|
+
default_branch = Git.detect_default_branch(source_root)
|
|
36
|
+
|
|
35
37
|
if !prefix.empty? && current_branch.start_with?(prefix)
|
|
38
|
+
ahead = commits_ahead(source_root, default_branch, current_branch)
|
|
39
|
+
warn_polluted_current(current_branch, ahead, default_branch) unless ahead.zero?
|
|
36
40
|
Log.info "already on a free branch (#{current_branch}); nothing to do"
|
|
37
41
|
exit 0
|
|
38
42
|
end
|
|
39
|
-
|
|
40
43
|
branches_out, _, branches_st = Sh.capture3("git", "-C", source_root.to_s, "branch", "--list", "#{prefix}*")
|
|
41
44
|
Log.die "git branch --list failed" unless branches_st.success?
|
|
42
45
|
all_free = branches_out.lines.map { |l| l.sub(/\A[*+ ] /, "").strip }.reject(&:empty?).sort
|
|
43
|
-
|
|
44
46
|
worktree_raw, _, wt_st = Sh.capture3("git", "-C", source_root.to_s, "worktree", "list", "--porcelain")
|
|
45
47
|
Log.die "git worktree list failed" unless wt_st.success?
|
|
46
48
|
occupied = List.parse_worktree_porcelain(worktree_raw).filter_map { |e| e[:branch] }.to_set
|
|
47
|
-
|
|
48
|
-
|
|
49
|
+
branch = first_available_branch(all_free, occupied) do |candidate|
|
|
50
|
+
ahead = commits_ahead(source_root, default_branch, candidate)
|
|
51
|
+
warn_stale_placeholder(candidate, ahead, default_branch) unless ahead.zero?
|
|
52
|
+
ahead.zero?
|
|
53
|
+
end
|
|
49
54
|
if branch
|
|
50
55
|
_, err, st = Spinner.with_spinner("checking out #{branch}") do
|
|
51
56
|
Sh.capture3("git", "-C", target_path.to_s, "checkout", branch)
|
|
@@ -54,18 +59,35 @@ module Ctree
|
|
|
54
59
|
else
|
|
55
60
|
branch = next_sequential_branch(prefix, all_free)
|
|
56
61
|
_, err, st = Spinner.with_spinner("checking out #{branch}") do
|
|
57
|
-
Sh.capture3("git", "-C", target_path.to_s, "checkout", "-b", branch)
|
|
62
|
+
Sh.capture3("git", "-C", target_path.to_s, "checkout", "--no-track", "-b", branch, default_branch)
|
|
58
63
|
end
|
|
59
64
|
Log.die "git checkout -b #{branch} failed: #{err.strip}" unless st.success?
|
|
60
65
|
end
|
|
61
66
|
Log.info "checked out #{branch}"
|
|
62
|
-
|
|
63
|
-
default_branch = Git.detect_default_branch(source_root)
|
|
64
67
|
Rebase.rebase_branch_onto_default(target_path, branch, default_branch)
|
|
65
68
|
end
|
|
66
69
|
|
|
67
70
|
def first_available_branch(all_free, occupied)
|
|
68
|
-
all_free.sort.find { |b| !occupied.include?(b) }
|
|
71
|
+
all_free.sort.find { |b| !occupied.include?(b) && (!block_given? || yield(b)) }
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def commits_ahead(source_root, default_branch, branch)
|
|
75
|
+
out, err, st = Sh.capture3("git", "-C", source_root.to_s,
|
|
76
|
+
"rev-list", "--count", "#{default_branch}..#{branch}")
|
|
77
|
+
Log.die "git rev-list #{default_branch}..#{branch} failed: #{err.strip}" unless st.success?
|
|
78
|
+
out.strip.to_i
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def warn_stale_placeholder(branch, ahead, default_branch)
|
|
82
|
+
noun = ahead == 1 ? "commit" : "commits"
|
|
83
|
+
Log.warn_ "skipping #{branch}: #{ahead} #{noun} not on #{default_branch} " \
|
|
84
|
+
"(see: git log #{default_branch}..#{branch}). Move that work to a named branch to reuse it."
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def warn_polluted_current(branch, ahead, default_branch)
|
|
88
|
+
noun = ahead == 1 ? "commit" : "commits"
|
|
89
|
+
Log.warn_ "#{branch} has #{ahead} #{noun} not on #{default_branch} " \
|
|
90
|
+
"(see: git log #{default_branch}..#{branch}). Move that work to a named branch, then reset the placeholder."
|
|
69
91
|
end
|
|
70
92
|
|
|
71
93
|
def next_sequential_branch(prefix, all_free)
|
data/lib/ctree/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ctree
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.5.
|
|
4
|
+
version: 0.5.5
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- mytrak
|
|
@@ -74,7 +74,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
74
74
|
- !ruby/object:Gem::Version
|
|
75
75
|
version: '0'
|
|
76
76
|
requirements: []
|
|
77
|
-
rubygems_version:
|
|
77
|
+
rubygems_version: 4.0.23
|
|
78
78
|
specification_version: 4
|
|
79
79
|
summary: Run multiple branches of a Docker-compose repo side by side
|
|
80
80
|
test_files: []
|