sugarjar 0.0.9 → 0.0.10
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/LICENSE +1 -1
- data/README.md +18 -2
- data/bin/sj +8 -3
- data/lib/sugarjar/commands.rb +72 -37
- data/lib/sugarjar/version.rb +1 -1
- data/sugarjar.gemspec +3 -0
- metadata +9 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a1c65749738fac53cfb69c3ec42007433f7598e3e43dd36e33217c8c0efbbb2e
|
4
|
+
data.tar.gz: 50288abc1d21962e793731a937a8dd886bd2674db269ed62fbb0f89bb4121850
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 97ca2433bccc9e15d8c86ab141fa74e8f441f62cdb2be16e3131e2dcf71b37319ed0399990a96cb8c34ee4c55e75f1eca8a652cd5c7031f272493eec3fdb0f9a
|
7
|
+
data.tar.gz: 5395379c1ca16bc50c900cd75a4b72665c0079dfe48f8717d38640d4ba610cc571c5f407333e088c0c387f19dc620039e3a406f03d6d6ea4a72a7348b98e7a41
|
data/LICENSE
CHANGED
@@ -186,7 +186,7 @@
|
|
186
186
|
same "printed page" as the copyright notice for easier
|
187
187
|
identification within third-party archives.
|
188
188
|
|
189
|
-
Copyright
|
189
|
+
Copyright 2020-present Phil Dibowitz
|
190
190
|
|
191
191
|
Licensed under the Apache License, Version 2.0 (the "License");
|
192
192
|
you may not use this file except in compliance with the License.
|
data/README.md
CHANGED
@@ -244,8 +244,8 @@ yaml file is a straight key-value pair of options without their '--'. For
|
|
244
244
|
example:
|
245
245
|
|
246
246
|
```yaml
|
247
|
-
|
248
|
-
|
247
|
+
log_level: debug
|
248
|
+
github_user: jaymzh
|
249
249
|
```
|
250
250
|
|
251
251
|
In addition, the environment variable `SUGARJAR_DEBUG` can be defined to set
|
@@ -312,6 +312,22 @@ sj clone jaymzh/sugarjar --github-host githuh.com
|
|
312
312
|
We will add the `hub.host` to the `sugarjar` clone so that future `hub` or `sj`
|
313
313
|
commands work without needing to specify..
|
314
314
|
|
315
|
+
## Installing
|
316
|
+
|
317
|
+
There are many ways to install SugarJar. The easiest is to use one of the
|
318
|
+
packages we provide in the
|
319
|
+
[releases](https://github.com/jaymzh/sugarjar/releases) section. Currently we
|
320
|
+
provide packages for Fedora, CentOS, Debian, and Ubuntu, but if you want
|
321
|
+
others, file an Issue. Since these packages are
|
322
|
+
[omnibus](https://github.com/chef/omnibus) packages which means they are bundled
|
323
|
+
with all of their dependencies. This means these packages will likely work as-is
|
324
|
+
on later releases of these distros or any similar distros.
|
325
|
+
|
326
|
+
We also distribute SugarJar via [RubyGems](https://rubygems.org/gems/sugarjar/),
|
327
|
+
so you can install it as a gem either via system ruby or via rvm/rbenv.
|
328
|
+
|
329
|
+
Finally you can clone the git repo and run it from within the repo if you'd like.
|
330
|
+
|
315
331
|
## FAQ
|
316
332
|
|
317
333
|
Why the name SugarJar?
|
data/bin/sj
CHANGED
@@ -182,19 +182,23 @@ extra_opts = []
|
|
182
182
|
config = SugarJar::Config.config
|
183
183
|
|
184
184
|
valid_commands = sj.public_methods - Object.public_methods
|
185
|
-
|
186
|
-
|
185
|
+
possible_valid_command = ARGV.any? do |arg|
|
186
|
+
valid_commands.include?(arg.to_s.to_sym)
|
187
|
+
end
|
187
188
|
|
188
189
|
# if we're configured to fall thru and the subcommand isn't one
|
189
190
|
# we recognize, don't parse the options as they may be different
|
190
191
|
# than git's. For example `git config -l` - we error because we
|
191
192
|
# require an arguement to `-l`.
|
192
|
-
if config['fallthru'] && !
|
193
|
+
if config['fallthru'] && !possible_valid_command
|
193
194
|
SugarJar::Log.debug(
|
194
195
|
'Skipping option parsing: fall-thru is set and we do not recognize ' +
|
195
196
|
'any subcommands',
|
196
197
|
)
|
197
198
|
else
|
199
|
+
SugarJar::Log.debug(
|
200
|
+
'We MIGHT have a valid command... parse-command line options',
|
201
|
+
)
|
198
202
|
# We want to allow people to pass in extra args to be passed to
|
199
203
|
# git commands, but OptionParser doesn't easily allow this. So we
|
200
204
|
# loop over it, catching exceptions.
|
@@ -240,6 +244,7 @@ SugarJar::Log.level = options['log_level'].to_sym if options['log_level']
|
|
240
244
|
sj = SugarJar::Commands.new(options)
|
241
245
|
|
242
246
|
subcommand = argv_copy.reject { |x| x.start_with?('-') }.first
|
247
|
+
is_valid_command = valid_commands.include?(subcommand.to_sym)
|
243
248
|
argv_copy.delete(subcommand)
|
244
249
|
SugarJar::Log.debug("subcommand is #{subcommand}")
|
245
250
|
|
data/lib/sugarjar/commands.rb
CHANGED
@@ -12,6 +12,8 @@ class SugarJar
|
|
12
12
|
class Commands
|
13
13
|
include SugarJar::Util
|
14
14
|
|
15
|
+
MAIN_BRANCHES = %w{master main}.freeze
|
16
|
+
|
15
17
|
def initialize(options)
|
16
18
|
SugarJar::Log.debug("Commands.initialize options: #{options}")
|
17
19
|
@ghuser = options['github_user']
|
@@ -30,7 +32,7 @@ class SugarJar
|
|
30
32
|
assert_in_repo
|
31
33
|
SugarJar::Log.debug("Feature: #{name}, #{base}")
|
32
34
|
die("#{name} already exists!") if all_branches.include?(name)
|
33
|
-
base ||=
|
35
|
+
base ||= most_main
|
34
36
|
base_pieces = base.split('/')
|
35
37
|
hub('fetch', base_pieces[0]) if base_pieces.length > 1
|
36
38
|
hub('checkout', '-b', name, base)
|
@@ -57,8 +59,8 @@ class SugarJar
|
|
57
59
|
assert_in_repo
|
58
60
|
curr = current_branch
|
59
61
|
all_branches.each do |branch|
|
60
|
-
if branch
|
61
|
-
SugarJar::Log.debug(
|
62
|
+
if MAIN_BRANCHES.include?(branch)
|
63
|
+
SugarJar::Log.debug("Skipping #{branch}")
|
62
64
|
next
|
63
65
|
end
|
64
66
|
|
@@ -73,11 +75,11 @@ class SugarJar
|
|
73
75
|
end
|
74
76
|
end
|
75
77
|
|
76
|
-
# Return to the branch we were on, or
|
78
|
+
# Return to the branch we were on, or main
|
77
79
|
if all_branches.include?(curr)
|
78
80
|
hub('checkout', curr)
|
79
81
|
else
|
80
|
-
|
82
|
+
checkout_main_branch
|
81
83
|
end
|
82
84
|
end
|
83
85
|
|
@@ -105,7 +107,7 @@ class SugarJar
|
|
105
107
|
assert_in_repo
|
106
108
|
SugarJar::Log.info(hub(
|
107
109
|
'log', '--graph', '--oneline', '--decorate', '--boundary',
|
108
|
-
'--branches', "#{
|
110
|
+
'--branches', "#{most_main}.."
|
109
111
|
).stdout.chomp)
|
110
112
|
end
|
111
113
|
|
@@ -113,13 +115,22 @@ class SugarJar
|
|
113
115
|
|
114
116
|
def up
|
115
117
|
assert_in_repo
|
118
|
+
# get a copy of our current branch, if rebase fails, we won't
|
119
|
+
# be able to determine it without backing out
|
120
|
+
curr = current_branch
|
116
121
|
result = gitup
|
117
|
-
if result
|
118
|
-
|
119
|
-
"#{color(
|
122
|
+
if result['so'].error?
|
123
|
+
die(
|
124
|
+
"#{color(curr, :red)}: Failed to rebase on " +
|
125
|
+
"#{result['base']}. Leaving the repo as-is. You can get out of " +
|
126
|
+
'this with a `git rebase --abort`. Output from failed rebase is: ' +
|
127
|
+
"\nSTDOUT:\n#{result['so'].stdout.lines.map { |x| "\t#{x}" }.join}" +
|
128
|
+
"\nSTDERR:\n#{result['so'].stderr.lines.map { |x| "\t#{x}" }.join}",
|
120
129
|
)
|
121
130
|
else
|
122
|
-
|
131
|
+
SugarJar::Log.info(
|
132
|
+
"#{color(current_branch, :green)} rebased on #{result['base']}",
|
133
|
+
)
|
123
134
|
end
|
124
135
|
end
|
125
136
|
|
@@ -139,20 +150,21 @@ class SugarJar
|
|
139
150
|
def upall
|
140
151
|
assert_in_repo
|
141
152
|
all_branches.each do |branch|
|
142
|
-
next if branch
|
153
|
+
next if MAIN_BRANCHES.include?(branch)
|
143
154
|
|
144
155
|
hub('checkout', branch)
|
145
156
|
result = gitup
|
146
|
-
if result
|
147
|
-
SugarJar::Log.info(
|
148
|
-
"#{color(branch, :green)} rebased on #{color(result, :green)}",
|
149
|
-
)
|
150
|
-
else
|
157
|
+
if result['so'].error?
|
151
158
|
SugarJar::Log.error(
|
152
159
|
"#{color(branch, :red)} failed rebase. Reverting attempt and " +
|
153
|
-
'moving to next branch',
|
160
|
+
'moving to next branch. Try `sj up` manually on that branch.',
|
154
161
|
)
|
155
162
|
hub('rebase', '--abort')
|
163
|
+
else
|
164
|
+
SugarJar::Log.info(
|
165
|
+
"#{color(branch, :green)} rebased on " +
|
166
|
+
color(result['base'], :green).to_s,
|
167
|
+
)
|
156
168
|
end
|
157
169
|
end
|
158
170
|
end
|
@@ -180,12 +192,26 @@ class SugarJar
|
|
180
192
|
|
181
193
|
s = hub_nofail('fork', '--remote-name=origin')
|
182
194
|
if s.error?
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
195
|
+
if s.stdout.include?('SAML enforcement')
|
196
|
+
SugarJar::Log.info(
|
197
|
+
'Forking the repo failed because the repo requires SAML ' +
|
198
|
+
"authentication. Full output:\n\n\t#{s.stdout}",
|
199
|
+
)
|
200
|
+
exit(1)
|
201
|
+
else
|
202
|
+
# In old versions of hub, it would fail if the upstream fork
|
203
|
+
# already existed. If we got an error, but didn't recognize
|
204
|
+
# that, we'll assume that's what happened and try to add the
|
205
|
+
# remote ourselves.
|
206
|
+
SugarJar::Log.info("Fork (#{@ghuser}/#{reponame}) detected.")
|
207
|
+
SugarJar::Log.debug(
|
208
|
+
'The above is a bit of a lie. "hub" failed to fork and it was ' +
|
209
|
+
'not a SAML error, so our best guess is that a fork exists ' +
|
210
|
+
'and so we will try to configure it.',
|
211
|
+
)
|
212
|
+
hub('remote', 'rename', 'origin', 'upstream')
|
213
|
+
hub('remote', 'add', 'origin', forked_repo(repo, @ghuser))
|
214
|
+
end
|
189
215
|
else
|
190
216
|
SugarJar::Log.info("Forked #{reponame} to #{@ghuser}")
|
191
217
|
end
|
@@ -461,14 +487,22 @@ class SugarJar
|
|
461
487
|
die('sugarjar must be run from inside a git repo') unless in_repo
|
462
488
|
end
|
463
489
|
|
490
|
+
def main_branch
|
491
|
+
@main_branch = all_branches.include?('main') ? 'main' : 'master'
|
492
|
+
end
|
493
|
+
|
494
|
+
def checkout_main_branch
|
495
|
+
hub('checkout', main_branch)
|
496
|
+
end
|
497
|
+
|
464
498
|
def clean_branch(name)
|
465
|
-
die(
|
499
|
+
die("Cannot remove #{name} branch") if MAIN_BRANCHES.include?(name)
|
466
500
|
SugarJar::Log.debug('Fetch relevant remote...')
|
467
501
|
fetch_upstream
|
468
502
|
return false unless safe_to_clean(name)
|
469
503
|
|
470
504
|
SugarJar::Log.debug('branch deemed safe to delete...')
|
471
|
-
|
505
|
+
checkout_main_branch
|
472
506
|
hub('branch', '-D', name)
|
473
507
|
gitup
|
474
508
|
true
|
@@ -477,8 +511,6 @@ class SugarJar
|
|
477
511
|
def all_branches
|
478
512
|
branches = []
|
479
513
|
hub('branch', '--format', '%(refname)').stdout.lines.each do |line|
|
480
|
-
next if line == 'master'
|
481
|
-
|
482
514
|
branches << line.strip.split('/')[2]
|
483
515
|
end
|
484
516
|
branches
|
@@ -502,7 +534,7 @@ class SugarJar
|
|
502
534
|
|
503
535
|
# if the "easy" check didn't work, it's probably because there
|
504
536
|
# was a squash-merge. To check for that we make our own squash
|
505
|
-
# merge to upstream/
|
537
|
+
# merge to upstream/main and see if that has any delta
|
506
538
|
|
507
539
|
# First we need a temp branch to work on
|
508
540
|
tmpbranch = "_sugar_jar.#{Process.pid}"
|
@@ -512,7 +544,7 @@ class SugarJar
|
|
512
544
|
if s.error?
|
513
545
|
cleanup_tmp_branch(tmpbranch, branch)
|
514
546
|
SugarJar::Log.debug(
|
515
|
-
'Failed to merge changes into current
|
547
|
+
'Failed to merge changes into current main. This means we could ' +
|
516
548
|
'not figure out if this is merged or not. Check manually and use ' +
|
517
549
|
"'git branch -D #{branch}' if it is safe to do so.",
|
518
550
|
)
|
@@ -530,7 +562,7 @@ class SugarJar
|
|
530
562
|
true
|
531
563
|
else
|
532
564
|
SugarJar::Log.debug(
|
533
|
-
'After squash-merging, this branch is NOT fully merged to
|
565
|
+
'After squash-merging, this branch is NOT fully merged to main',
|
534
566
|
)
|
535
567
|
false
|
536
568
|
end
|
@@ -555,9 +587,8 @@ class SugarJar
|
|
555
587
|
SugarJar::Log.debug('Fetching upstream')
|
556
588
|
fetch_upstream
|
557
589
|
curr = current_branch
|
558
|
-
SugarJar::Log.debug('Rebasing')
|
559
590
|
base = tracked_branch
|
560
|
-
if curr
|
591
|
+
if !MAIN_BRANCHES.include?(curr) && base == "origin/#{curr}"
|
561
592
|
SugarJar::Log.warn(
|
562
593
|
"This branch is tracking origin/#{curr}, which is probably your " +
|
563
594
|
'downstream (where you push _to_) as opposed to your upstream ' +
|
@@ -566,8 +597,12 @@ class SugarJar
|
|
566
597
|
'to do a "git branch -u upstream".',
|
567
598
|
)
|
568
599
|
end
|
600
|
+
SugarJar::Log.debug('Rebasing')
|
569
601
|
s = hub_nofail('rebase', base)
|
570
|
-
|
602
|
+
{
|
603
|
+
'so' => s,
|
604
|
+
'base' => base,
|
605
|
+
}
|
571
606
|
end
|
572
607
|
|
573
608
|
def tracked_branch
|
@@ -575,18 +610,18 @@ class SugarJar
|
|
575
610
|
'rev-parse', '--abbrev-ref', '--symbolic-full-name', '@{u}'
|
576
611
|
)
|
577
612
|
if s.error?
|
578
|
-
|
613
|
+
most_main
|
579
614
|
else
|
580
615
|
s.stdout.strip
|
581
616
|
end
|
582
617
|
end
|
583
618
|
|
584
|
-
def
|
619
|
+
def most_main
|
585
620
|
us = upstream
|
586
621
|
if us
|
587
|
-
"#{us}
|
622
|
+
"#{us}/#{main_branch}"
|
588
623
|
else
|
589
|
-
|
624
|
+
main_branch
|
590
625
|
end
|
591
626
|
end
|
592
627
|
|
data/lib/sugarjar/version.rb
CHANGED
data/sugarjar.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sugarjar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Phil Dibowitz
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-08-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mixlib-log
|
@@ -52,7 +52,7 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
-
description:
|
55
|
+
description:
|
56
56
|
email:
|
57
57
|
- phil@ipom.com
|
58
58
|
executables:
|
@@ -78,8 +78,9 @@ files:
|
|
78
78
|
homepage: https://github.com/jaymzh/sugarjar
|
79
79
|
licenses:
|
80
80
|
- Apache-2.0
|
81
|
-
metadata:
|
82
|
-
|
81
|
+
metadata:
|
82
|
+
rubygems_mfa_required: 'true'
|
83
|
+
post_install_message:
|
83
84
|
rdoc_options: []
|
84
85
|
require_paths:
|
85
86
|
- lib
|
@@ -94,8 +95,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
94
95
|
- !ruby/object:Gem::Version
|
95
96
|
version: '0'
|
96
97
|
requirements: []
|
97
|
-
rubygems_version: 3.
|
98
|
-
signing_key:
|
98
|
+
rubygems_version: 3.3.15
|
99
|
+
signing_key:
|
99
100
|
specification_version: 4
|
100
101
|
summary: A git/github helper script
|
101
102
|
test_files: []
|