gitit 0.3.0 → 0.4.0

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
  SHA1:
3
- metadata.gz: fe90ba6d576b4229458a0f87a846ffbd2f7b0778
4
- data.tar.gz: 9fff1938db737966882eadd712aae732048daa6b
3
+ metadata.gz: af209587e77caca9136ae19f2d0efbf8ba3eb91b
4
+ data.tar.gz: 666be3564b3934764dc32bd234b3d5fb33826e89
5
5
  SHA512:
6
- metadata.gz: fd65fab4db9ff67991a87e0e62fb77ddc0f62a455d99484776125d6b01967e6691f15c5c03432d9f56244ada4c4788294871afe3baea1da18937c19bdf464c9c
7
- data.tar.gz: eb58091dbc95bcadfbf852eaa946a2b82567f4e9f87185ae423b2f551fc2230b2367a581ccf9606871f519789bef94b6ac17d510ea3e392f0d275888869489dc
6
+ metadata.gz: 6021bd64aad05f62f49cf37418428b40fc2a4bce8aac5d61530495be7258d98d27822ff9eda80f16752971206896e9508fcd447293a5ec899fef17901da8d5c9
7
+ data.tar.gz: 4f56f4a768aa3920f4ad1eaacb1170d823b595c0f25377d2fbc1523f47d5e5f1f4b69a5b19b17c4aa30fe18f80736d363b2169d1566dbd8c5b8777cec789e1a1
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.4.0
@@ -0,0 +1,33 @@
1
+ require "bundler/setup"
2
+ require "gitit/command_executor"
3
+
4
+ Bundler.require(:default)
5
+
6
+ module Gitit
7
+
8
+ # ---------------------------------------------------------------------------
9
+ # ---------------------------------------------------------------------------
10
+ class Branch
11
+ include CommandExecutor
12
+
13
+ attr_reader :name;
14
+
15
+ # -------------------------------------------------------------------------
16
+ # -------------------------------------------------------------------------
17
+ def initialize(repo, name)
18
+ @repo = repo
19
+ @name = name
20
+ end
21
+
22
+ # -------------------------------------------------------------------------
23
+ # -------------------------------------------------------------------------
24
+ def valid?
25
+ executeCommand("diff --cached --no-ext-diff --ignore-submodules --quiet --exit-code")
26
+ return true if $?.exitstatus == 1
27
+ return false
28
+ end
29
+
30
+ end
31
+
32
+ end
33
+
@@ -0,0 +1,41 @@
1
+ require "bundler/setup"
2
+ require "gitit/command_executor"
3
+
4
+ Bundler.require(:default)
5
+
6
+ module Gitit
7
+
8
+ # ---------------------------------------------------------------------------
9
+ # ---------------------------------------------------------------------------
10
+ class Branches
11
+ include CommandExecutor
12
+
13
+ # -------------------------------------------------------------------------
14
+ # -------------------------------------------------------------------------
15
+ def initialize(repo)
16
+ @repo = repo
17
+ end
18
+
19
+ # -------------------------------------------------------------------------
20
+ # -------------------------------------------------------------------------
21
+ def existsLocally?(name)
22
+ branches = executeCommand("branch --no-color | sed 's/^[* ] //'")
23
+ executeCommand("branch --no-color | sed 's/^[* ] //' | grep #{name}")
24
+ return true if $?.exitstatus == 0
25
+ return false
26
+ end
27
+
28
+ # -------------------------------------------------------------------------
29
+ # -------------------------------------------------------------------------
30
+ def existsRemotely?(name)
31
+ branches = executeCommand("branch -r --no-color | sed 's/^[* ] //'")
32
+ executeCommand("branch --no-color | sed 's/^[* ] //' | grep #{name}")
33
+ return true if $?.exitstatus == 0
34
+ return false
35
+ end
36
+
37
+ end
38
+
39
+ end
40
+
41
+
data/lib/gitit/git.rb CHANGED
@@ -1,8 +1,11 @@
1
1
  require "bundler/setup"
2
2
  require "gitit"
3
3
  require "gitit/repo"
4
- require "gitit/command_config"
5
- require "gitit/command_status"
4
+ Dir[File.dirname(__FILE__) + "/command_*.rb"].each do |file|
5
+ require file
6
+ end
7
+ #require "gitit/command_config"
8
+ #require "gitit/command_status"
6
9
 
7
10
  Bundler.require(:default)
8
11
 
@@ -14,6 +17,7 @@ module Gitit
14
17
  attr_reader :repo;
15
18
  attr_reader :config;
16
19
  attr_reader :status;
20
+ attr_reader :branches;
17
21
 
18
22
  # -------------------------------------------------------------------------
19
23
  # -------------------------------------------------------------------------
@@ -21,6 +25,7 @@ module Gitit
21
25
  @repo = Repo.new(location)
22
26
  @config = Config.new(repo)
23
27
  @status = Status.new(repo)
28
+ @branches = Branches.new(repo)
24
29
  end
25
30
  end
26
31
 
data/lib/gitit/repo.rb CHANGED
@@ -20,7 +20,7 @@ module Gitit
20
20
  # -------------------------------------------------------------------------
21
21
  # -------------------------------------------------------------------------
22
22
  def valid?
23
- commandres = `(cd #{@location} && git status 2&>/dev/null)`
23
+ commandres = `(cd #{@location} && git rev-parse --git-dir >/dev/null 2>&1)`
24
24
  return true unless $?.exitstatus != 0
25
25
  return false
26
26
  end
@@ -0,0 +1,138 @@
1
+ require 'cli-colorize'
2
+
3
+ def valid? version
4
+ pattern = /^\d+\.\d+\.\d+(\-(dev|beta|rc\d+))?$/
5
+ raise "Tried to set invalid version: #{version}".red unless version =~ pattern
6
+ end
7
+
8
+ def correct_version version
9
+ ver, flag = version.split '-'
10
+ v = ver.split '.'
11
+ (0..2).each do |n|
12
+ v[n] = v[n].to_i
13
+ end
14
+ [v.join('.'), flag].compact.join '-'
15
+ end
16
+
17
+ def read_version
18
+ begin
19
+ File.read 'VERSION'
20
+ rescue
21
+ raise "VERSION file not found or unreadable.".red
22
+ end
23
+ end
24
+
25
+ def write_version version
26
+ valid? version
27
+ begin
28
+ File.open 'VERSION', 'w' do |file|
29
+ file.write correct_version(version)
30
+ end
31
+ rescue
32
+ raise "VERSION file not found or unwritable.".red
33
+ end
34
+ end
35
+
36
+ def reset current, which
37
+ version, flag = current.split '-'
38
+ v = version.split '.'
39
+ which.each do |part|
40
+ v[part] = 0
41
+ end
42
+ [v.join('.'), flag].compact.join '-'
43
+ end
44
+
45
+ def increment current, which
46
+ version, flag = current.split '-'
47
+ v = version.split '.'
48
+ v[which] = v[which].to_i + 1
49
+ [v.join('.'), flag].compact.join '-'
50
+ end
51
+
52
+ desc "Prints the current application version"
53
+ version = read_version
54
+ task :version do
55
+ puts <<HELP
56
+ Available commands are:
57
+ -----------------------
58
+ rake version:write[version] # set custom version in the x.x.x-? format
59
+ rake version:patch # increment the patch x.x.x+1 (keeps any flags on)
60
+ rake version:minor # increment minor and reset patch x.x+1.0 (keeps any flags on)
61
+ rake version:major # increment major and reset others x+1.0.0 (keeps any flags on)
62
+ rake version:dev # set the dev flag on x.x.x-dev
63
+ rake version:beta # set the beta flag on x.x.x-beta
64
+ rake version:rc # set or increment the rc flag x.x.x-rcX
65
+ rake version:release # removes any flags from the current version
66
+
67
+ HELP
68
+ puts "Current version is: #{version.green}"
69
+ end
70
+
71
+ namespace :version do
72
+
73
+ desc "Write version explicitly by specifying version number as a parameter"
74
+ task :write, [:version] do |task, args|
75
+ write_version args[:version].strip
76
+ puts "Version explicitly written: #{read_version.green}"
77
+ end
78
+
79
+ desc "Increments the patch version"
80
+ task :patch do
81
+ new_version = increment read_version, 2
82
+ write_version new_version
83
+ puts "Application patched: #{new_version.green}"
84
+ end
85
+
86
+ desc "Increments the minor version and resets the patch"
87
+ task :minor do
88
+ incremented = increment read_version, 1
89
+ new_version = reset incremented, [2]
90
+ write_version new_version
91
+ puts "New version released: #{new_version.green}"
92
+ end
93
+
94
+ desc "Increments the major version and resets both minor and patch"
95
+ task :major do
96
+ incremented = increment read_version, 0
97
+ new_version = reset incremented, [1, 2]
98
+ write_version new_version
99
+ puts "Major application version change: #{new_version.green}. Congratulations!"
100
+ end
101
+
102
+ desc "Sets the development flag on"
103
+ task :dev do
104
+ version, flag = read_version.split '-'
105
+ new_version = [version, 'dev'].join '-'
106
+ write_version new_version
107
+ puts "Version in development: #{new_version.green}"
108
+ end
109
+
110
+ desc "Sets the beta flag on"
111
+ task :beta do
112
+ version, flag = read_version.split '-'
113
+ new_version = [version, 'beta'].join '-'
114
+ write_version new_version
115
+ puts "Version in beta: #{new_version.green}"
116
+ end
117
+
118
+ desc "Sets or increments the rc flag"
119
+ task :rc do
120
+ version, flag = read_version.split '-'
121
+ rc = /^rc(\d+)$/.match flag
122
+ if rc
123
+ new_version = [version, "rc#{rc[1].to_i+1}"].join '-'
124
+ else
125
+ new_version = [version, 'rc1'].join '-'
126
+ end
127
+ write_version new_version
128
+ puts "New version release candidate: #{new_version.green}"
129
+ end
130
+
131
+ desc "Removes any version flags"
132
+ task :release do
133
+ version, flag = read_version.split '-'
134
+ write_version version
135
+ puts "Released stable version: #{version.green}"
136
+ end
137
+
138
+ end
@@ -0,0 +1,29 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ module Gitit
4
+
5
+ describe Branch do
6
+
7
+ # -------------------------------------------------------------------------
8
+ # -------------------------------------------------------------------------
9
+ describe "#testRepoBranch" do
10
+
11
+ before(:each) do
12
+ FileUtils.mkpath TEST_REPO_PATH
13
+ git = Git.new(TEST_REPO_PATH)
14
+ @myRepo = git.repo
15
+ @myRepo.init
16
+ @repoBranch = Gitit::Branch.new(@myRepo, "master")
17
+ end
18
+
19
+ it "will tell us if the branch is a valid branch" do
20
+ end
21
+
22
+ after(:each) do
23
+ FileUtils.rm_rf TEST_REPO_PATH
24
+ end
25
+
26
+ end
27
+ end
28
+
29
+ end
@@ -0,0 +1,83 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ module Gitit
4
+
5
+ describe Branches do
6
+
7
+ # -------------------------------------------------------------------------
8
+ # -------------------------------------------------------------------------
9
+ describe "#testBranchesExistance" do
10
+
11
+ before(:each) do
12
+ FileUtils.mkpath TEST_REPO_PATH
13
+ git = Git.new(TEST_REPO_PATH)
14
+ @myRepo = git.repo
15
+ @myRepo.init
16
+ @repoBranches = git.branches
17
+
18
+ File.open("#{TEST_REPO_PATH}/out.txt", "w+") { |file| file.write("boo!") }
19
+ `(cd #{TEST_REPO_PATH} && git add #{TEST_REPO_PATH}/out.txt && git commit -am "wip")`
20
+
21
+ `(mkdir -p #{TEST_REPO_PATH_BARE} && cd #{TEST_REPO_PATH_BARE} && git init --bare)`
22
+ `(cd #{TEST_REPO_PATH} && git remote add origin #{TEST_REPO_PATH_BARE})`
23
+ `(cd #{TEST_REPO_PATH} && git push origin master --quiet)`
24
+
25
+ end
26
+
27
+ it "will successfully find a valid local branch" do
28
+ @repoBranches.existsLocally?("master").should eq true
29
+ end
30
+
31
+ it "will fail to find an invalid local branch" do
32
+ @repoBranches.existsLocally?("asdasdsad").should eq false
33
+ end
34
+
35
+ it "will successfully find a valid remote branch" do
36
+ @repoBranches.existsRemotely?("master").should eq true
37
+ end
38
+
39
+ it "will fail to find an invalid remote branch" do
40
+ @repoBranches.existsRemotely?("asdasdsad").should eq false
41
+ end
42
+
43
+ after(:each) do
44
+ FileUtils.rm_rf TEST_REPO_PATH
45
+ FileUtils.rm_rf TEST_REPO_PATH_BARE
46
+ end
47
+
48
+ end
49
+
50
+ # -------------------------------------------------------------------------
51
+ # -------------------------------------------------------------------------
52
+ describe "#testBranchCreationLocally" do
53
+
54
+ before(:each) do
55
+ FileUtils.mkpath TEST_REPO_PATH
56
+ git = Git.new(TEST_REPO_PATH)
57
+ @myRepo = git.repo
58
+ @myRepo.init
59
+ @repoBranches = git.branches
60
+
61
+ File.open("#{TEST_REPO_PATH}/out.txt", "w+") { |file| file.write("boo!") }
62
+ `(cd #{TEST_REPO_PATH} && git add #{TEST_REPO_PATH}/out.txt && git commit -am "wip")`
63
+
64
+ `(mkdir -p #{TEST_REPO_PATH_BARE} && cd #{TEST_REPO_PATH_BARE} && git init --bare)`
65
+ `(cd #{TEST_REPO_PATH} && git remote add origin #{TEST_REPO_PATH_BARE})`
66
+ `(cd #{TEST_REPO_PATH} && git push origin master --quiet)`
67
+
68
+ end
69
+
70
+ after(:each) do
71
+ FileUtils.rm_rf TEST_REPO_PATH
72
+ FileUtils.rm_rf TEST_REPO_PATH_BARE
73
+ end
74
+
75
+ end
76
+
77
+ # -------------------------------------------------------------------------
78
+ # -------------------------------------------------------------------------
79
+
80
+ end
81
+
82
+ end
83
+
@@ -3,7 +3,7 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
3
3
 
4
4
  module Gitit
5
5
 
6
- describe Repo do
6
+ describe Config do
7
7
 
8
8
  # -------------------------------------------------------------------------
9
9
  # -------------------------------------------------------------------------
data/spec/gitit_spec.rb CHANGED
@@ -11,6 +11,7 @@ module Gitit
11
11
  TMP_PATH = "/tmp/"
12
12
  BAD_PATH = "/adsdsadasdsa"
13
13
  TEST_REPO_PATH = "/tmp/test_git"
14
+ TEST_REPO_PATH_BARE = "/tmp/test_git_bare"
14
15
 
15
16
  before(:each) do
16
17
  end
@@ -3,7 +3,7 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
3
3
 
4
4
  module Gitit
5
5
 
6
- describe Repo do
6
+ describe Status do
7
7
 
8
8
  # -------------------------------------------------------------------------
9
9
  # -------------------------------------------------------------------------
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pat Laplante
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-18 00:00:00.000000000 Z
11
+ date: 2013-07-23 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: '"ruby git command line wrapper"'
14
14
  email:
@@ -33,12 +33,17 @@ files:
33
33
  - gitit.gemspecbak
34
34
  - lib/ext/string.rb
35
35
  - lib/gitit.rb
36
+ - lib/gitit/command_branch.rb
37
+ - lib/gitit/command_branches.rb
36
38
  - lib/gitit/command_config.rb
37
39
  - lib/gitit/command_executor.rb
38
40
  - lib/gitit/command_status.rb
39
41
  - lib/gitit/git.rb
40
42
  - lib/gitit/repo.rb
41
43
  - lib/gitit/version.rb
44
+ - lib/tasks/version.rake
45
+ - spec/gitit_branch_spec.rb
46
+ - spec/gitit_branches_spec.rb
42
47
  - spec/gitit_config_spec.rb
43
48
  - spec/gitit_spec.rb
44
49
  - spec/gitit_status_spec.rb
@@ -71,6 +76,8 @@ test_files:
71
76
  - features/gitit.feature
72
77
  - features/step_definitions/gitit_steps.rb
73
78
  - features/support/env.rb
79
+ - spec/gitit_branch_spec.rb
80
+ - spec/gitit_branches_spec.rb
74
81
  - spec/gitit_config_spec.rb
75
82
  - spec/gitit_spec.rb
76
83
  - spec/gitit_status_spec.rb