dreamcat4-braid 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,80 @@
1
+ require File.dirname(__FILE__) + '/../integration_helper'
2
+
3
+ describe "Adding a mirror in a clean repository" do
4
+
5
+ before do
6
+ FileUtils.rm_rf(TMP_PATH)
7
+ FileUtils.mkdir_p(TMP_PATH)
8
+ end
9
+
10
+ describe "from a git repository" do
11
+ before do
12
+ @shiny = create_git_repo_from_fixture("shiny")
13
+ @skit1 = create_git_repo_from_fixture("skit1")
14
+ end
15
+
16
+ it "should add the files and commit" do
17
+ in_dir(@shiny) do
18
+ `#{BRAID_BIN} add --type git #{@skit1}`
19
+ end
20
+
21
+ file_name = "skit1/layouts/layout.liquid"
22
+ output = `diff -U 3 #{File.join(FIXTURE_PATH, file_name)} #{File.join(TMP_PATH, "shiny", file_name)}`
23
+ $?.should.be.success
24
+
25
+ output = `git log --pretty=oneline`.split("\n")
26
+ output.length.should == 2
27
+ output[0].should =~ /Braid: Added mirror 'skit1' at '[0-9a-f]{7}'/
28
+ end
29
+
30
+ it "should create .braids and add the mirror to it" do
31
+ in_dir(@shiny) do
32
+ `#{BRAID_BIN} add --type git #{@skit1}`
33
+ end
34
+
35
+ braids = YAML::load_file("#{@shiny}/.braids")
36
+ braids["skit1"]["squashed"].should == true
37
+ braids["skit1"]["url"].should == @skit1
38
+ braids["skit1"]["type"].should == "git"
39
+ braids["skit1"]["revision"].should.not.be nil
40
+ braids["skit1"]["branch"].should == "master"
41
+ braids["skit1"]["remote"].should == "braid/skit1"
42
+ end
43
+ end
44
+
45
+ describe "from an svn repository" do
46
+ before do
47
+ @shiny = create_git_repo_from_fixture("shiny")
48
+ @skit1 = create_svn_repo_from_fixture("skit1")
49
+ end
50
+
51
+ it "should add the files and commit" do
52
+ in_dir(@shiny) do
53
+ `#{BRAID_BIN} add --type svn #{@skit1}`
54
+ end
55
+
56
+ file_name = "skit1/layouts/layout.liquid"
57
+ output = `diff -U 3 #{File.join(FIXTURE_PATH, file_name)} #{File.join(TMP_PATH, "shiny", file_name)}`
58
+ $?.should.be.success
59
+
60
+ output = `git log --pretty=oneline`.split("\n")
61
+ output.length.should == 2
62
+ output[0].should =~ /Braid: Added mirror 'skit1' at r1/
63
+ end
64
+
65
+ it "should create .braids and add the mirror to it" do
66
+ in_dir(@shiny) do
67
+ `#{BRAID_BIN} add --type svn #{@skit1}`
68
+ end
69
+
70
+ braids = YAML::load_file("#{@shiny}/.braids")
71
+ braids["skit1"]["squashed"].should == true
72
+ braids["skit1"]["url"].should == @skit1
73
+ braids["skit1"]["type"].should == "svn"
74
+ braids["skit1"]["revision"].should == 1
75
+ braids["skit1"]["remote"].should == "braid/skit1"
76
+ braids["skit1"]["branch"].should.be == nil
77
+ end
78
+ end
79
+
80
+ end
@@ -0,0 +1,87 @@
1
+ require File.dirname(__FILE__) + '/../integration_helper'
2
+
3
+ describe "Updating a mirror without conflicts" do
4
+
5
+ before do
6
+ FileUtils.rm_rf(TMP_PATH)
7
+ FileUtils.mkdir_p(TMP_PATH)
8
+ end
9
+
10
+ describe "from a git repository" do
11
+ before do
12
+ @shiny = create_git_repo_from_fixture("shiny")
13
+ @skit1 = create_git_repo_from_fixture("skit1")
14
+
15
+ in_dir(@shiny) do
16
+ `#{BRAID_BIN} add --type git #{@skit1}`
17
+ end
18
+
19
+ update_dir_from_fixture("skit1", "skit1.1")
20
+ in_dir(@skit1) do
21
+ `git add *`
22
+ `git commit -m "change default color"`
23
+ end
24
+
25
+ update_dir_from_fixture("skit1", "skit1.2")
26
+ in_dir(@skit1) do
27
+ `git add *`
28
+ `git commit -m "add a happy note"`
29
+ end
30
+
31
+ end
32
+
33
+ it "should add the files and commit" do
34
+ in_dir(@shiny) do
35
+ `#{BRAID_BIN} update skit1`
36
+ end
37
+
38
+ file_name = "layouts/layout.liquid"
39
+ output = `diff -U 3 #{File.join(FIXTURE_PATH, "skit1.2", file_name)} #{File.join(TMP_PATH, "shiny", "skit1", file_name)}`
40
+ $?.should.be.success
41
+
42
+ output = `git log --pretty=oneline`.split("\n")
43
+ output.length.should == 3
44
+ output[0].should =~ /Braid: Updated mirror 'skit1' to '[0-9a-f]{7}'/
45
+ end
46
+
47
+ end
48
+
49
+ describe "from a svn repository" do
50
+ before do
51
+ @shiny = create_git_repo_from_fixture("shiny")
52
+ @skit1 = create_svn_repo_from_fixture("skit1")
53
+ @skit1_wc = File.join(TMP_PATH, "skit1_wc")
54
+
55
+ in_dir(@shiny) do
56
+ `#{BRAID_BIN} add --type svn #{@skit1}`
57
+ end
58
+
59
+ update_dir_from_fixture("skit1_wc", "skit1.1")
60
+ in_dir(@skit1_wc) do
61
+ `svn commit -m "change default color"`
62
+ end
63
+
64
+ update_dir_from_fixture("skit1_wc", "skit1.2")
65
+ in_dir(@skit1_wc) do
66
+ `svn commit -m "add a happy note"`
67
+ end
68
+
69
+ end
70
+
71
+ it "should add the files and commit" do
72
+ in_dir(@shiny) do
73
+ `#{BRAID_BIN} update skit1`
74
+ end
75
+
76
+ file_name = "layouts/layout.liquid"
77
+ output = `diff -U 3 #{File.join(FIXTURE_PATH, "skit1.2", file_name)} #{File.join(TMP_PATH, "shiny", "skit1", file_name)}`
78
+ $?.should.be.success
79
+
80
+ output = `git log --pretty=oneline`.split("\n")
81
+ output.length.should == 3
82
+ output[0].should =~ /Braid: Updated mirror 'skit1' to r3/
83
+ end
84
+
85
+ end
86
+
87
+ end
@@ -0,0 +1,70 @@
1
+ require 'rubygems'
2
+ require 'test/spec'
3
+ require 'mocha'
4
+
5
+ require 'tempfile'
6
+ require 'fileutils'
7
+ require 'pathname'
8
+
9
+ TMP_PATH = File.join(Dir.tmpdir, "braid_integration")
10
+ BRAID_PATH = Pathname.new(File.dirname(__FILE__)).parent.realpath
11
+ FIXTURE_PATH = File.join(BRAID_PATH, "test", "fixtures")
12
+ FileUtils.rm_rf(TMP_PATH)
13
+ FileUtils.mkdir_p(TMP_PATH)
14
+ BRAID_BIN = File.join(BRAID_PATH, "bin", "braid")
15
+
16
+ #def exec(cmd)
17
+ # `cd #{TMP} && #{cmd}`
18
+ #end
19
+
20
+ def in_dir(dir = TMP_PATH)
21
+ Dir.chdir(dir)
22
+ yield
23
+ end
24
+
25
+ def run_cmds(ary)
26
+ ary.each do |cmd|
27
+ cmd = cmd.strip!
28
+ out = `#{cmd}`
29
+ end
30
+ end
31
+
32
+ def update_dir_from_fixture(dir, fixture = dir)
33
+ to_dir = File.join(TMP_PATH, dir)
34
+ FileUtils.mkdir_p(to_dir)
35
+ FileUtils.cp_r(File.join(FIXTURE_PATH, fixture) + "/.", to_dir)
36
+ end
37
+
38
+ def create_git_repo_from_fixture(fixture_name)
39
+ git_repo = File.join(TMP_PATH, fixture_name)
40
+ update_dir_from_fixture(fixture_name)
41
+
42
+ in_dir(git_repo) do
43
+ run_cmds(<<-EOD)
44
+ git init
45
+ git add *
46
+ git commit -m "initial commit of #{fixture_name}"
47
+ EOD
48
+ end
49
+
50
+ git_repo
51
+ end
52
+
53
+ def create_svn_repo_from_fixture(fixture_name)
54
+ svn_wc = File.join(TMP_PATH, fixture_name + "_wc")
55
+ svn_repo = File.join(TMP_PATH, fixture_name)
56
+ run_cmds(<<-EOD)
57
+ svnadmin create #{svn_repo}
58
+ svn co file://#{svn_repo} #{svn_wc}
59
+ EOD
60
+ update_dir_from_fixture(fixture_name + "_wc", fixture_name)
61
+ in_dir(svn_wc) do
62
+ run_cmds(<<-EOD)
63
+ svn add *
64
+ svn commit -m "initial commit of #{fixture_name}"
65
+ EOD
66
+ end
67
+ "file://#{svn_repo}"
68
+ end
69
+
70
+
@@ -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: dreamcat4-braid
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.1
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 -07: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
+