sugarjar 0.0.11 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +35 -24
- data/bin/sj +27 -9
- data/lib/sugarjar/commands.rb +51 -6
- data/lib/sugarjar/config.rb +1 -1
- data/lib/sugarjar/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: 95e4979017c0ed58f99c446d9215a6b64aec7d5ebc22694a95903710d5af9d7e
|
4
|
+
data.tar.gz: b4b7a648bc7e8002e46dfbaa73cc52749cd38258b5782a2b33a6d66db98facfc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0e34735382f6646bf5fe1577eb6637ad7aaceaa9ccf2d2dad024d4a95f3e2a0e8ec080fe086fd5dae7354b3f15f83d26e6ae8b067a1fae9fb5b3da777f9e1f86
|
7
|
+
data.tar.gz: 155d1aa1c7148f2d7181678f64ef64b17fb5efc90386ce3bd27c2bcc7b256113680b4e69a16558790ab3c77080325fc36a56c9f3cc76cf4962f8f575cd00d5d7
|
data/README.md
CHANGED
@@ -4,10 +4,16 @@
|
|
4
4
|
[![Unittest](https://github.com/jaymzh/sugarjar/workflows/Unittests/badge.svg)](https://github.com/jaymzh/sugarjar/actions?query=workflow%3AUnittests)
|
5
5
|
[![DCO](https://github.com/jaymzh/sugarjar/workflows/DCO%20Check/badge.svg)](https://github.com/jaymzh/sugarjar/actions?query=workflow%3A%22DCO+Check%22)
|
6
6
|
|
7
|
+
> [!IMPORTANT]
|
8
|
+
> You probably want to use [Sapling](https://sapling-scm.com/)
|
9
|
+
> instead of this! This was written as a stop-gap to approximate some features
|
10
|
+
> of the Facebook/Meta internal development tools before they were released.
|
11
|
+
> Now that those tools have been open-sourced and work with GitHub, this is
|
12
|
+
> likely to be deprecated at some point. Sapling is far more feature rich,
|
13
|
+
> faster, and have more development resources behind them.
|
14
|
+
|
7
15
|
Welcome to SugarJar - a git/github helper. It needs one of the GitHub CLI's:
|
8
|
-
|
9
|
-
experimental support for [gh](https://cli.github.com/). So you will need one of
|
10
|
-
those two installed.
|
16
|
+
either [gh](https://cli.github.com/) or the older [hub](https://hub.github.com/).
|
11
17
|
|
12
18
|
SugarJar is inspired by [arcanist](https://github.com/phacility/arcanist), and
|
13
19
|
its replacement at Facebook, JellyFish. Many of the features they provide for
|
@@ -27,6 +33,12 @@ list here, and if so, use your package manager (or `gem`) to install it:
|
|
27
33
|
|
28
34
|
[![Packaging status](https://repology.org/badge/vertical-allrepos/sugarjar.svg)](https://repology.org/project/sugarjar/versions)
|
29
35
|
|
36
|
+
For Ubuntu users, Sugarjar will likely be available starting in the upcoming
|
37
|
+
23.04 release. Until then, for supported LTS releases starting 20.04 (focal)
|
38
|
+
and the latest non-LTS release, you can use [this PPA](
|
39
|
+
https://launchpad.net/~michel-slm/+archive/ubuntu/sugarjar) maintained by the
|
40
|
+
Debian package maintainer.
|
41
|
+
|
30
42
|
Another option is to use our [omnibus
|
31
43
|
packages](https://github.com/jaymzh/sugarjar/releases). We keep Omnibus
|
32
44
|
packages for most distros that do not package Sugarjar. Omnibus packages are
|
@@ -279,8 +291,8 @@ log_level: debug
|
|
279
291
|
github_user: jaymzh
|
280
292
|
```
|
281
293
|
|
282
|
-
In addition, the environment variable `
|
283
|
-
|
294
|
+
In addition, the environment variable `SUGARJAR_LOGLEVEL` can be defined to set
|
295
|
+
a log level. This is primarily used as a way to turn debug on earlier in order to
|
284
296
|
troubleshoot configuration parsing.
|
285
297
|
|
286
298
|
## Repository Configuration
|
@@ -294,7 +306,7 @@ how to handle repo-specific things. Currently there options are:
|
|
294
306
|
per line. Takes precedence over `lint`. The command (and the resulting
|
295
307
|
linters) will be run from the root of the repo.
|
296
308
|
* `unit` - A list of scripts to run on `sj unit`. These should be unittest
|
297
|
-
runners like rspec or pyunit. Test will be run
|
309
|
+
runners like rspec or pyunit. Test will be run from the root of the repo.
|
298
310
|
* `unit_list_cmd` - A command to run which will print out the unit tests to
|
299
311
|
run, one more line. Takes precedence over `unit`. The command (and the
|
300
312
|
resulting unit tests) will be run from the root of the repo.
|
@@ -349,41 +361,40 @@ sj clone jaymzh/sugarjar --github-host githuh.com
|
|
349
361
|
We will add the `hub.host` to the `sugarjar` clone so that future `hub` or `sj`
|
350
362
|
commands work without needing to specify..
|
351
363
|
|
352
|
-
##
|
353
|
-
|
354
|
-
As of version 0.11 there is experimental support for the `gh` CLI (instead of
|
355
|
-
`hub`). If you would like to use `gh`, install it and then add the following
|
356
|
-
to your configuration:
|
364
|
+
## Choosing a GitHub CLI
|
357
365
|
|
358
|
-
|
359
|
-
|
360
|
-
|
366
|
+
SugarJar will use `gh` if it is available or otherwise fall back to `hub`. You
|
367
|
+
can override this by specifying `--github-cli` on the command line or setting
|
368
|
+
`github_cli` to either `gh` or `hub` (it defaults to `auto`) in your
|
369
|
+
configuration.
|
361
370
|
|
362
371
|
## FAQ
|
363
372
|
|
364
|
-
Why the name SugarJar
|
373
|
+
**Why the name SugarJar?**
|
365
374
|
|
366
|
-
It's mostly a
|
375
|
+
It's mostly a backronym. Like jellyfish, I wanted two letters that were on home
|
367
376
|
row on different sides of the keyboard to make it easy to type. I looked at the
|
368
377
|
possible options that where there and not taken and tried to find one I could
|
369
378
|
make an appropriate name out of. Since this utility adds lots of sugar to git
|
370
379
|
and github, it seemed appropriate.
|
371
380
|
|
372
|
-
Why did you use `hub` instead of the newer `gh` CLI
|
381
|
+
**Why did you originally use `hub` instead of the newer `gh` CLI?**
|
373
382
|
|
374
383
|
When I originally wrote SugarJar, `gh` was in early development, and `hub` had
|
375
|
-
many more features.
|
376
|
-
`
|
384
|
+
many more features. In addition, I wrote SugarJar to be a wrapper for git/hub,
|
385
|
+
and `hub` allows this but `gh` does not.
|
377
386
|
|
378
|
-
|
379
|
-
|
387
|
+
When `gh` matured, we added experimental `gh` support in 0.0.11, and switched the
|
388
|
+
default to prefer `gh` in 1.0.0.
|
380
389
|
|
381
|
-
I'd like to package SugarJar for my favorite distro/OS, is that OK
|
390
|
+
**I'd like to package SugarJar for my favorite distro/OS, is that OK?**
|
382
391
|
|
383
392
|
Of course! But I'd appreciate you emailing me to give me a heads up. Doing so
|
384
393
|
will allow me to make sure it shows up in the Repology badge above as well as
|
385
394
|
stop building Omnibus packages for whatever distro.
|
386
395
|
|
387
|
-
|
396
|
+
**What platforms does it work on?**
|
388
397
|
|
389
|
-
|
398
|
+
Since it's Ruby, it should work across all platforms, however, it's developed
|
399
|
+
and primarily tested on Linux as well as regularly used on Mac. I've not tested
|
400
|
+
it on Windows, but I'll happily accept patches for Windows compatibility.
|
data/bin/sj
CHANGED
@@ -29,15 +29,20 @@ parser = OptionParser.new do |opts|
|
|
29
29
|
opts.separator ''
|
30
30
|
opts.separator 'OPTIONS:'
|
31
31
|
|
32
|
-
opts.on('--[no-]fallthru', 'Fall-thru to git') do |fallthru|
|
32
|
+
opts.on('--[no-]fallthru', 'Fall-thru to git. [default: true]') do |fallthru|
|
33
33
|
options['fallthru'] = fallthru
|
34
34
|
end
|
35
35
|
|
36
|
+
opts.on('--feature-prefix', 'Prefix to use for feature branches') do |prefix|
|
37
|
+
options['feature_prefix'] = prefix
|
38
|
+
end
|
39
|
+
|
36
40
|
opts.on(
|
37
41
|
'--github-cli CLI',
|
38
42
|
%w{gh cli},
|
39
|
-
'Github CLI to use ("gh" or "hub").
|
40
|
-
'
|
43
|
+
'Github CLI to use ("gh" or "hub" or "auto"). Auto (the default) will ' +
|
44
|
+
'prefer "gh" if it is available but will fall back to "hub." ' +
|
45
|
+
'[default: "auto"]',
|
41
46
|
) do |cli|
|
42
47
|
options['github_cli'] = cli
|
43
48
|
end
|
@@ -64,22 +69,24 @@ parser = OptionParser.new do |opts|
|
|
64
69
|
|
65
70
|
opts.on(
|
66
71
|
'--ignore-dirty',
|
67
|
-
'Tell command that check for a dirty repo to carry on anyway.'
|
72
|
+
'Tell command that check for a dirty repo to carry on anyway. ' +
|
73
|
+
'[default: false]',
|
68
74
|
) do
|
69
75
|
options['ignore_dirty'] = true
|
70
76
|
end
|
71
77
|
|
72
78
|
opts.on(
|
73
79
|
'--ignore-prerun-failure',
|
74
|
-
'Ignore preprun failure on *push commands.',
|
80
|
+
'Ignore preprun failure on *push commands. [default: false]',
|
75
81
|
) do
|
76
82
|
options['ignore_prerun_failure'] = true
|
77
83
|
end
|
78
84
|
|
79
85
|
opts.on(
|
80
86
|
'--log-level LEVEL',
|
81
|
-
'Set logging level (fatal, error, warning, info, debug, trace).
|
82
|
-
'
|
87
|
+
'Set logging level (fatal, error, warning, info, debug, trace). This can ' +
|
88
|
+
'also be set via the SUGARJAR_LOGLEVEL environment variable. [default: ' +
|
89
|
+
'info]',
|
83
90
|
) do |level|
|
84
91
|
options['log_level'] = level
|
85
92
|
end
|
@@ -127,6 +134,12 @@ COMMANDS:
|
|
127
134
|
of preference it will be upstream/master, origin/master, master,
|
128
135
|
depending upon what remotes are available.
|
129
136
|
|
137
|
+
Note that you can specify "--feature-prefix" (or add
|
138
|
+
"feature_prefix" to your config) to have all features created
|
139
|
+
with a prefix. This is useful for branch-based workflows where
|
140
|
+
developers are expected to create branches names that, for
|
141
|
+
example, start with their username.
|
142
|
+
|
130
143
|
forcepush, fpush
|
131
144
|
The same as "smartpush", but uses "--force-with-lease". This is
|
132
145
|
a "safer" way of doing force-pushes and is the recommended way
|
@@ -176,6 +189,10 @@ COMMANDS:
|
|
176
189
|
version
|
177
190
|
Print the version of sugarjar, and then run 'hub version'
|
178
191
|
to show the hub and git versions.
|
192
|
+
|
193
|
+
Be sure to checkout Sapling (https://sapling-scm.com/)! This was written as
|
194
|
+
a stop-gap to get Sapling features before it was open-sourced, and as such
|
195
|
+
I may deprecate this in the future.
|
179
196
|
COMMANDS
|
180
197
|
|
181
198
|
# rubocop:enable Layout/HeredocIndentation
|
@@ -246,7 +263,9 @@ else
|
|
246
263
|
end
|
247
264
|
end
|
248
265
|
|
249
|
-
|
266
|
+
subcommand = argv_copy.reject { |x| x.start_with?('-') }.first
|
267
|
+
|
268
|
+
if ARGV.empty? || !subcommand
|
250
269
|
puts parser
|
251
270
|
exit
|
252
271
|
end
|
@@ -257,7 +276,6 @@ options = config.merge(options)
|
|
257
276
|
SugarJar::Log.level = options['log_level'].to_sym if options['log_level']
|
258
277
|
sj = SugarJar::Commands.new(options)
|
259
278
|
|
260
|
-
subcommand = argv_copy.reject { |x| x.start_with?('-') }.first
|
261
279
|
is_valid_command = valid_commands.include?(subcommand.to_sym)
|
262
280
|
argv_copy.delete(subcommand)
|
263
281
|
SugarJar::Log.debug("subcommand is #{subcommand}")
|
data/lib/sugarjar/commands.rb
CHANGED
@@ -18,16 +18,20 @@ class SugarJar
|
|
18
18
|
SugarJar::Log.debug("Commands.initialize options: #{options}")
|
19
19
|
@ghuser = options['github_user']
|
20
20
|
@ghhost = options['github_host']
|
21
|
-
@cli = options['github_cli']
|
22
21
|
@ignore_dirty = options['ignore_dirty']
|
23
22
|
@ignore_prerun_failure = options['ignore_prerun_failure']
|
24
23
|
@repo_config = SugarJar::RepoConfig.config
|
25
24
|
@color = options['color']
|
25
|
+
@feature_prefix = options['feature_prefix']
|
26
26
|
@checks = {}
|
27
27
|
@main_branch = nil
|
28
28
|
@main_remote_branches = {}
|
29
29
|
return if options['no_change']
|
30
30
|
|
31
|
+
# technically this doesn't "change" things, but we won't have this
|
32
|
+
# option on the no_change call
|
33
|
+
@cli = determine_cli(options['github_cli'])
|
34
|
+
|
31
35
|
set_hub_host
|
32
36
|
set_commit_template if @repo_config['commit_template']
|
33
37
|
end
|
@@ -35,6 +39,7 @@ class SugarJar
|
|
35
39
|
def feature(name, base = nil)
|
36
40
|
assert_in_repo
|
37
41
|
SugarJar::Log.debug("Feature: #{name}, #{base}")
|
42
|
+
name = fprefix(name)
|
38
43
|
die("#{name} already exists!") if all_local_branches.include?(name)
|
39
44
|
base ||= most_main
|
40
45
|
base_pieces = base.split('/')
|
@@ -49,6 +54,7 @@ class SugarJar
|
|
49
54
|
def bclean(name = nil)
|
50
55
|
assert_in_repo
|
51
56
|
name ||= current_branch
|
57
|
+
name = fprefix(name) unless all_local_branches.include?(name)
|
52
58
|
if clean_branch(name)
|
53
59
|
SugarJar::Log.info("#{name}: #{color('reaped', :green)}")
|
54
60
|
else
|
@@ -180,28 +186,34 @@ class SugarJar
|
|
180
186
|
|
181
187
|
reponame = File.basename(repo, '.git')
|
182
188
|
dir ||= reponame
|
189
|
+
org = extract_org(repo)
|
183
190
|
|
184
191
|
SugarJar::Log.info("Cloning #{reponame}...")
|
185
192
|
|
186
193
|
# GH's 'fork' command (with the --clone arg) will fork, if necessary,
|
187
194
|
# then clone, and then setup the remotes with the appropriate names. So
|
188
195
|
# we just let it do all the work for us and return.
|
189
|
-
|
196
|
+
#
|
197
|
+
# Unless the repo is in our own org and cannot be forked, then it
|
198
|
+
# will fail.
|
199
|
+
if gh? && org != @ghuser
|
190
200
|
ghcli('repo', 'fork', '--clone', canonicalize_repo(repo), dir, *args)
|
191
201
|
SugarJar::Log.info('Remotes "origin" and "upstream" configured.')
|
192
202
|
return
|
193
203
|
end
|
194
204
|
|
195
|
-
# For 'hub'
|
196
|
-
#
|
205
|
+
# For 'hub' first we clone, using git, as 'hub' always needs a repo to
|
206
|
+
# operate on.
|
207
|
+
#
|
208
|
+
# Or for 'gh' when we can't fork...
|
197
209
|
git('clone', canonicalize_repo(repo), dir, *args)
|
198
210
|
|
199
211
|
# Then we go into it and attempt to use the 'fork' capability
|
212
|
+
# or if not
|
200
213
|
Dir.chdir dir do
|
201
214
|
# Now that we have a repo, if we have a hub host set it.
|
202
215
|
set_hub_host
|
203
216
|
|
204
|
-
org = extract_org(repo)
|
205
217
|
SugarJar::Log.debug("Comparing org #{org} to ghuser #{@ghuser}")
|
206
218
|
if org == @ghuser
|
207
219
|
puts 'Cloned forked or self-owned repo. Not creating "upstream".'
|
@@ -339,6 +351,16 @@ class SugarJar
|
|
339
351
|
|
340
352
|
private
|
341
353
|
|
354
|
+
def fprefix(name)
|
355
|
+
return name unless @feature_prefix
|
356
|
+
|
357
|
+
newname = "#{@feature_prefix}#{name}"
|
358
|
+
SugarJar::Log.debug(
|
359
|
+
"Munging feature name: #{name} -> #{newname} due to feature prefix",
|
360
|
+
)
|
361
|
+
newname
|
362
|
+
end
|
363
|
+
|
342
364
|
def _smartpush(remote, branch, force)
|
343
365
|
unless remote && branch
|
344
366
|
remote ||= 'origin'
|
@@ -686,7 +708,7 @@ class SugarJar
|
|
686
708
|
).stdout.lines.reject do |line|
|
687
709
|
line.start_with?('-')
|
688
710
|
end
|
689
|
-
if out.
|
711
|
+
if out.empty?
|
690
712
|
SugarJar::Log.debug(
|
691
713
|
"cherry-pick shows branch #{branch} obviously safe to delete",
|
692
714
|
)
|
@@ -833,6 +855,29 @@ class SugarJar
|
|
833
855
|
end
|
834
856
|
end
|
835
857
|
|
858
|
+
def determine_cli(cli)
|
859
|
+
return cli if %w{gh hub}.include?(cli)
|
860
|
+
|
861
|
+
die("'github_cli' has unknown setting: #{cli}") unless cli == 'auto'
|
862
|
+
|
863
|
+
SugarJar::Log.debug('github_cli set to auto')
|
864
|
+
|
865
|
+
if which_nofail('gh')
|
866
|
+
SugarJar::Log.debug('Found "gh"')
|
867
|
+
return 'gh'
|
868
|
+
end
|
869
|
+
if which_nofail('hub')
|
870
|
+
SugarJar::Log.debug('Did not find "gh" but did find "hub"')
|
871
|
+
return 'hub'
|
872
|
+
end
|
873
|
+
|
874
|
+
die(
|
875
|
+
'Neither "gh" nor "hub" found in PATH, please ensure at least one ' +
|
876
|
+
'of these utilities is in the PATH. If both are available you can ' +
|
877
|
+
'specify which to use with --github-cli',
|
878
|
+
)
|
879
|
+
end
|
880
|
+
|
836
881
|
def hub?
|
837
882
|
@cli == 'hub'
|
838
883
|
end
|
data/lib/sugarjar/config.rb
CHANGED
data/lib/sugarjar/version.rb
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: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Phil Dibowitz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-10-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mixlib-log
|