From 01476fffba362826cf7f39f3d3af56fd3c3dc625 Mon Sep 17 00:00:00 2001 From: Tim Morgan Date: Fri, 11 May 2012 15:34:16 -0700 Subject: [PATCH 1/9] Added git-blame command --- lib/git.rb | 1 + lib/git/base.rb | 6 ++++++ lib/git/blame.rb | 46 ++++++++++++++++++++++++++++++++++++++++++++++ lib/git/lib.rb | 25 +++++++++++++++++++++++++ 4 files changed, 78 insertions(+) create mode 100644 lib/git/blame.rb diff --git a/lib/git.rb b/lib/git.rb index acf7d1b3..c4a09846 100644 --- a/lib/git.rb +++ b/lib/git.rb @@ -13,6 +13,7 @@ require 'git/working_directory' require 'git/log' +require 'git/blame' require 'git/object' require 'git/branches' diff --git a/lib/git/base.rb b/lib/git/base.rb index 5ad8906a..75abe4a3 100644 --- a/lib/git/base.rb +++ b/lib/git/base.rb @@ -170,6 +170,12 @@ def log(count = 30) Git::Log.new(self, count) end + # returns a Git::BlameResult object with the commits that most recently + # modified each line + def blame(file, opts={}) + Git::Blame.new(self, file, opts).result + end + # returns a Git::Status object def status Git::Status.new(self) diff --git a/lib/git/blame.rb b/lib/git/blame.rb new file mode 100644 index 00000000..3651fdf3 --- /dev/null +++ b/lib/git/blame.rb @@ -0,0 +1,46 @@ +class Git::Blame + attr_reader :result + + def initialize(base, file, opts={}) + @base = base + @file = file + @options = opts + + @result = run_blame + end + + private + + def run_blame + lines = @base.lib.blame(@file, @options) + result = Git::BlameResult.new(@base) + lines.each do |line| + words = line.split(/\s+/) + next unless words.first.length == 40 #TODO this breaks if git ever introduces a 40-character attribute name + ref = words[0] + block_start = words[2].to_i + block_length = words[3].to_i + result.add_block ref, block_start, block_length + end + result + end +end + +class Git::BlameResult + delegate :[], :each, :each_with_index, to: :lines + + def initialize(base) + @base = base + @commit_cache = {} + @lines = [] + end + + def add_block(ref, start, length) + commit = (@commit_cache[ref] ||= @base.object(ref)) + length.times { |i| @lines[start + i] = commit } + commit + end + + attr_reader :lines + private :lines +end diff --git a/lib/git/lib.rb b/lib/git/lib.rb index 52fb2e6c..d1145e22 100644 --- a/lib/git/lib.rb +++ b/lib/git/lib.rb @@ -92,6 +92,31 @@ def full_log_commits(opts = {}) full_log = command_lines('log', arr_opts, true) process_commit_data(full_log) end + + def blame(file, opts={}) + arr_opts = %w( --incremental ) + arr_opts << "-L#{opts[:start]},#{opts[:end]}" if opts[:start] && opts[:end] + arr_opts << '--reverse' if opts[:reverse] + case opts[:detect_intrafile_moves] + when true then arr_opts << '-M' + when Fixnum then arr_opts << "-M#{opts[:detect_intrafile_moves]}" + end + if opts[:detect_interfile_moves] + c_opt = if opts[:check_all_commits_for_interfile_moves] + '-CCC' + elsif opts[:check_first_file_commit_for_interfile_moves] + '-CC' + else + '-C' + end + c_opt << opts[:detect_interfile_moves] if opts[:detect_interfile_moves].kind_of?(Fixnum) + end + arr_opts << '-w' if opts[:ignore_whitespace] + arr_opts << opts[:revision] if opts[:revision] + arr_opts << '--' << file + + command_lines 'blame', arr_opts + end def revparse(string) return string if string =~ /[A-Fa-f0-9]{40}/ # passing in a sha - just no-op it From 0e64b62c8bd80cd4b3d3abaa3a44eaf18f3e3e2c Mon Sep 17 00:00:00 2001 From: Tim Morgan Date: Mon, 14 May 2012 10:52:13 -0700 Subject: [PATCH 2/9] Return nil if the objectish doesn't exist --- lib/git/base.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/git/base.rb b/lib/git/base.rb index 75abe4a3..c589c9d7 100644 --- a/lib/git/base.rb +++ b/lib/git/base.rb @@ -150,7 +150,10 @@ def config(name = nil, value = nil) # on the objectish and determine the type of the object and return # an appropriate object for that type def object(objectish) + return nil unless objectish Git::Object.new(self, objectish) + rescue Git::GitExecuteError + return nil # unknown revision end def gtree(objectish) From da66aa81ff9a8d0654891dd28227419d8132d983 Mon Sep 17 00:00:00 2001 From: Tim Morgan Date: Mon, 14 May 2012 14:45:54 -0700 Subject: [PATCH 3/9] Add --mirror option to git-clone --- lib/git/lib.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/git/lib.rb b/lib/git/lib.rb index d1145e22..41184452 100644 --- a/lib/git/lib.rb +++ b/lib/git/lib.rb @@ -47,6 +47,7 @@ def clone(repository, name, opts = {}) arr_opts = [] arr_opts << "--bare" if opts[:bare] + arr_opts << "--mirror" if opts[:mirror] arr_opts << "-o" << opts[:remote] if opts[:remote] arr_opts << "--depth" << opts[:depth].to_i if opts[:depth] && opts[:depth].to_i > 0 @@ -56,7 +57,7 @@ def clone(repository, name, opts = {}) command('clone', arr_opts) - opts[:bare] ? {:repository => clone_dir} : {:working_directory => clone_dir} + (opts[:bare] || opts[:mirror]) ? {:repository => clone_dir} : {:working_directory => clone_dir} end From e6a872b87743f528a0e0332514dd1d141146d963 Mon Sep 17 00:00:00 2001 From: Tim Morgan Date: Mon, 14 May 2012 15:29:30 -0700 Subject: [PATCH 4/9] Fix for JRuby --- lib/git/path.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/git/path.rb b/lib/git/path.rb index 87f5c84e..f81f6f5b 100644 --- a/lib/git/path.rb +++ b/lib/git/path.rb @@ -7,7 +7,7 @@ def initialize(path, check_path = true) if !check_path || File.exists?(path) @path = File.expand_path(path) else - raise ArgumentError, "path does not exist", File.expand_path(path) + raise ArgumentError, "path does not exist: #{File.expand_path(path)}" end end @@ -24,4 +24,4 @@ def to_s end end -end \ No newline at end of file +end From 473d8ecc1fd49cbfcbabff0061484319d4bac9fa Mon Sep 17 00:00:00 2001 From: Tim Morgan Date: Thu, 21 Jun 2012 11:03:55 -0700 Subject: [PATCH 5/9] I guess trees can have commits in them too --- lib/git/lib.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/git/lib.rb b/lib/git/lib.rb index 41184452..433b253b 100644 --- a/lib/git/lib.rb +++ b/lib/git/lib.rb @@ -194,7 +194,7 @@ def object_contents(sha, &block) end def ls_tree(sha) - data = {'blob' => {}, 'tree' => {}} + data = {'blob' => {}, 'tree' => {}, 'commit' => {}, 'tag' => {}} command_lines('ls-tree', sha).each do |line| (info, filenm) = line.split("\t") From 1fe5b805dc76fde0d3fa61d6d934f102d9a2a8de Mon Sep 17 00:00:00 2001 From: William Harris Date: Mon, 4 Feb 2013 16:20:14 -0600 Subject: [PATCH 6/9] make sure git log commands have no color characters I think I needed this becuase I have color always in my .gitconfig --- lib/git/lib.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/git/lib.rb b/lib/git/lib.rb index 433b253b..2cf6ea0b 100644 --- a/lib/git/lib.rb +++ b/lib/git/lib.rb @@ -66,6 +66,7 @@ def clone(repository, name, opts = {}) def log_commits(opts = {}) arr_opts = ['--pretty=oneline'] + arr_opts << ['--no-color'] arr_opts << "-#{opts[:count]}" if opts[:count] arr_opts << "--since=#{opts[:since]}" if opts[:since].is_a? String arr_opts << "--until=#{opts[:until]}" if opts[:until].is_a? String @@ -80,6 +81,7 @@ def log_commits(opts = {}) def full_log_commits(opts = {}) arr_opts = ['--pretty=raw'] + arr_opts << ['--no-color'] arr_opts << "-#{opts[:count]}" if opts[:count] arr_opts << "--skip=#{opts[:skip]}" if opts[:skip] arr_opts << "--since=#{opts[:since]}" if opts[:since].is_a? String From 6ab7a7045f4f672a750fde18d9c484402b67b949 Mon Sep 17 00:00:00 2001 From: Tim Morgan Date: Tue, 26 Mar 2013 18:36:41 -0700 Subject: [PATCH 7/9] Fix bug where UTF-16-encoded blobs were improperly chomped as if they were UTF-8 encoded --- lib/git/lib.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/git/lib.rb b/lib/git/lib.rb index 2cf6ea0b..b827e53a 100644 --- a/lib/git/lib.rb +++ b/lib/git/lib.rb @@ -734,7 +734,7 @@ def run_command(git_cmd, &block) if block_given? IO.popen(git_cmd, &block) else - `#{git_cmd}`.chomp + `#{git_cmd}` end end From 2d2204aaa1b5f8fdea042c208503fc5ec08e7be4 Mon Sep 17 00:00:00 2001 From: Tim Morgan Date: Wed, 27 Mar 2013 10:05:16 -0700 Subject: [PATCH 8/9] Chomp newlines except for object_contents --- lib/git/lib.rb | 92 +++++++++++++++++++++++++------------------------- 1 file changed, 46 insertions(+), 46 deletions(-) diff --git a/lib/git/lib.rb b/lib/git/lib.rb index b827e53a..98dafe64 100644 --- a/lib/git/lib.rb +++ b/lib/git/lib.rb @@ -26,7 +26,7 @@ def initialize(base = nil, logger = nil) end def init - command('init') + command('init').chomp end # tries to clone the given repo @@ -55,7 +55,7 @@ def clone(repository, name, opts = {}) arr_opts << repository arr_opts << clone_dir - command('clone', arr_opts) + command('clone', arr_opts).chomp (opts[:bare] || opts[:mirror]) ? {:repository => clone_dir} : {:working_directory => clone_dir} end @@ -129,15 +129,15 @@ def revparse(string) File.file?(path) end return File.read(rev).chomp if rev - command('rev-parse', string) + command('rev-parse', string).chomp end def namerev(string) - command('name-rev', string).split[1] + command('name-rev', string).split[1].chomp end def object_type(sha) - command('cat-file', ['-t', sha]) + command('cat-file', ['-t', sha]).chomp end def object_size(sha) @@ -220,7 +220,7 @@ def tree_depth(sha) end def change_head_branch(branch_name) - command('symbolic-ref', ['HEAD', "refs/heads/#{branch_name}"]) + command('symbolic-ref', ['HEAD', "refs/heads/#{branch_name}"]).chomp end def branches_all @@ -274,7 +274,7 @@ def diff_full(obj1 = 'HEAD', obj2 = nil, opts = {}) diff_opts << obj2 if obj2.is_a?(String) diff_opts << '--' << opts[:path_limiter] if opts[:path_limiter].is_a? String - command('diff', diff_opts) + command('diff', diff_opts).chomp end def diff_stats(obj1 = 'HEAD', obj2 = nil, opts = {}) @@ -350,7 +350,7 @@ def config_remote(name) def config_get(name) do_get = lambda do - command('config', ['--get', name]) + command('config', ['--get', name]).chomp end if @git_dir @@ -361,7 +361,7 @@ def config_get(name) end def global_config_get(name) - command('config', ['--global', '--get', name], false) + command('config', ['--global', '--get', name], false).chomp end def config_list @@ -413,11 +413,11 @@ def parse_config(file) ## WRITE COMMANDS ## def config_set(name, value) - command('config', [name, value]) + command('config', [name, value]).chomp end def global_config_set(name, value) - command('config', ['--global', name, value], false) + command('config', ['--global', name, value], false).chomp end def add(path = '.') @@ -427,7 +427,7 @@ def add(path = '.') else arr_opts << path end - command('add', arr_opts) + command('add', arr_opts).chomp end def remove(path = '.', opts = {}) @@ -440,7 +440,7 @@ def remove(path = '.', opts = {}) arr_opts << path end - command('rm', arr_opts) + command('rm', arr_opts).chomp end def commit(message, opts = {}) @@ -448,26 +448,26 @@ def commit(message, opts = {}) arr_opts << '-a' if opts[:add_all] arr_opts << '--allow-empty' if opts[:allow_empty] arr_opts << "--author" << opts[:author] if opts[:author] - command('commit', arr_opts) + command('commit', arr_opts).chomp end def reset(commit, opts = {}) arr_opts = [] arr_opts << '--hard' if opts[:hard] arr_opts << commit if commit - command('reset', arr_opts) + command('reset', arr_opts).chomp end def apply(patch_file) arr_opts = [] arr_opts << '--' << patch_file if patch_file - command('apply', arr_opts) + command('apply', arr_opts).chomp end def apply_mail(patch_file) arr_opts = [] arr_opts << '--' << patch_file if patch_file - command('am', arr_opts) + command('am', arr_opts).chomp end def stashes_all @@ -483,32 +483,32 @@ def stashes_all end def stash_save(message) - output = command('stash save', ['--', message]) + output = command('stash save', ['--', message]).chomp output =~ /HEAD is now at/ end def stash_apply(id = nil) if id - command('stash apply', [id]) + command('stash apply', [id]).chomp else - command('stash apply') + command('stash apply').chomp end end def stash_clear - command('stash clear') + command('stash clear').chomp end def stash_list - command('stash list') + command('stash list').chomp end def branch_new(branch) - command('branch', branch) + command('branch', branch).chomp end def branch_delete(branch) - command('branch', ['-D', branch]) + command('branch', ['-D', branch]).chomp end def checkout(branch, opts = {}) @@ -517,21 +517,21 @@ def checkout(branch, opts = {}) arr_opts << '-b' << opts[:new_branch] if opts[:new_branch] arr_opts << branch - command('checkout', arr_opts) + command('checkout', arr_opts).chomp end def checkout_file(version, file) arr_opts = [] arr_opts << version arr_opts << file - command('checkout', arr_opts) + command('checkout', arr_opts).chomp end def merge(branch, message = nil) arr_opts = [] arr_opts << '-m' << message if message arr_opts += [branch] - command('merge', arr_opts) + command('merge', arr_opts).chomp end def unmerged @@ -545,10 +545,10 @@ def unmerged def conflicts # :yields: file, your, their self.unmerged.each do |f| your = Tempfile.new("YOUR-#{File.basename(f)}").path - command('show', ":2:#{f}", true, "> #{escape your}") + command('show', ":2:#{f}", true, "> #{escape your}").chomp their = Tempfile.new("THEIR-#{File.basename(f)}").path - command('show', ":3:#{f}", true, "> #{escape their}") + command('show', ":3:#{f}", true, "> #{escape their}").chomp yield(f, your, their) end end @@ -560,13 +560,13 @@ def remote_add(name, url, opts = {}) arr_opts << name arr_opts << url - command('remote', arr_opts) + command('remote', arr_opts).chomp end # this is documented as such, but seems broken for some reason # i'll try to get around it some other way later def remote_remove(name) - command('remote', ['rm', '--', name]) + command('remote', ['rm', '--', name]).chomp end def remotes @@ -578,32 +578,32 @@ def tags end def tag(tag) - command('tag', tag) + command('tag', tag).chomp end def fetch(remote) - command('fetch', remote) + command('fetch', remote).chomp end def push(remote, branch = 'master', tags = false) - command('push', [remote, branch]) - command('push', ['--tags', remote]) if tags + command('push', [remote, branch]).chomp + command('push', ['--tags', remote]) if tags.chomp end def tag_sha(tag_name) head = File.join(@git_dir, 'refs', 'tags', tag_name) return File.read(head).chomp if File.exists?(head) - command('show-ref', ['--tags', '-s', tag_name]) + command('show-ref', ['--tags', '-s', tag_name]).chomp end def repack - command('repack', ['-a', '-d']) + command('repack', ['-a', '-d']).chomp end def gc - command('gc', ['--prune', '--aggressive', '--auto']) + command('gc', ['--prune', '--aggressive', '--auto']).chomp end # reads a tree into the current index file @@ -611,11 +611,11 @@ def read_tree(treeish, opts = {}) arr_opts = [] arr_opts << "--prefix=#{opts[:prefix]}" if opts[:prefix] arr_opts += [treeish] - command('read-tree', arr_opts) + command('read-tree', arr_opts).chomp end def write_tree - command('write-tree') + command('write-tree').chomp end def commit_tree(tree, opts = {}) @@ -628,11 +628,11 @@ def commit_tree(tree, opts = {}) arr_opts << tree arr_opts << '-p' << opts[:parent] if opts[:parent] arr_opts += [opts[:parents]].map { |p| ['-p', p] }.flatten if opts[:parents] - command('commit-tree', arr_opts, true, "< #{escape t.path}") + command('commit-tree', arr_opts, true, "< #{escape t.path}").chomp end def update_ref(branch, commit) - command('update-ref', [branch, commit]) + command('update-ref', [branch, commit]).chomp end def checkout_index(opts = {}) @@ -642,7 +642,7 @@ def checkout_index(opts = {}) arr_opts << "--all" if opts[:all] arr_opts << '--' << opts[:path_limiter] if opts[:path_limiter].is_a? String - command('checkout-index', arr_opts) + command('checkout-index', arr_opts).chomp end # creates an archive file @@ -668,13 +668,13 @@ def archive(sha, file = nil, opts = {}) arr_opts << "--remote=#{opts[:remote]}" if opts[:remote] arr_opts << sha arr_opts << '--' << opts[:path] if opts[:path] - command('archive', arr_opts, true, (opts[:add_gzip] ? '| gzip' : '') + " > #{escape file}") + command('archive', arr_opts, true, (opts[:add_gzip] ? '| gzip' : '') + " > #{escape file}").chomp return file end # returns the current version of git, as an Array of Fixnums. def current_command_version - output = command('version', [], false) + output = command('version', [], false).chomp version = output[/\d+\.\d+(\.\d+)+/] version.split('.').collect {|i| i.to_i} end @@ -697,7 +697,7 @@ def meets_required_version? private def command_lines(cmd, opts = [], chdir = true, redirect = '') - command(cmd, opts, chdir).split("\n") + command(cmd, opts, chdir).chomp.split("\n") end def command(cmd, opts = [], chdir = true, redirect = '', &block) From 2da2ed301fc5d2f9cb3125bd78db0522b322ed84 Mon Sep 17 00:00:00 2001 From: Tim Morgan Date: Tue, 14 May 2013 23:52:40 -0700 Subject: [PATCH 9/9] Spec fixes --- lib/git/blame.rb | 4 +++- lib/git/lib.rb | 2 +- tests/units/test_archive.rb | 12 ++++++------ tests/units/test_index_ops.rb | 4 ++-- tests/units/test_lib.rb | 6 +++--- tests/units/test_object.rb | 4 ++-- 6 files changed, 17 insertions(+), 15 deletions(-) mode change 100644 => 100755 tests/units/test_archive.rb mode change 100644 => 100755 tests/units/test_index_ops.rb mode change 100644 => 100755 tests/units/test_lib.rb mode change 100644 => 100755 tests/units/test_object.rb diff --git a/lib/git/blame.rb b/lib/git/blame.rb index 3651fdf3..fb36f151 100644 --- a/lib/git/blame.rb +++ b/lib/git/blame.rb @@ -27,7 +27,9 @@ def run_blame end class Git::BlameResult - delegate :[], :each, :each_with_index, to: :lines + def [](*args) lines[*args] end + def each(*args, &block) lines.each(*args, &block) end + def each_with_index(*args, &block) lines.each_with_index(*args, &block) end def initialize(base) @base = base diff --git a/lib/git/lib.rb b/lib/git/lib.rb index c34e0624..3eb1e250 100644 --- a/lib/git/lib.rb +++ b/lib/git/lib.rb @@ -565,7 +565,7 @@ def fetch(remote) def push(remote, branch = 'master', tags = false) command('push', [remote, branch]).chomp - command('push', ['--tags', remote]) if tags.chomp + command('push', ['--tags', remote]).chomp if tags end def tag_sha(tag_name) diff --git a/tests/units/test_archive.rb b/tests/units/test_archive.rb old mode 100644 new mode 100755 index efff94a3..0994389b --- a/tests/units/test_archive.rb +++ b/tests/units/test_archive.rb @@ -26,9 +26,9 @@ def test_archive f = @git.object('v2.6').archive(nil, :format => 'tar') # returns path to temp file assert(File.exists?(f)) - lines = `cd /tmp; tar xvpf #{f}`.split("\n") - assert_equal('ex_dir/', lines[0]) - assert_equal('example.txt', lines[2]) + lines = `cd /tmp; tar xvpf #{f} 2>&1`.split("\n") + assert_equal('x ex_dir/', lines[0]) + assert_equal('x example.txt', lines[2]) f = @git.object('v2.6').archive(tempfile, :format => 'zip') assert(File.file?(f)) @@ -39,9 +39,9 @@ def test_archive f = @git.object('v2.6').archive(tempfile, :format => 'tar', :prefix => 'test/', :path => 'ex_dir/') assert(File.exists?(f)) - lines = `cd /tmp; tar xvpf #{f}`.split("\n") - assert_equal('test/', lines[0]) - assert_equal('test/ex_dir/ex.txt', lines[2]) + lines = `cd /tmp; tar xvpf #{f} 2>&1`.split("\n") + assert_equal('x test/', lines[0]) + assert_equal('x test/ex_dir/ex.txt', lines[2]) in_temp_dir do c = Git.clone(@wbare, 'new') diff --git a/tests/units/test_index_ops.rb b/tests/units/test_index_ops.rb old mode 100644 new mode 100755 index dcd84984..27115b40 --- a/tests/units/test_index_ops.rb +++ b/tests/units/test_index_ops.rb @@ -33,7 +33,7 @@ def test_add assert(!g.status.changed.assoc('example.txt')) assert(!g.status.added.assoc('test-file')) assert(!g.status.untracked.assoc('test-file')) - assert_equal('hahahaha', g.status['example.txt'].blob.contents) + assert_equal("hahahaha\n", g.status['example.txt'].blob.contents) end end end @@ -55,7 +55,7 @@ def test_add_array g.commit('my message') assert(!g.status.added.assoc('test-file1')) assert(!g.status.untracked.assoc('test-file1')) - assert_equal('blahblahblah1', g.status['test-file1'].blob.contents) + assert_equal("blahblahblah1\n", g.status['test-file1'].blob.contents) end end end diff --git a/tests/units/test_lib.rb b/tests/units/test_lib.rb old mode 100644 new mode 100755 index 93ea34f3..c52b63df --- a/tests/units/test_lib.rb +++ b/tests/units/test_lib.rb @@ -74,14 +74,14 @@ def test_object_contents commit << "parent 546bec6f8872efa41d5d97a369f669165ecda0de\n" commit << "author scott Chacon 1194561188 -0800\n" commit << "committer scott Chacon 1194561188 -0800\n" - commit << "\ntest" + commit << "\ntest\n" assert_equal(commit, @lib.object_contents('1cc8667014381')) # commit tree = "040000 tree 6b790ddc5eab30f18cabdd0513e8f8dac0d2d3ed\tex_dir\n" - tree << "100644 blob 3aac4b445017a8fc07502670ec2dbf744213dd48\texample.txt" + tree << "100644 blob 3aac4b445017a8fc07502670ec2dbf744213dd48\texample.txt\n" assert_equal(tree, @lib.object_contents('1cc8667014381^{tree}')) #tree - blob = "1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n2" + blob = "1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n2\n" assert_equal(blob, @lib.object_contents('v2.5:example.txt')) #blob end diff --git a/tests/units/test_object.rb b/tests/units/test_object.rb old mode 100644 new mode 100755 index 870d37f2..13f41a89 --- a/tests/units/test_object.rb +++ b/tests/units/test_object.rb @@ -100,8 +100,8 @@ def test_blob def test_blob_contents o = @git.gblob('v2.6:example.txt') - assert_equal('replace with new text', o.contents) - assert_equal('replace with new text', o.contents) # this should be cached + assert_equal("replace with new text\n", o.contents) + assert_equal("replace with new text\n", o.contents) # this should be cached # make sure the block is called block_called = false