norbert-braid 0.4.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,94 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ describe "Braid::Mirror.new_from_options" do
4
+ it "should default branch to master" do
5
+ new_from_options("git://path")
6
+ @mirror.branch.should == "master"
7
+ end
8
+
9
+ it "should default type to git, from protocol" do
10
+ new_from_options("git://path")
11
+ @mirror.type.should == "git"
12
+ end
13
+
14
+ it "should default type to git, if path ends in .git" do
15
+ new_from_options("http://path.git")
16
+ @mirror.type.should == "git"
17
+ end
18
+
19
+ it "should default type to svn, from protocol" do
20
+ new_from_options("svn://path")
21
+ @mirror.type.should == "svn"
22
+ end
23
+
24
+ it "should default type to svn, if path ends in /trunk" do
25
+ new_from_options("http://path/trunk")
26
+ @mirror.type.should == "svn"
27
+ end
28
+
29
+ it "should raise if no type can be guessed" do
30
+ lambda { new_from_options("http://path") }.should.raise(Braid::Mirror::CannotGuessType)
31
+ end
32
+
33
+ it "should default mirror to previous to last path part, if last path part is /trunk" do
34
+ new_from_options("http://path/trunk")
35
+ @mirror.path.should == "path"
36
+ end
37
+
38
+ it "should default mirror to last path part, ignoring trailing .git" do
39
+ new_from_options("http://path.git")
40
+ @mirror.path.should == "path"
41
+ end
42
+ end
43
+
44
+ describe "Braid::Mirror#diff" do
45
+ before(:each) do
46
+ @mirror = build_mirror("revision" => 'a' * 40)
47
+ @mirror.stubs(:base_revision).returns(@mirror.revision) # bypass rev_parse
48
+ end
49
+
50
+ def set_hashes(remote_hash, local_hash)
51
+ git.expects(:rev_parse).with("#{@mirror.revision}:").returns(remote_hash)
52
+ git.expects(:tree_hash).with(@mirror.path).returns(local_hash)
53
+ end
54
+
55
+ it "should return an empty string when the hashes match" do
56
+ set_hashes('b' * 40, 'b' * 40)
57
+ git.expects(:diff_tree).never
58
+ @mirror.diff.should == ""
59
+ end
60
+
61
+ it "should generate a diff when the hashes do not match" do
62
+ set_hashes('b' * 40, 'c' * 40)
63
+ diff = "diff --git a/path b/path\n"
64
+ git.expects(:diff_tree).with('b' * 40, 'c' * 40, @mirror.path).returns(diff)
65
+ @mirror.diff.should == diff
66
+ end
67
+ end
68
+
69
+ describe "Braid::Mirror#base_revision" do
70
+ it "should be inferred when no revision is set" do
71
+ @mirror = build_mirror
72
+ @mirror.revision.should.be.nil
73
+ @mirror.expects(:inferred_revision).returns('b' * 40)
74
+ @mirror.send(:base_revision).should == 'b' * 40
75
+ end
76
+
77
+ it "should be the parsed hash for git mirrors" do
78
+ @mirror = build_mirror("revision" => 'a' * 7)
79
+ git.expects(:rev_parse).with('a' * 7).returns('a' * 40)
80
+ @mirror.send(:base_revision).should == 'a' * 40
81
+ end
82
+ end
83
+
84
+ describe "Braid::Mirror#inferred_revision" do
85
+ it "should return the last commit before the most recent update" do
86
+ @mirror = new_from_options("git://path")
87
+ git.expects(:rev_list).times(2).returns(
88
+ "#{'a' * 40}\n",
89
+ "commit #{'b' * 40}\n#{'t' * 40}\n"
90
+ )
91
+ git.expects(:tree_hash).with(@mirror.path, 'a' * 40).returns('t' * 40)
92
+ @mirror.send(:inferred_revision).should == 'b' * 40
93
+ end
94
+ end
@@ -0,0 +1,69 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ describe "Braid::Operations::Git#remote_exists?" do
4
+ before(:each) do
5
+ File.expects(:readlines).returns(["[remote \"braid/git/one\"]\n", "[svn-remote \"braid/git/two\"]\n"])
6
+ end
7
+
8
+ it "should return true for existing git remotes" do
9
+ git.remote_exists?("braid/git/one").should == true
10
+ end
11
+
12
+ it "should return true for existing svn remotes" do
13
+ git.remote_exists?("braid/git/two").should == true
14
+ end
15
+
16
+ it "should return false for nonexistent remotes" do
17
+ git.remote_exists?("N/A").should == false
18
+ end
19
+ end
20
+
21
+ describe "Braid::Operations::Git#rev_parse" do
22
+ it "should return the full hash when a hash is found" do
23
+ full_revision = 'a' * 40
24
+ git.expects(:exec).returns([0, full_revision, ""])
25
+ git.rev_parse('a' * 7).should == full_revision
26
+ end
27
+
28
+ it "should raise a revision error when the hash is not found" do
29
+ ambiguous_revision = 'b' * 7
30
+ git.expects(:exec).returns([1, ambiguous_revision, "fatal: ..."])
31
+ lambda { git.rev_parse(ambiguous_revision) }.should.raise(Braid::Operations::UnknownRevision)
32
+ end
33
+ end
34
+
35
+ describe "Braid::Operations::Git#version" do
36
+ ACTUAL_VERSION = "1.5.5.1.98.gf0ec4"
37
+
38
+ before(:each) do
39
+ git.expects(:exec).returns([0, "git version #{ACTUAL_VERSION}\n", ""])
40
+ end
41
+
42
+ it "should extract from git --version output" do
43
+ git.version.should == ACTUAL_VERSION
44
+ end
45
+ end
46
+
47
+ describe "Braid::Operations::Git#require_version" do
48
+ REQUIRED_VERSION = "1.5.4.5"
49
+ PASS_VERSIONS = %w(1.5.4.6 1.5.5 1.6 1.5.4.5.2 1.5.5.1.98.gf0ec4)
50
+ FAIL_VERSIONS = %w(1.5.4.4 1.5.4 1.5.3 1.4.5.6)
51
+
52
+ def set_version(str)
53
+ git.expects(:exec).returns([0, "git version #{str}\n", ""])
54
+ end
55
+
56
+ it "should return true for higher revisions" do
57
+ PASS_VERSIONS.each do |version|
58
+ set_version(version)
59
+ git.require_version(REQUIRED_VERSION).should == true
60
+ end
61
+ end
62
+
63
+ it "should return false for lower revisions" do
64
+ FAIL_VERSIONS.each do |version|
65
+ set_version(version)
66
+ git.require_version(REQUIRED_VERSION).should == false
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,15 @@
1
+ require 'rubygems'
2
+ require 'test/spec'
3
+ require 'mocha'
4
+
5
+ require File.dirname(__FILE__) + '/../lib/braid'
6
+
7
+ def new_from_options(url, options = {})
8
+ @mirror = Braid::Mirror.new_from_options(url, options)
9
+ end
10
+
11
+ def build_mirror(options = {})
12
+ Braid::Mirror.new("path", options)
13
+ end
14
+
15
+ include Braid::Operations::VersionControl
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: norbert-braid
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.9
5
+ platform: ruby
6
+ authors:
7
+ - Cristi Balan
8
+ - Norbert Crombach
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2008-09-06 00:00:00 -07:00
14
+ default_executable: braid
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: main
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 2.8.0
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: open4
27
+ version_requirement:
28
+ version_requirements: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 0.9.6
33
+ version:
34
+ description: A simple tool for tracking vendor branches in git.
35
+ email: evil@che.lu
36
+ executables:
37
+ - braid
38
+ extensions: []
39
+
40
+ extra_rdoc_files:
41
+ - README.rdoc
42
+ files:
43
+ - LICENSE
44
+ - README.rdoc
45
+ - Rakefile
46
+ - braid.gemspec
47
+ - bin/braid
48
+ - lib/braid/command.rb
49
+ - lib/braid/commands/add.rb
50
+ - lib/braid/commands/diff.rb
51
+ - lib/braid/commands/remove.rb
52
+ - lib/braid/commands/setup.rb
53
+ - lib/braid/commands/update.rb
54
+ - lib/braid/config.rb
55
+ - lib/braid/mirror.rb
56
+ - lib/braid/operations.rb
57
+ - lib/braid.rb
58
+ - test/braid_test.rb
59
+ - test/config_test.rb
60
+ - test/mirror_test.rb
61
+ - test/operations_test.rb
62
+ - test/test_helper.rb
63
+ has_rdoc: true
64
+ homepage: http://evil.che.lu/projects/braid
65
+ post_install_message:
66
+ rdoc_options:
67
+ - --line-numbers
68
+ - --inline-source
69
+ - --title
70
+ - braid
71
+ - --main
72
+ - README.rdoc
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: "0"
80
+ version:
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: "0"
86
+ version:
87
+ requirements: []
88
+
89
+ rubyforge_project: braid
90
+ rubygems_version: 1.2.0
91
+ signing_key:
92
+ specification_version: 2
93
+ summary: A simple tool for tracking vendor branches in git.
94
+ test_files: []
95
+