braid 1.0.21 → 1.0.22
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +0 -1
- data/bin/braid +13 -7
- data/braid.gemspec +1 -1
- data/lib/braid/commands/diff.rb +1 -0
- data/lib/braid/mirror.rb +16 -1
- data/lib/braid/operations.rb +2 -51
- data/lib/braid/version.rb +1 -1
- data/spec/integration/diff_spec.rb +50 -22
- data/spec/mirror_spec.rb +0 -27
- metadata +3 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ab9eeee697a55d6b0126b0b7fc83f1ef5bcd72ce
|
4
|
+
data.tar.gz: 592d7f2a02f89a1afa3accb32c3e8ab910982ba8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e0e1aab9e20c6be6b449c14e9c8c9b768e71b58bc81634e737b83358172a39b62044f92cc0dc8e7fb2eb48045ea4b3dfed67b19ac22faae335619040265a2869
|
7
|
+
data.tar.gz: 644e0aced9a33f47309f1bf6df77c31e7098b9292e3133a1e44e7f5852b7f2d749f02147425b73f949f9e39d444cc1aa156897613450953906f073ff062d3231
|
data/.travis.yml
CHANGED
data/bin/braid
CHANGED
@@ -1,6 +1,18 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
|
3
|
+
# Duplicated from Braid::Command.run. :(
|
4
|
+
def die(msg)
|
5
|
+
puts "Braid: Error: #{msg}"
|
6
|
+
exit(1)
|
7
|
+
end
|
8
|
+
|
9
|
+
# If we assume Ruby >= 2.0, we can use __dir__.
|
10
|
+
libdir = File.expand_path(File.dirname(File.realpath(__FILE__)) + '/../lib')
|
11
|
+
unless File.exists?(libdir)
|
12
|
+
# Don't silently fall back to a different globally installed copy of Braid!
|
13
|
+
die "Cannot find Braid's 'lib' directory."
|
14
|
+
end
|
15
|
+
$LOAD_PATH.unshift(libdir)
|
4
16
|
require 'braid'
|
5
17
|
|
6
18
|
require 'rubygems'
|
@@ -20,12 +32,6 @@ Main {
|
|
20
32
|
You can then merge back or cherry-pick changes.
|
21
33
|
TXT
|
22
34
|
|
23
|
-
# Duplicated from Braid::Command.run. :(
|
24
|
-
def die(msg)
|
25
|
-
puts "Braid: Error: #{msg}"
|
26
|
-
exit(1)
|
27
|
-
end
|
28
|
-
|
29
35
|
# The "main" library doesn't provide a way to do this??
|
30
36
|
def check_no_extra_args!
|
31
37
|
if @argv.length > 0
|
data/braid.gemspec
CHANGED
@@ -25,8 +25,8 @@ Gem::Specification.new do |s|
|
|
25
25
|
s.has_rdoc = false
|
26
26
|
s.rdoc_options = %w(--line-numbers --inline-source --title braid --main)
|
27
27
|
|
28
|
+
s.required_ruby_version = '>= 2.2.0'
|
28
29
|
s.add_dependency(%q<main>, ['>= 4.7.3'])
|
29
|
-
s.add_dependency(%q<open4>, ['>= 1.0.1']) unless defined?(JRUBY_VERSION)
|
30
30
|
|
31
31
|
s.add_development_dependency(%q<rspec>, ['>= 3.4.4'])
|
32
32
|
s.add_development_dependency(%q<mocha>, ['>= 0.9.11'])
|
data/lib/braid/commands/diff.rb
CHANGED
@@ -31,6 +31,7 @@ module Braid
|
|
31
31
|
def show_diff(path, options = {})
|
32
32
|
mirror = config.get!(path)
|
33
33
|
setup_remote(mirror)
|
34
|
+
mirror.fetch_base_revision_if_missing
|
34
35
|
|
35
36
|
# We do not need to spend the time to copy the content outside the
|
36
37
|
# mirror from HEAD because --relative will exclude it anyway. Rename
|
data/lib/braid/mirror.rb
CHANGED
@@ -64,12 +64,27 @@ module Braid
|
|
64
64
|
end
|
65
65
|
|
66
66
|
def diff
|
67
|
-
|
67
|
+
fetch_base_revision_if_missing
|
68
68
|
remote_hash = git.rev_parse(versioned_path(base_revision))
|
69
69
|
local_hash = git.tree_hash(path)
|
70
70
|
remote_hash != local_hash ? git.diff_tree(remote_hash, local_hash) : ''
|
71
71
|
end
|
72
72
|
|
73
|
+
# Re-fetching the remote after deleting and re-adding it may be slow even if
|
74
|
+
# all objects are still present in the repository
|
75
|
+
# (https://github.com/cristibalan/braid/issues/71). Mitigate this for
|
76
|
+
# `braid diff` and other commands that need the diff by skipping the fetch
|
77
|
+
# if the base revision is already present in the repository.
|
78
|
+
def fetch_base_revision_if_missing
|
79
|
+
begin
|
80
|
+
# Without ^{commit}, this will happily pass back an object hash even if
|
81
|
+
# the object isn't present. See the git-rev-parse(1) man page.
|
82
|
+
git.rev_parse(base_revision + "^{commit}")
|
83
|
+
rescue Operations::UnknownRevision
|
84
|
+
fetch
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
73
88
|
def fetch
|
74
89
|
git_cache.fetch(url) if cached?
|
75
90
|
git.fetch(remote)
|
data/lib/braid/operations.rb
CHANGED
@@ -3,8 +3,7 @@ require 'rubygems'
|
|
3
3
|
require 'tempfile'
|
4
4
|
|
5
5
|
module Braid
|
6
|
-
|
7
|
-
require USE_OPEN3 ? 'open3' : 'open4'
|
6
|
+
require 'open3'
|
8
7
|
|
9
8
|
module Operations
|
10
9
|
class ShellExecutionError < BraidError
|
@@ -111,29 +110,8 @@ module Braid
|
|
111
110
|
cmd.strip!
|
112
111
|
|
113
112
|
Operations::with_modified_environment({'LANG' => 'C'}) do
|
114
|
-
out, err = nil
|
115
|
-
status, pid = 0
|
116
113
|
log(cmd)
|
117
|
-
|
118
|
-
if USE_OPEN3
|
119
|
-
status = nil
|
120
|
-
Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thread|
|
121
|
-
# Under old jrubies this may sometimes throw an exception
|
122
|
-
stdin.close rescue nil
|
123
|
-
out = stdout.read
|
124
|
-
err = stderr.read
|
125
|
-
# Under earlier jrubies this is not correctly passed so add in check
|
126
|
-
status = wait_thread.value if wait_thread # Process::Status object returned.
|
127
|
-
end
|
128
|
-
# Handle earlier jrubies such as 1.6.7.2
|
129
|
-
status = $?.exitstatus if status.nil?
|
130
|
-
else
|
131
|
-
status = Open4.popen4(cmd) do |pid, stdin, stdout, stderr|
|
132
|
-
out = stdout.read
|
133
|
-
err = stderr.read
|
134
|
-
end.exitstatus
|
135
|
-
end
|
136
|
-
|
114
|
+
out, err, status = Open3.capture3(cmd)
|
137
115
|
[status, out, err]
|
138
116
|
end
|
139
117
|
end
|
@@ -402,33 +380,6 @@ module Braid
|
|
402
380
|
out[2..-1]
|
403
381
|
end
|
404
382
|
|
405
|
-
def apply(diff, *args)
|
406
|
-
status, err = nil, nil
|
407
|
-
|
408
|
-
command = "git apply --index --whitespace=nowarn #{args.join(' ')} -"
|
409
|
-
|
410
|
-
if USE_OPEN3
|
411
|
-
Open3.popen3(command) do |stdin, stdout, stderr, wait_thread|
|
412
|
-
stdin.puts(diff)
|
413
|
-
stdin.close
|
414
|
-
err = stderr.read
|
415
|
-
# Under earlier jrubies this is not correctly passed so add in check
|
416
|
-
status = wait_thread.value if wait_thread # Process::Status object returned.
|
417
|
-
end
|
418
|
-
# Handle earlier jrubies such as 1.6.7.2
|
419
|
-
status = $?.exitstatus if status.nil?
|
420
|
-
else
|
421
|
-
status = Open4.popen4(command) do |pid, stdin, stdout, stderr|
|
422
|
-
stdin.puts(diff)
|
423
|
-
stdin.close
|
424
|
-
err = stderr.read
|
425
|
-
end.exitstatus
|
426
|
-
end
|
427
|
-
|
428
|
-
raise ShellExecutionError, err unless status == 0
|
429
|
-
true
|
430
|
-
end
|
431
|
-
|
432
383
|
def clone(*args)
|
433
384
|
# overrides builtin
|
434
385
|
invoke(:clone, *args)
|
data/lib/braid/version.rb
CHANGED
@@ -47,13 +47,7 @@ describe 'Running braid diff with a mirror' do
|
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
|
-
|
51
|
-
diff = nil
|
52
|
-
in_dir(@repository_dir) do
|
53
|
-
diff = run_command("#{BRAID_BIN} diff skit1")
|
54
|
-
end
|
55
|
-
|
56
|
-
expect(diff).to eq(<<PATCH)
|
50
|
+
EXPECTED_DIFF=<<PATCH
|
57
51
|
diff --git a/layouts/layout.liquid b/layouts/layout.liquid
|
58
52
|
index 9f75009..25a4b32 100644
|
59
53
|
--- a/layouts/layout.liquid
|
@@ -68,6 +62,14 @@ index 9f75009..25a4b32 100644
|
|
68
62
|
|
69
63
|
<div id="wrapper">
|
70
64
|
PATCH
|
65
|
+
|
66
|
+
it 'with the mirror specified should emit diff' do
|
67
|
+
diff = nil
|
68
|
+
in_dir(@repository_dir) do
|
69
|
+
diff = run_command("#{BRAID_BIN} diff skit1")
|
70
|
+
end
|
71
|
+
|
72
|
+
expect(diff).to eq(EXPECTED_DIFF)
|
71
73
|
end
|
72
74
|
|
73
75
|
it 'without specifying a mirror should emit diff and banners' do
|
@@ -76,24 +78,50 @@ PATCH
|
|
76
78
|
diff = run_command("#{BRAID_BIN} diff")
|
77
79
|
end
|
78
80
|
|
79
|
-
expect(diff).to eq(<<
|
81
|
+
expect(diff).to eq(<<BANNER + EXPECTED_DIFF)
|
80
82
|
=======================================================
|
81
83
|
Braid: Diffing skit1
|
82
84
|
=======================================================
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
85
|
+
BANNER
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'in a new clone of the downstream repository should fetch the base revision and emit diff' do
|
89
|
+
diff = nil
|
90
|
+
CLONE_NAME = 'shiny-clone'
|
91
|
+
in_dir(TMP_PATH) do
|
92
|
+
run_command("git clone --quiet #{@repository_dir} #{CLONE_NAME}")
|
93
|
+
end
|
94
|
+
clone_dir = File.join(TMP_PATH, CLONE_NAME)
|
95
|
+
in_dir(clone_dir) do
|
96
|
+
diff = run_command("#{BRAID_BIN} diff skit1")
|
97
|
+
end
|
98
|
+
|
99
|
+
expect(diff).to eq(EXPECTED_DIFF)
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'after pruning the base revision from the repository should fetch it again and emit diff' do
|
103
|
+
# Note: It is not the intent of this test case to require that Braid
|
104
|
+
# leave objects from the mirror in the main repository after it exits.
|
105
|
+
# A design change to stop doing that would legitimately require this
|
106
|
+
# test case to be modified or dropped.
|
107
|
+
diff = nil
|
108
|
+
in_dir(@repository_dir) do
|
109
|
+
status_out = run_command("#{BRAID_BIN} status skit1")
|
110
|
+
base_revision = /^skit1 \(([0-9a-f]{40})\)/.match(status_out)[1]
|
111
|
+
# Make sure the base revision is in the repository as a sanity check.
|
112
|
+
run_command("git rev-parse --verify --quiet #{base_revision}^{commit}")
|
113
|
+
run_command("git gc --quiet --prune=all")
|
114
|
+
# Make sure it's gone now so we know we're actually testing Braid's fetch behavior.
|
115
|
+
`git rev-parse --verify --quiet #{base_revision}^{commit}`
|
116
|
+
raise "'git gc' did not delete the base revision from the repository." if $?.success?
|
117
|
+
|
118
|
+
diff = run_command("#{BRAID_BIN} diff skit1")
|
119
|
+
|
120
|
+
# The base revision should be present again.
|
121
|
+
run_command("git rev-parse --verify --quiet #{base_revision}^{commit}")
|
122
|
+
end
|
123
|
+
|
124
|
+
expect(diff).to eq(EXPECTED_DIFF)
|
97
125
|
end
|
98
126
|
end
|
99
127
|
|
data/spec/mirror_spec.rb
CHANGED
@@ -69,33 +69,6 @@ describe 'Braid::Mirror.new_from_options' do
|
|
69
69
|
|
70
70
|
end
|
71
71
|
|
72
|
-
describe 'Braid::Mirror#diff' do
|
73
|
-
before(:each) do
|
74
|
-
@mirror = build_mirror('revision' => 'a' * 40, 'url' => 'git://path')
|
75
|
-
@mirror.stubs(:base_revision).returns(@mirror.revision) # bypass rev_parse
|
76
|
-
end
|
77
|
-
|
78
|
-
def set_hashes(remote_hash, local_hash)
|
79
|
-
git.expects(:rev_parse).with("#{@mirror.revision}:").returns(remote_hash)
|
80
|
-
git.expects(:tree_hash).with(@mirror.path).returns(local_hash)
|
81
|
-
end
|
82
|
-
|
83
|
-
it 'should return an empty string when the hashes match' do
|
84
|
-
set_hashes('b' * 40, 'b' * 40)
|
85
|
-
git.expects(:fetch)
|
86
|
-
git.expects(:diff_tree).never
|
87
|
-
expect(@mirror.diff).to eq('')
|
88
|
-
end
|
89
|
-
|
90
|
-
it 'should generate a diff when the hashes do not match' do
|
91
|
-
set_hashes('b' * 40, 'c' * 40)
|
92
|
-
diff = "diff --git a/path b/path\n"
|
93
|
-
git.expects(:fetch)
|
94
|
-
git.expects(:diff_tree).with('b' * 40, 'c' * 40).returns(diff)
|
95
|
-
expect(@mirror.diff).to eq(diff)
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
72
|
describe 'Braid::Mirror#base_revision' do
|
100
73
|
it 'should be inferred when no revision is set' do
|
101
74
|
@mirror = build_mirror
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: braid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.22
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cristi Balan
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2017-
|
13
|
+
date: 2017-12-30 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: main
|
@@ -26,20 +26,6 @@ dependencies:
|
|
26
26
|
- - ">="
|
27
27
|
- !ruby/object:Gem::Version
|
28
28
|
version: 4.7.3
|
29
|
-
- !ruby/object:Gem::Dependency
|
30
|
-
name: open4
|
31
|
-
requirement: !ruby/object:Gem::Requirement
|
32
|
-
requirements:
|
33
|
-
- - ">="
|
34
|
-
- !ruby/object:Gem::Version
|
35
|
-
version: 1.0.1
|
36
|
-
type: :runtime
|
37
|
-
prerelease: false
|
38
|
-
version_requirements: !ruby/object:Gem::Requirement
|
39
|
-
requirements:
|
40
|
-
- - ">="
|
41
|
-
- !ruby/object:Gem::Version
|
42
|
-
version: 1.0.1
|
43
29
|
- !ruby/object:Gem::Dependency
|
44
30
|
name: rspec
|
45
31
|
requirement: !ruby/object:Gem::Requirement
|
@@ -140,7 +126,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
140
126
|
requirements:
|
141
127
|
- - ">="
|
142
128
|
- !ruby/object:Gem::Version
|
143
|
-
version:
|
129
|
+
version: 2.2.0
|
144
130
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
145
131
|
requirements:
|
146
132
|
- - ">="
|