dev_git 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +34 -1
- data/lib/git.rb +24 -19
- data/spec/git_spec.rb +34 -0
- metadata +4 -35
data/README.md
CHANGED
@@ -1 +1,34 @@
|
|
1
|
-
|
1
|
+
## dev_git <img src="https://badge.fury.io/rb/dev_git.png" alt="Gem Version" />
|
2
|
+
|
3
|
+
A ruby gem to assist with git operations.
|
4
|
+
The dev_tasks gem defines a constant DEV
|
5
|
+
|
6
|
+
### Installation
|
7
|
+
|
8
|
+
The gem can be installed by the single command
|
9
|
+
```
|
10
|
+
gem install dev_git
|
11
|
+
```
|
12
|
+
|
13
|
+
### Usage
|
14
|
+
|
15
|
+
This is an example of a simple usage
|
16
|
+
```
|
17
|
+
require 'dev_git'
|
18
|
+
```
|
19
|
+
|
20
|
+
### License
|
21
|
+
Copyright 2014-2015 Lou Parslow
|
22
|
+
|
23
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
24
|
+
you may not use this file except in compliance with the License.
|
25
|
+
You may obtain a copy of the License at
|
26
|
+
|
27
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
28
|
+
|
29
|
+
Unless required by applicable law or agreed to in writing, software
|
30
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
31
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
32
|
+
See the License for the specific language governing permissions and
|
33
|
+
limitations under the License.
|
34
|
+
|
data/lib/git.rb
CHANGED
@@ -1,10 +1,13 @@
|
|
1
1
|
class Git
|
2
|
-
def self.branch
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
2
|
+
def self.branch directory=''
|
3
|
+
directory=Dir.pwd if directory.length == 0
|
4
|
+
Dir.chdir(directory) do
|
5
|
+
begin
|
6
|
+
`git branch`.scan(/\* ([.\w-]+)/)[0][0] if(File.exists?('.git'))
|
7
|
+
rescue
|
8
|
+
''
|
9
|
+
end
|
10
|
+
end
|
8
11
|
end
|
9
12
|
|
10
13
|
def self.remote_origin directory=''
|
@@ -28,19 +31,21 @@ class Git
|
|
28
31
|
end
|
29
32
|
end
|
30
33
|
false
|
31
|
-
|
32
|
-
# On branch master
|
33
|
-
# nothing to commit, working directory clean
|
34
|
-
|
35
|
-
# $ git status
|
36
|
-
# On branch master
|
37
|
-
# Changes not staged for commit:
|
38
|
-
# (use "git add <file>..." to update what will be committed)
|
39
|
-
# (use "git checkout -- <file>..." to discard changes in working directory)
|
40
|
-
#
|
41
|
-
# modified: lib/git.rb
|
42
|
-
#
|
43
|
-
# no changes added to commit (use "git add" and/or "git commit -a")
|
34
|
+
end
|
44
35
|
|
36
|
+
def self.init directory=''
|
37
|
+
directory=Dir.pwd if directory.length==0
|
38
|
+
FileUtils.mkpath directory if !File.exists?(directory)
|
39
|
+
if(!File.exists?("#{directory}/.git"))
|
40
|
+
Dir.chdir(directory) do
|
41
|
+
`git init`
|
42
|
+
File.open('.gitignore','w'){|f|
|
43
|
+
f.puts '### Mac ###'
|
44
|
+
f.puts '*.DS_Store'
|
45
|
+
}
|
46
|
+
`git add .gitignore`
|
47
|
+
`git commit -m'added .gitignore'`
|
48
|
+
end
|
49
|
+
end
|
45
50
|
end
|
46
51
|
end
|
data/spec/git_spec.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require_relative '../lib/git.rb'
|
2
|
+
require 'fileutils'
|
2
3
|
|
3
4
|
describe Git do
|
4
5
|
it "should be able to get the remote origin" do
|
@@ -8,4 +9,37 @@ describe Git do
|
|
8
9
|
it "should be able to get the current branch" do
|
9
10
|
expect(Git.branch).not_to eq('')
|
10
11
|
end
|
12
|
+
|
13
|
+
it "should be able to perform a basic workflow" do
|
14
|
+
repo_dir="#{File.dirname(__FILE__)}/tmp/repo"
|
15
|
+
|
16
|
+
FileUtils.rm_r repo_dir if File.exists?(repo_dir)
|
17
|
+
|
18
|
+
Git.init repo_dir
|
19
|
+
#FileUtils.mkpath repo_dir if !File.exists?(repo_dir)
|
20
|
+
#Dir.chdir(repo_dir) do
|
21
|
+
# `git init`
|
22
|
+
# File.open('.gitignore','w'){|f|
|
23
|
+
# f.puts '### Ruby ###'
|
24
|
+
# f.puts '*.gem'
|
25
|
+
# }
|
26
|
+
# `git add .gitignore`
|
27
|
+
# `git commit -m'added .gitignore'`
|
28
|
+
#end
|
29
|
+
expect(File.exists?("#{repo_dir}/.git")).to eq(true)
|
30
|
+
#Node.Net.Environment.Command createMaster = new Node.Net.Environment.Command("git checkout -b master", workingPath);
|
31
|
+
#expect(Git.branch repo_dir).to eq('master')
|
32
|
+
|
33
|
+
wrk_dir="#{File.dirname(__FILE__)}/tmp/wrk"
|
34
|
+
FileUtils.rm_r wrk_dir if File.exists?(wrk_dir)
|
35
|
+
`git clone #{repo_dir} #{wrk_dir}`
|
36
|
+
expect(File.exists?("#{wrk_dir}/.git")).to eq(true)
|
37
|
+
Dir.chdir(wrk_dir) do
|
38
|
+
#{}`git checkout -b master`
|
39
|
+
#expect(Git.branch).to eq('master')
|
40
|
+
end
|
41
|
+
#expect(Git.branch wrk_dir).to eq('master')
|
42
|
+
FileUtils.rm_r repo_dir
|
43
|
+
FileUtils.rm_r wrk_dir
|
44
|
+
end
|
11
45
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dev_git
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,40 +9,8 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
13
|
-
dependencies:
|
14
|
-
- !ruby/object:Gem::Dependency
|
15
|
-
name: rake
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
|
-
requirements:
|
19
|
-
- - ~>
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
version: '10.0'
|
22
|
-
type: :development
|
23
|
-
prerelease: false
|
24
|
-
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
|
-
requirements:
|
27
|
-
- - ~>
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: '10.0'
|
30
|
-
- !ruby/object:Gem::Dependency
|
31
|
-
name: rspec
|
32
|
-
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
|
-
requirements:
|
35
|
-
- - ~>
|
36
|
-
- !ruby/object:Gem::Version
|
37
|
-
version: '3.0'
|
38
|
-
type: :development
|
39
|
-
prerelease: false
|
40
|
-
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
|
-
requirements:
|
43
|
-
- - ~>
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
version: '3.0'
|
12
|
+
date: 2015-04-06 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
46
14
|
description: execution of git operations
|
47
15
|
email: lou.parslow@gmail.com
|
48
16
|
executables: []
|
@@ -81,3 +49,4 @@ signing_key:
|
|
81
49
|
specification_version: 3
|
82
50
|
summary: gem to assist with git operations
|
83
51
|
test_files: []
|
52
|
+
has_rdoc:
|