git-si 0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f5c033e4e7de28be2feb823ec8f1d32db17796b7
4
+ data.tar.gz: cb102435c9881c6614b06c20a27a67911de50186
5
+ SHA512:
6
+ metadata.gz: ad49417b382b982f453ee176e7e54acd424c7fe2a39ac19c208e0ca74634c2ae3d1b93c4cc34715efda4918eb70669f1d155495cfc1c6422c9817073d87ff244
7
+ data.tar.gz: d5c427755fd6df789324d55e22e37eea8ac2633338c6c63340986a781eae4eb93496f0ce1f0dd422fb6b2d31d8e76bd8312c1a2c857d7bade152d0b4ace0bab9
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.swp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in git-si.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Payton Swick
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,26 @@
1
+ # Git::Si
2
+
3
+ Git Svn Interface: a simple git extention to use git locally with a remote svn repo. It's like a simple version of git-svn which doesn't keep track of history locally.
4
+
5
+ ## Installation
6
+
7
+ $ gem install git-si
8
+
9
+ ## Usage
10
+
11
+ Commands:
12
+ git-si add [FILES] # Perform an svn and a git add on the files.
13
+ git-si diff [FILES] # Perform an svn diff piped through a colorizer. Also tests to be sure a rebase is not needed.
14
+ git-si fetch # Updates mirror branch to latest svn commit.
15
+ git-si help [COMMAND] # Describe available commands or one specific command
16
+ git-si pull # Fetch the latest svn commit and rebase the current branch.
17
+ git-si rebase # Rebases current branch to mirror branch.
18
+ git-si status [FILES] # Perform an svn status.
19
+
20
+ ## Contributing
21
+
22
+ 1. Fork it
23
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
24
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
25
+ 4. Push to the branch (`git push origin my-new-feature`)
26
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/git-si ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift(File.dirname(__FILE__), '..', 'lib')
4
+ require 'git/si'
5
+
6
+ Git::Si::SvnInterface.start(ARGV)
data/git-si.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'git/si/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "git-si"
8
+ spec.version = Git::Si::VERSION
9
+ spec.authors = ["Payton Swick"]
10
+ spec.email = ["payton@foolord.com"]
11
+ spec.description = %q{Git Svn Interface: a simple git extention to use git locally with a remote svn repo.}
12
+ spec.summary = %q{It's like a simple version of git-svn which doesn't keep track of history locally.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "thor"
24
+ spec.add_development_dependency "pager"
25
+
26
+ spec.add_runtime_dependency "thor"
27
+ spec.add_runtime_dependency "pager"
28
+ end
@@ -0,0 +1,5 @@
1
+ module Git
2
+ module Si
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
data/lib/git/si.rb ADDED
@@ -0,0 +1,291 @@
1
+ require "git/si/version"
2
+ require "thor"
3
+ require "pager"
4
+
5
+ module Git
6
+
7
+ module Si
8
+
9
+ class GitSiError < StandardError
10
+ end
11
+
12
+ class ShellError < GitSiError
13
+ end
14
+
15
+ class GitError < GitSiError
16
+ end
17
+
18
+ class SvnError < GitSiError
19
+ end
20
+
21
+ class VersionError < GitSiError
22
+ end
23
+
24
+ class SvnInterface < Thor
25
+ include Thor::Actions
26
+ include Pager
27
+
28
+ default_task :usage
29
+
30
+ @@mirror_branch = 'MIRRORBRANCH'
31
+
32
+ desc "usage", "How does this thing work?"
33
+ def usage
34
+ say "git-si
35
+
36
+ Git Svn Interface: a simple git extention to use git locally with a remote svn
37
+ repo. It's like a simple version of git-svn which doesn't keep track of history
38
+ locally.
39
+
40
+ Start with the init command to set up the mirror branch and from there you can
41
+ use the commands below.
42
+
43
+ "
44
+ help
45
+ end
46
+
47
+ desc "status [FILES]", "Perform an svn status."
48
+ def status(*args)
49
+ on_local_branch do
50
+ command = "svn status --ignore-externals " + args.join(' ')
51
+ svn_status = `#{command}`
52
+ raise SvnError.new("Failed to get the svn status. I'm not sure why. Check for any errors above.") if ! $?.success?
53
+ svn_status.each_line do |line|
54
+ case line.strip!
55
+ when /^X/, /\.git/, /\.swp$/
56
+ else
57
+ if STDOUT.tty?
58
+ print_colordiff line
59
+ else
60
+ say line
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
66
+
67
+ desc "diff [FILES]", "Perform an svn diff piped through a colorizer. Also tests to be sure a rebase is not needed."
68
+ def diff(*args)
69
+ on_local_branch do
70
+ last_fetched_version = get_svn_version()
71
+ git_log = `git log --pretty=%B`
72
+ results = git_log.match(/svn update to version (\d+)/i)
73
+ last_rebased_version = results[1] if results
74
+ if last_fetched_version and last_rebased_version
75
+ raise VersionError.new("This branch is out-of-date (rev #{last_rebased_version}; mirror branch is at #{last_fetched_version}). You should do a git si rebase.") if last_fetched_version != last_rebased_version
76
+ else
77
+ notice_message "Could not determine last version information. This may be fine if you haven't used git-si before."
78
+ end
79
+
80
+ command = "svn diff " + args.join(' ')
81
+ notice_message "Running #{command}"
82
+ results = `#{command}`
83
+ if STDOUT.tty?
84
+ page
85
+ print_colordiff results
86
+ else
87
+ say results
88
+ end
89
+ end
90
+ end
91
+
92
+ desc "add [FILES]", "Perform an svn and a git add on the files."
93
+ def add(*args)
94
+ on_local_branch do
95
+ command = "svn add " + args.join(' ')
96
+ run_command(command)
97
+ command = "git add " + args.join(' ')
98
+ run_command(command)
99
+ end
100
+ end
101
+
102
+ desc "fetch", "Updates mirror branch to latest svn commit."
103
+ def fetch
104
+ on_local_branch do
105
+ git_status = `git status --porcelain`
106
+ raise GitError.new("There are local changes; please commit them before continuing.") if git_status.match(/^[^\?]/)
107
+ end
108
+ on_mirror_branch do
109
+ notice_message "Fetching remote data from svn"
110
+ run_command("svn up --accept theirs-full --ignore-externals")
111
+ run_command("svn revert -R ./")
112
+ system("git add .")
113
+ run_command("git commit --allow-empty -am 'svn update to version #{get_svn_version}'")
114
+ end
115
+ success_message "fetch complete!"
116
+ end
117
+
118
+ desc "rebase", "Rebases current branch to mirror branch."
119
+ def rebase
120
+ on_local_branch do
121
+ run_command("git rebase '#{@@mirror_branch}'")
122
+ success_message "rebase complete!"
123
+ end
124
+ end
125
+
126
+ desc "pull", "Fetch the latest svn commit and rebase the current branch."
127
+ def pull
128
+ fetch
129
+ rebase
130
+ end
131
+
132
+ desc "commit", "Perform an svn commit and update the mirror branch."
133
+ def commit
134
+ on_local_branch do
135
+ run_command("svn commit")
136
+ success_message "commit complete!"
137
+ if yes? "Do you want to update the mirror branch to the latest commit? [y/N] "
138
+ on_mirror_branch do
139
+ fetch
140
+ end
141
+ end
142
+ end
143
+ end
144
+
145
+ desc "blame <FILE>", "Alias for svn blame."
146
+ def blame(*args)
147
+ on_local_branch do
148
+ command = "svn blame " + args.join(' ')
149
+ run_command(command)
150
+ end
151
+ end
152
+
153
+ desc "init", "Initializes git-si in this directory with a gitignore and creates a special mirror branch."
154
+ def init
155
+ on_local_branch do
156
+ # check for svn repo
157
+ `svn info`
158
+ raise SvnError.new("No svn repository was found here. Maybe you're in the wrong directory?") unless $?.success?
159
+ make_a_commit = false
160
+
161
+ # check for existing .git repo
162
+ if File.exist? '.git'
163
+ notice_message "Looks like a git repository already exists here."
164
+ else
165
+ notice_message "Initializing git repository"
166
+ `git init`
167
+ raise GitError.new("Failed to initialize git repository. I'm not sure why. Check for any errors above.") unless $?.success?
168
+ make_a_commit = true
169
+ end
170
+
171
+ # check for existing .gitingore
172
+ gitignore = [".svn", "*.swp", ".config", "*.err", "*.pid", "*.log"]
173
+ command = "svn status --ignore-externals "
174
+ svn_status = `#{command}`
175
+ raise SvnError.new("Failed to get the svn status. I'm not sure why. Check for any errors above.") if ! $?.success?
176
+ externals = []
177
+ svn_status.each_line do |line|
178
+ externals << $1 if line.strip.match(/^X\s+(\S.+)/)
179
+ end
180
+ gitignore += externals
181
+ gitignore = gitignore.join("\n")
182
+
183
+ if File.exist? '.gitignore'
184
+ notice_message "Looks like a gitignore file already exists here."
185
+ error_message "Be SURE that the gitignore contains the following:\n#{gitignore}"
186
+ else
187
+ notice_message "Creating gitignore file."
188
+ create_file('.gitignore', gitignore)
189
+ run_command("git add .gitignore")
190
+ make_a_commit = true
191
+ end
192
+
193
+ # make initial commit
194
+ if make_a_commit
195
+ notice_message "Making initial commit."
196
+ run_command("git add .")
197
+ run_command("git commit -am 'initial commit by git-si'")
198
+ end
199
+
200
+ # check for exiting mirror branch
201
+ `git show-ref refs/heads/#{@@mirror_branch}`
202
+ if $?.success?
203
+ notice_message "Looks like the mirror branch already exists here."
204
+ else
205
+ notice_message "Creating mirror branch '#{@@mirror_branch}'."
206
+ run_command("git branch '#{@@mirror_branch}'")
207
+ end
208
+
209
+ success_message "init complete!"
210
+ end
211
+ end
212
+
213
+
214
+ private
215
+
216
+ def get_svn_version
217
+ svn_info = `svn info`
218
+ results = svn_info.match(/^Revision:\s+(\d+)/)
219
+ return results[1] if results
220
+ return nil
221
+ end
222
+
223
+ def get_local_branch
224
+ git_branches = `git branch`
225
+ results = git_branches.match(/^\*\s+(\S+)/)
226
+ local_branch = results[1] if results
227
+ raise GitError.new("Could not find local branch name.") unless local_branch
228
+ return local_branch
229
+ end
230
+
231
+ def on_local_branch(&block)
232
+ begin
233
+ yield
234
+ rescue GitSiError => err
235
+ error_message err
236
+ exit false
237
+ end
238
+ end
239
+
240
+ def on_mirror_branch(&block)
241
+ local_branch = get_local_branch()
242
+ run_command("git checkout #{@@mirror_branch}")
243
+ begin
244
+ yield
245
+ rescue GitSiError => err
246
+ error_message err
247
+ exit false
248
+ ensure
249
+ run_command("git checkout #{local_branch}")
250
+ end
251
+ end
252
+
253
+ def success_message(message)
254
+ $stderr.puts set_color message, :green
255
+ end
256
+
257
+ def notice_message(message)
258
+ $stderr.puts set_color message, :yellow
259
+ end
260
+
261
+ def error_message(message)
262
+ $stderr.puts set_color message, :red
263
+ end
264
+
265
+ def run_command(command, options={})
266
+ if STDOUT.tty?
267
+ run(command, options)
268
+ else
269
+ run(command, options.update(verbose: false))
270
+ end
271
+ raise ShellError.new("There was an error while trying to run the command: #{command}. Look above for any errors.") unless $?.success?
272
+ end
273
+
274
+ def print_colordiff(diff)
275
+ diff.each_line do |line|
276
+ line.rstrip!
277
+ case line
278
+ when /^\+/, /^A/
279
+ line = set_color line, :green
280
+ when /^\-/, /^M/
281
+ line = set_color line, :red
282
+ when /^\?/
283
+ line = set_color line, :yellow
284
+ end
285
+ say line
286
+ end
287
+ end
288
+
289
+ end
290
+ end
291
+ end
data/lib/git-si.rb ADDED
@@ -0,0 +1 @@
1
+ require "git/si"
metadata ADDED
@@ -0,0 +1,141 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: git-si
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Payton Swick
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-10-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: thor
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pager
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: thor
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pager
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: 'Git Svn Interface: a simple git extention to use git locally with a
98
+ remote svn repo.'
99
+ email:
100
+ - payton@foolord.com
101
+ executables:
102
+ - git-si
103
+ extensions: []
104
+ extra_rdoc_files: []
105
+ files:
106
+ - .gitignore
107
+ - Gemfile
108
+ - LICENSE.txt
109
+ - README.md
110
+ - Rakefile
111
+ - bin/git-si
112
+ - git-si.gemspec
113
+ - lib/git-si.rb
114
+ - lib/git/si.rb
115
+ - lib/git/si/version.rb
116
+ homepage: ''
117
+ licenses:
118
+ - MIT
119
+ metadata: {}
120
+ post_install_message:
121
+ rdoc_options: []
122
+ require_paths:
123
+ - lib
124
+ required_ruby_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - '>='
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ required_rubygems_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ requirements: []
135
+ rubyforge_project:
136
+ rubygems_version: 2.0.5
137
+ signing_key:
138
+ specification_version: 4
139
+ summary: It's like a simple version of git-svn which doesn't keep track of history
140
+ locally.
141
+ test_files: []