git-merge-structure-sql 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0e8c35db8645408746b82cf6f317a2a6c6c5c70ba693ca198f84325c508d4f49
4
- data.tar.gz: ad2f45570587be9299b378adcb601a481c3f953c2b7eed39a348003e696ff946
3
+ metadata.gz: 45fa3f60e8db64b7a23134411c828fe3a2282c0460de038c4a4797053c3e0fd0
4
+ data.tar.gz: 3b2fed60a95223f78e75054594e368ef672aa57a44726ef8f34f142add0aa677
5
5
  SHA512:
6
- metadata.gz: ce85fd23fe236cb10da132ae9e06577c196a0b754425de855087614486de10492b06650a4ebde6f5cf05719e0b7aef5a5eb9c342eb24bc1c235658e85b436d78
7
- data.tar.gz: 6558f1ed947236bf03762e0d22d47653e7d8957209ea912a16f757f02859599103eab39245c4dded0c49d6a2502f5085d05c98eaca115cc92181846461ab9c23
6
+ metadata.gz: 77f0237b83a0d37ab7c699d4d88f68288cfc658e13778ab2995aedb30e2e0c17c53f95b1ca3992d8bc5af006eb6e46b0086261a5539e00f604cd7f372d4ffdd4
7
+ data.tar.gz: b18704eb043e4cbe1039a0dfd9adfa8c1853f58f5deec99e917cc9c1728cc55bd1b23b2f56770b5386047ceb18d160266493dcc2023375c23ada3986e966a7a5
data/CHANGELOG.md CHANGED
@@ -12,3 +12,7 @@
12
12
  ## 1.1.1 (2021-04-28)
13
13
 
14
14
  - Fix installation when the attribute file does not exist yet
15
+
16
+ ## 1.1.2 (2021-04-30)
17
+
18
+ - Implemnt local installation with --install=local
data/README.md CHANGED
@@ -30,6 +30,11 @@ This adds necessary settings to your `~/.gitconfig` or
30
30
  `$XDG_CONFIG_HOME/git/config` and the default gitattributes(5) file to
31
31
  enable the merge driver for structure.sql files.
32
32
 
33
+ If you want to enable this driver only in the current git directory,
34
+ run this:
35
+
36
+ $ git-merge-structure-sql --install=local
37
+
33
38
  ## Usage
34
39
 
35
40
  Once enabled, Git should call this driver as necessary when it needs
@@ -33,7 +33,7 @@
33
33
  #
34
34
 
35
35
  class StructureSqlMergeDriver
36
- VERSION = '1.1.1'
36
+ VERSION = '1.1.2'
37
37
  VARIANTS = []
38
38
 
39
39
  module Default # This covers PostgreSQL, SQLite and newer MySQL formats.
@@ -154,49 +154,73 @@ class StructureSqlMergeDriver
154
154
  opts.summary_indent = ''
155
155
  opts.summary_width = 24
156
156
 
157
- opts.on('--install',
158
- "Enable this merge driver in Git") { |val|
159
- install = val
157
+ opts.on('--install[={global|local}]',
158
+ "Enable this merge driver in Git (default: global)") { |val|
159
+ case install = val&.to_sym || :global
160
+ when :global, :local
161
+ # ok
162
+ else
163
+ raise OptionParser::InvalidArgument, "--install=#{val}: unknown argument"
164
+ end
160
165
  }
161
166
  }
162
167
 
163
168
  files = opts.order(argv)
164
169
 
165
170
  if install
166
- puts "Registering the \"#{driver_name}\" driver in your git configuration"
167
-
168
- system!(*%W[
169
- git config --global merge.#{driver_name}.name
170
- #{'Rails structure.sql merge driver'}
171
- ])
172
- system!(*%W[
173
- git config --global merge.#{driver_name}.driver
174
- #{"#{myname.shellescape} %A %O %B"}
175
- ])
176
-
177
- attributes_file = `git config --global core.attributesfile`.chomp
171
+ global = install == :global
172
+
173
+ git_config = ["git", "config", *("--global" if global)]
174
+
175
+ config_file = `GIT_EDITOR=echo #{git_config.shelljoin} -e 2>/dev/null`.chomp
176
+
177
+ puts "#{config_file}: Adding the \"#{driver_name}\" driver definition"
178
+
179
+ system!(
180
+ *git_config,
181
+ "merge.#{driver_name}.name",
182
+ "Rails structure.sql merge driver"
183
+ )
184
+ system!(
185
+ *git_config,
186
+ "merge.#{driver_name}.driver",
187
+ "#{myname.shellescape} %A %O %B"
188
+ )
189
+
178
190
  attributes_file =
179
- if $?.success?
180
- File.expand_path(attributes_file)
191
+ if global
192
+ filename = `git config --global core.attributesfile`.chomp
193
+
194
+ if $?.success?
195
+ File.expand_path(filename)
196
+ else
197
+ [
198
+ [File.join(ENV['XDG_CONFIG_HOME'] || '~/.config', 'git'), 'attributes'],
199
+ ['~', '.gitattributes']
200
+ ].find { |dir, file|
201
+ if File.directory?(File.expand_path(dir))
202
+ system!(*%W[
203
+ git config --global core.attributesfile #{File.join(dir, file)}
204
+ ])
205
+ break File.expand_path(file, dir)
206
+ end
207
+ } or raise "don't you have home?"
208
+ end
181
209
  else
182
- [
183
- [File.join(ENV['XDG_CONFIG_HOME'] || '~/.config', 'git'), 'attributes'],
184
- ['~', '.gitattributes']
185
- ].find { |dir, file|
186
- if File.directory?(File.expand_path(dir))
187
- system!(*%W[
188
- git config --global core.attributesfile #{File.join(dir, file)}
189
- ])
190
- break File.expand_path(file, dir)
191
- end
192
- } or raise "don't you have home?"
210
+ git_dir = `git rev-parse --git-dir`.chomp
211
+
212
+ if $?.success?
213
+ File.expand_path(File.join('info', 'attributes'), git_dir)
214
+ else
215
+ raise "not in a git directory"
216
+ end
193
217
  end
194
218
 
195
219
  File.open(attributes_file, 'a+') { |f|
196
220
  pattern = /^\s*structure.sql\s+(?:\S+\s+)*merge=#{Regexp.quote(driver_name)}(?:\s|$)/
197
221
  break if f.any? { |line| pattern === line }
198
222
 
199
- puts "Enabling the \"#{driver_name}\" driver for structure.sql"
223
+ puts "#{attributes_file}: Registering the \"#{driver_name}\" driver for structure.sql"
200
224
  f.puts if f.pos > 0
201
225
  f.puts "structure.sql merge=#{driver_name}"
202
226
  }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git-merge-structure-sql
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Akinori MUSHA
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-04-28 00:00:00.000000000 Z
11
+ date: 2021-04-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler