git_repository 0.0.11
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/git_repository.rb +62 -0
- metadata +65 -0
@@ -0,0 +1,62 @@
|
|
1
|
+
class GitRepository
|
2
|
+
def initialize(hash = {})
|
3
|
+
@system_wrapper = hash[:system] || SystemWrapper.new
|
4
|
+
remote = hash[:remote] || 'origin'
|
5
|
+
@location = get_repository(hash[:ssh_repository]) || remote
|
6
|
+
@branch = hash[:branch] || 'master'
|
7
|
+
end
|
8
|
+
def commit(hash)
|
9
|
+
message_with_options = insert_options(:message => 'git commit', :options=>hash[:options])
|
10
|
+
commit_message = "#{message_with_options} -m '#{hash[:message]}'"
|
11
|
+
@system_wrapper.execute(commit_message)
|
12
|
+
end
|
13
|
+
|
14
|
+
def has_changes?
|
15
|
+
git_status = @system_wrapper.execute('git status')
|
16
|
+
result = git_status.include?('Changes not staged for commit') || git_status.include?('Changes to be committed:')
|
17
|
+
return result
|
18
|
+
end
|
19
|
+
|
20
|
+
def has_untracked?
|
21
|
+
git_status = @system_wrapper.execute("git status")
|
22
|
+
return git_status.include?("Untracked files:")
|
23
|
+
end
|
24
|
+
|
25
|
+
def push(hash = {})
|
26
|
+
push_message_with_options = insert_options(:message => 'git push', :options => hash[:options])
|
27
|
+
push_message = "#{push_message_with_options} #{@location} #{@branch}"
|
28
|
+
@system_wrapper.execute(push_message)
|
29
|
+
end
|
30
|
+
|
31
|
+
def pull(hash = {})
|
32
|
+
pull_message_with_options = insert_options(:message => 'git pull',:options => hash[:options])
|
33
|
+
pull_message = "#{pull_message_with_options} #{@location} #{@branch}"
|
34
|
+
@system_wrapper.execute(pull_message)
|
35
|
+
end
|
36
|
+
|
37
|
+
def add(hash = {})
|
38
|
+
files = hash[:files] || '.'
|
39
|
+
add_message_with_options = insert_options(:message => 'git add', :options => hash[:options])
|
40
|
+
@system_wrapper.execute("#{add_message_with_options} #{files}")
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
def get_repository(repository)
|
45
|
+
return "--repo='#{repository}'" unless repository.nil?
|
46
|
+
end
|
47
|
+
|
48
|
+
def insert_options(hash)
|
49
|
+
if(hash[:options].nil?)
|
50
|
+
return "#{hash[:message]}"
|
51
|
+
else
|
52
|
+
return "#{hash[:message]} #{hash[:options]}"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
class SystemWrapper
|
59
|
+
def execute(command)
|
60
|
+
`#{command}`
|
61
|
+
end
|
62
|
+
end
|
metadata
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: git_repository
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 9
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 11
|
10
|
+
version: 0.0.11
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Ben Flowers
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2013-02-24 00:00:00 Z
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description:
|
22
|
+
email: ben.j.flowers@gmail.com
|
23
|
+
executables: []
|
24
|
+
|
25
|
+
extensions: []
|
26
|
+
|
27
|
+
extra_rdoc_files: []
|
28
|
+
|
29
|
+
files:
|
30
|
+
- lib/git_repository.rb
|
31
|
+
homepage: https://github.com/benoj/GitRepository
|
32
|
+
licenses: []
|
33
|
+
|
34
|
+
post_install_message:
|
35
|
+
rdoc_options: []
|
36
|
+
|
37
|
+
require_paths:
|
38
|
+
- lib
|
39
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
hash: 3
|
45
|
+
segments:
|
46
|
+
- 0
|
47
|
+
version: "0"
|
48
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
hash: 3
|
54
|
+
segments:
|
55
|
+
- 0
|
56
|
+
version: "0"
|
57
|
+
requirements: []
|
58
|
+
|
59
|
+
rubyforge_project:
|
60
|
+
rubygems_version: 1.8.15
|
61
|
+
signing_key:
|
62
|
+
specification_version: 3
|
63
|
+
summary: Simple interaction with git repository. Useful for deployment scripts.
|
64
|
+
test_files: []
|
65
|
+
|