git_stage_formatter 3.0.0 → 3.0.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eef46e1e61e9298617a81667ae1d75dda336b9abae96da8d3f31f504e7a369e7
4
- data.tar.gz: 315e59902076c09d46b87c57ddd580819860b4e5919085c0d232dd59ca7cf0ed
3
+ metadata.gz: 64a3dd9bf65c6bb93cb17974466d6a638bf68690e61a3ec9c113db4be63a6ac1
4
+ data.tar.gz: ded69b5da94227a628edb0c2f2341f960a340a3113fa8587b6be1f0405226346
5
5
  SHA512:
6
- metadata.gz: 38b0689f0aa55e86523f8081ff222b48933613df2df159c6ac9a6bd7c27d865d438e7bc2d6e7e899299b0dcf15492c46fd8b5925164717978a7a4323d9f3ac95
7
- data.tar.gz: cc11ea3ed725beaa56c164f882d19ac589dc0f4e6f3dfc3ba401a32af6d3600ef627be690611900bee82e1ba032bda49607e6686893a70039225ead123dfe139
6
+ metadata.gz: 5d6523769d0021592706c94ce8f9b47bce70abaa8b74d9c025c4bc33ff65803fd60381fc0e38882dcd1993ce8b3ae9d86e21cfbf0f7a046eb89b0bbfa8d495a0
7
+ data.tar.gz: 70492bc58d979e5105524e168353a82d2216f946cf1b776d774ff21fa22e9ab31277fd6e1c1438ee321d32e5df538ab7d87b067dc06b7dd64eb07c668fb4621e
data/.gitignore CHANGED
@@ -4,7 +4,6 @@ yarn-error.log
4
4
 
5
5
  # Ruby
6
6
  .bundle
7
- Gemfile.lock
8
7
  /pkg/
9
8
 
10
9
  # Misc
data/Gemfile CHANGED
@@ -4,3 +4,7 @@ source "https://rubygems.org"
4
4
 
5
5
  # Gem dependencies specified in git_stage_formatter.gemspec
6
6
  gemspec
7
+
8
+ gem "bundler", "~> 2"
9
+ gem "rake"
10
+ gem "tty-prompt"
data/Gemfile.lock ADDED
@@ -0,0 +1,34 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ git_stage_formatter (3.0.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ pastel (0.8.0)
10
+ tty-color (~> 0.5)
11
+ rake (13.0.6)
12
+ tty-color (0.6.0)
13
+ tty-cursor (0.7.1)
14
+ tty-prompt (0.23.1)
15
+ pastel (~> 0.8)
16
+ tty-reader (~> 0.8)
17
+ tty-reader (0.9.0)
18
+ tty-cursor (~> 0.7)
19
+ tty-screen (~> 0.8)
20
+ wisper (~> 2.0)
21
+ tty-screen (0.8.1)
22
+ wisper (2.0.1)
23
+
24
+ PLATFORMS
25
+ arm64-darwin-21
26
+
27
+ DEPENDENCIES
28
+ bundler (~> 2)
29
+ git_stage_formatter!
30
+ rake
31
+ tty-prompt
32
+
33
+ BUNDLED WITH
34
+ 2.4.18
data/README.md CHANGED
@@ -217,3 +217,15 @@ Some more comparisons:
217
217
  [pretty-quick]: https://www.npmjs.com/package/pretty-quick
218
218
  [lint-staged]: https://github.com/okonet/lint-staged
219
219
  [lint changed hunks]: https://github.com/okonet/lint-staged/issues/62#issuecomment-383217916
220
+
221
+ # Development
222
+
223
+ To bump the lib's version, run `bundle exec rake bump[1.2.3]` (replacing the value with the desired version).
224
+
225
+ To release a new version, update the version number in `version.rb` (likely done via `rake bump` above), 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).
226
+
227
+ # Contributing
228
+
229
+ If you spot something wrong, missing, or if you'd like to propose improvements to this project, please open an Issue or a Pull Request with your ideas and I promise to get back to you within 24 hours! 😇
230
+
231
+ For a list of issues worth tackling check out: https://github.com/rogerluan/git_stage_formatter/issues
data/Rakefile CHANGED
@@ -1,4 +1,21 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "bundler/gem_tasks"
4
+ require "tty-prompt"
5
+
4
6
  task default: %i[]
7
+
8
+ desc "Sets lib version to the semantic version given, and push it to remote."
9
+ task :bump, [:v] do |_t, args|
10
+ version = args[:v] || raise("A version is required. Pass it like `rake bump[1.2.3]`")
11
+ next unless TTY::Prompt.new.yes?("Would you like to set the new version of the app to be '#{version}'?")
12
+
13
+ version_filename = Dir.glob("lib/*/version.rb").first
14
+ version_file_contents = File.read(version_filename)
15
+ new_version_file_contents = version_file_contents.gsub(/VERSION = "(?:.*)"/, "VERSION = \"#{version}\"")
16
+ File.open(version_filename, "w") { |file| file.puts new_version_file_contents }
17
+ sh("bundle install")
18
+ sh("git add #{version_filename} Gemfile.lock")
19
+ sh("git commit -m 'Bump app version to v#{version}.'")
20
+ sh("git push origin")
21
+ end
data/git-format-staged CHANGED
@@ -36,7 +36,7 @@ def fatal(msg):
36
36
  print('{}: error: {}'.format(PROG, msg), file=sys.stderr)
37
37
  exit(1)
38
38
 
39
- def format_staged_files(file_patterns, formatter, git_root, update_working_tree=True, write=True):
39
+ def format_staged_files(file_patterns, formatter, git_root, update_working_tree=True, write=True, verbose=False):
40
40
  try:
41
41
  output = subprocess.check_output([
42
42
  'git', 'diff-index',
@@ -53,7 +53,7 @@ def format_staged_files(file_patterns, formatter, git_root, update_working_tree=
53
53
  continue
54
54
  if not (matches_some_path(file_patterns, entry_path)):
55
55
  continue
56
- if format_file_in_index(formatter, entry, update_working_tree=update_working_tree, write=write):
56
+ if format_file_in_index(formatter, entry, update_working_tree=update_working_tree, write=write, verbose=verbose):
57
57
  info('Reformatted {} with {}'.format(entry['src_path'], formatter))
58
58
  except Exception as err:
59
59
  fatal(str(err))
@@ -61,9 +61,9 @@ def format_staged_files(file_patterns, formatter, git_root, update_working_tree=
61
61
  # Run formatter on file in the git index. Creates a new git object with the
62
62
  # result, and replaces the content of the file in the index with that object.
63
63
  # Returns hash of the new object if formatting produced any changes.
64
- def format_file_in_index(formatter, diff_entry, update_working_tree=True, write=True):
64
+ def format_file_in_index(formatter, diff_entry, update_working_tree=True, write=True, verbose=False):
65
65
  orig_hash = diff_entry['dst_hash']
66
- new_hash = format_object(formatter, orig_hash, diff_entry['src_path'])
66
+ new_hash = format_object(formatter, orig_hash, diff_entry['src_path'], verbose=verbose)
67
67
 
68
68
  # If the new hash is the same then the formatter did not make any changes.
69
69
  if not write or new_hash == orig_hash:
@@ -90,13 +90,16 @@ file_path_placeholder = re.compile('\{\}')
90
90
 
91
91
  # Run formatter on a git blob identified by its hash. Writes output to a new git
92
92
  # blob, and returns the hash of the new blob.
93
- def format_object(formatter, object_hash, file_path):
93
+ def format_object(formatter, object_hash, file_path, verbose=False):
94
94
  get_content = subprocess.Popen(
95
95
  ['git', 'cat-file', '-p', object_hash],
96
96
  stdout=subprocess.PIPE
97
97
  )
98
+ command = re.sub(file_path_placeholder, file_path, formatter)
99
+ if verbose:
100
+ info(command)
98
101
  format_content = subprocess.Popen(
99
- re.sub(file_path_placeholder, file_path, formatter),
102
+ command,
100
103
  shell=True,
101
104
  stdin=get_content.stdout,
102
105
  stdout=subprocess.PIPE
@@ -145,7 +148,7 @@ def replace_file_in_index(diff_entry, new_object_hash):
145
148
 
146
149
  def patch_working_file(path, orig_object_hash, new_object_hash):
147
150
  patch = subprocess.check_output(
148
- ['git', 'diff', '--color=never', orig_object_hash, new_object_hash]
151
+ ['git', 'diff', '--no-ext-diff', '--color=never', orig_object_hash, new_object_hash]
149
152
  )
150
153
 
151
154
  # Substitute object hashes in patch header with path to working tree file
@@ -254,6 +257,11 @@ if __name__ == '__main__':
254
257
  version='%(prog)s version {}'.format(VERSION),
255
258
  help='Display version of %(prog)s'
256
259
  )
260
+ parser.add_argument(
261
+ '--verbose',
262
+ help='Show the formatting commands that are running',
263
+ action='store_true'
264
+ )
257
265
  parser.add_argument(
258
266
  'files',
259
267
  nargs='+',
@@ -266,5 +274,6 @@ if __name__ == '__main__':
266
274
  formatter=vars(args)['formatter'],
267
275
  git_root=get_git_root(),
268
276
  update_working_tree=not vars(args)['no_update_working_tree'],
269
- write=not vars(args)['no_write']
277
+ write=not vars(args)['no_write'],
278
+ verbose=vars(args)['verbose']
270
279
  )
@@ -23,7 +23,4 @@ Gem::Specification.new do |spec|
23
23
  spec.bindir = "bin"
24
24
  spec.executables = ['git_stage_formatter']
25
25
  spec.require_paths = ["lib"]
26
-
27
- spec.add_development_dependency 'bundler', '>= 2.0.0', '< 3.0.0'
28
- spec.add_development_dependency 'rake', '~> 13.0'
29
26
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GitStageFormatter
4
- VERSION = "3.0.0"
4
+ VERSION = "3.0.1"
5
5
  end
@@ -2,7 +2,8 @@ require_relative "git_stage_formatter/version"
2
2
 
3
3
  module GitStageFormatter
4
4
  def self.run(args)
5
- args = args.join(' ')
5
+ # Wrap each argument in quotes to handle spaces in paths
6
+ args = args.map { |arg| "\"#{arg}\"" }.join(' ')
6
7
  script_path = File.expand_path('../git-format-staged', File.dirname(__FILE__))
7
8
  exec("#{script_path} #{args}")
8
9
  end