realityforge-braid 0.7.2

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: Add 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: Add 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: Update 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: Update 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).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,155 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: realityforge-braid
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.7.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Cristi Balan
9
+ - Norbert Crombach
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2013-01-02 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: main
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: 4.7.3
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ! '>='
29
+ - !ruby/object:Gem::Version
30
+ version: 4.7.3
31
+ - !ruby/object:Gem::Dependency
32
+ name: open4
33
+ requirement: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: 1.0.1
39
+ type: :runtime
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: 1.0.1
47
+ - !ruby/object:Gem::Dependency
48
+ name: test-spec
49
+ requirement: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: 0.10.0
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: 0.10.0
63
+ - !ruby/object:Gem::Dependency
64
+ name: mocha
65
+ requirement: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: 0.9.11
71
+ type: :development
72
+ prerelease: false
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: 0.9.11
79
+ description: A simple tool for tracking vendor branches in git.
80
+ email: evil@che.lu
81
+ executables:
82
+ - braid
83
+ extensions: []
84
+ extra_rdoc_files: []
85
+ files:
86
+ - .gitignore
87
+ - Gemfile
88
+ - LICENSE
89
+ - README.md
90
+ - Rakefile
91
+ - bin/braid
92
+ - braid.gemspec
93
+ - lib/braid.rb
94
+ - lib/braid/command.rb
95
+ - lib/braid/commands/add.rb
96
+ - lib/braid/commands/diff.rb
97
+ - lib/braid/commands/list.rb
98
+ - lib/braid/commands/push.rb
99
+ - lib/braid/commands/remove.rb
100
+ - lib/braid/commands/setup.rb
101
+ - lib/braid/commands/update.rb
102
+ - lib/braid/config.rb
103
+ - lib/braid/mirror.rb
104
+ - lib/braid/operations.rb
105
+ - lib/braid/version.rb
106
+ - lib/core_ext.rb
107
+ - test/braid_test.rb
108
+ - test/config_test.rb
109
+ - test/fixtures/shiny/README
110
+ - test/fixtures/skit1.1/layouts/layout.liquid
111
+ - test/fixtures/skit1.2/layouts/layout.liquid
112
+ - test/fixtures/skit1/layouts/layout.liquid
113
+ - test/fixtures/skit1/preview.png
114
+ - test/integration/adding_test.rb
115
+ - test/integration/updating_test.rb
116
+ - test/integration_helper.rb
117
+ - test/mirror_test.rb
118
+ - test/operations_test.rb
119
+ - test/test_helper.rb
120
+ homepage: http://evil.che.lu/projects/braid
121
+ licenses: []
122
+ post_install_message:
123
+ rdoc_options:
124
+ - --line-numbers
125
+ - --inline-source
126
+ - --title
127
+ - braid
128
+ - --main
129
+ require_paths:
130
+ - lib
131
+ required_ruby_version: !ruby/object:Gem::Requirement
132
+ none: false
133
+ requirements:
134
+ - - ! '>='
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ segments:
138
+ - 0
139
+ hash: 4601304509761184650
140
+ required_rubygems_version: !ruby/object:Gem::Requirement
141
+ none: false
142
+ requirements:
143
+ - - ! '>='
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ segments:
147
+ - 0
148
+ hash: 4601304509761184650
149
+ requirements: []
150
+ rubyforge_project: braid
151
+ rubygems_version: 1.8.23
152
+ signing_key:
153
+ specification_version: 3
154
+ summary: A simple tool for tracking vendor branches in git.
155
+ test_files: []