braid 0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,110 @@
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.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.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
95
+
96
+ describe "Braid::Mirror#cached?" do
97
+ before(:each) do
98
+ @mirror = new_from_options("git://path")
99
+ end
100
+
101
+ it "should be true when the remote path matches the cache path" do
102
+ git.expects(:remote_url).with(@mirror.remote).returns(git_cache.path(@mirror.url))
103
+ @mirror.should.be.cached
104
+ end
105
+
106
+ it "should be false if the remote does not point to the cache" do
107
+ git.expects(:remote_url).with(@mirror.remote).returns(@mirror.url)
108
+ @mirror.should.not.be.cached
109
+ end
110
+ end
@@ -0,0 +1,66 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ describe "Braid::Operations::Git#remote_url" do
4
+ it "should use git config" do
5
+ # FIXME weak test
6
+ git.expects(:invoke).with(:config, 'remote.braid/git/one.url').returns("git://path")
7
+ git.remote_url("braid/git/one").should == "git://path"
8
+ end
9
+ end
10
+
11
+ describe "Braid::Operations::Git#rev_parse" do
12
+ it "should return the full hash when a hash is found" do
13
+ full_revision = 'a' * 40
14
+ git.expects(:exec).returns([0, full_revision, ""])
15
+ git.rev_parse('a' * 7).should == full_revision
16
+ end
17
+
18
+ it "should raise a revision error when the hash is not found" do
19
+ ambiguous_revision = 'b' * 7
20
+ git.expects(:exec).returns([1, ambiguous_revision, "fatal: ..."])
21
+ lambda { git.rev_parse(ambiguous_revision) }.should.raise(Braid::Operations::UnknownRevision)
22
+ end
23
+ end
24
+
25
+ describe "Braid::Operations::Git#version" do
26
+ ACTUAL_VERSION = "1.5.5.1.98.gf0ec4"
27
+
28
+ before(:each) do
29
+ git.expects(:exec).returns([0, "git version #{ACTUAL_VERSION}\n", ""])
30
+ end
31
+
32
+ it "should extract from git --version output" do
33
+ git.version.should == ACTUAL_VERSION
34
+ end
35
+ end
36
+
37
+ describe "Braid::Operations::Git#require_version" do
38
+ REQUIRED_VERSION = "1.5.4.5"
39
+ PASS_VERSIONS = %w(1.5.4.6 1.5.5 1.6 1.5.4.5.2 1.5.5.1.98.gf0ec4)
40
+ FAIL_VERSIONS = %w(1.5.4.4 1.5.4 1.5.3 1.4.5.6)
41
+
42
+ def set_version(str)
43
+ git.expects(:exec).returns([0, "git version #{str}\n", ""])
44
+ end
45
+
46
+ it "should return true for higher revisions" do
47
+ PASS_VERSIONS.each do |version|
48
+ set_version(version)
49
+ git.require_version(REQUIRED_VERSION).should == true
50
+ end
51
+ end
52
+
53
+ it "should return false for lower revisions" do
54
+ FAIL_VERSIONS.each do |version|
55
+ set_version(version)
56
+ git.require_version(REQUIRED_VERSION).should == false
57
+ end
58
+ end
59
+ end
60
+
61
+ describe "Braid::Operations::GitCache#path" do
62
+ it "should use the local cache directory and strip characters" do
63
+ git_cache.path("git://path").should == File.join(Braid.local_cache_dir, "git___path")
64
+ git_cache.path("git@domain:repository.git").should == File.join(Braid.local_cache_dir, "git_domain_repository.git")
65
+ end
66
+ 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,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: braid
3
+ version: !ruby/object:Gem::Version
4
+ version: "0.5"
5
+ platform: ruby
6
+ authors:
7
+ - Cristi Balan
8
+ - Norbert Crombach
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2008-10-29 00:00:00 +02:00
14
+ default_executable: braid
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: main
18
+ type: :runtime
19
+ version_requirement:
20
+ version_requirements: !ruby/object:Gem::Requirement
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: 2.8.0
25
+ version:
26
+ - !ruby/object:Gem::Dependency
27
+ name: open4
28
+ type: :runtime
29
+ version_requirement:
30
+ version_requirements: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: 0.9.6
35
+ version:
36
+ description: A simple tool for tracking vendor branches in git.
37
+ email: evil@che.lu
38
+ executables:
39
+ - braid
40
+ extensions: []
41
+
42
+ extra_rdoc_files: []
43
+
44
+ files:
45
+ - bin/braid
46
+ - braid.gemspec
47
+ - lib/braid/command.rb
48
+ - lib/braid/commands/add.rb
49
+ - lib/braid/commands/diff.rb
50
+ - lib/braid/commands/remove.rb
51
+ - lib/braid/commands/setup.rb
52
+ - lib/braid/commands/update.rb
53
+ - lib/braid/config.rb
54
+ - lib/braid/mirror.rb
55
+ - lib/braid/operations.rb
56
+ - lib/braid.rb
57
+ - LICENSE
58
+ - Rakefile
59
+ - README.textile
60
+ - test/braid_test.rb
61
+ - test/config_test.rb
62
+ - test/fixtures/shiny/README
63
+ - test/fixtures/skit1/layouts/layout.liquid
64
+ - test/fixtures/skit1/preview.png
65
+ - test/fixtures/skit1.1/layouts/layout.liquid
66
+ - test/fixtures/skit1.2/layouts/layout.liquid
67
+ - test/integration/adding_test.rb
68
+ - test/integration/updating_test.rb
69
+ - test/integration_helper.rb
70
+ - test/mirror_test.rb
71
+ - test/operations_test.rb
72
+ - test/test_helper.rb
73
+ has_rdoc: false
74
+ homepage: http://evil.che.lu/projects/braid
75
+ post_install_message:
76
+ rdoc_options:
77
+ - --line-numbers
78
+ - --inline-source
79
+ - --title
80
+ - braid
81
+ - --main
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: "0"
89
+ version:
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: "0"
95
+ version:
96
+ requirements: []
97
+
98
+ rubyforge_project: braid
99
+ rubygems_version: 1.2.0
100
+ signing_key:
101
+ specification_version: 2
102
+ summary: A simple tool for tracking vendor branches in git.
103
+ test_files: []
104
+