This repository was archived by the owner on Dec 13, 2023. It is now read-only.
File tree 3 files changed +70
-0
lines changed
3 files changed +70
-0
lines changed Original file line number Diff line number Diff line change
1
+ module Scm ::Adapters
2
+ class BzrAdapter < AbstractAdapter
3
+ def cat_file ( commit , diff )
4
+ cat ( commit . token , diff . path )
5
+ end
6
+
7
+ def cat_file_parent ( commit , diff )
8
+ p = parents ( commit )
9
+ cat ( p . first . token , diff . path ) if p . first
10
+ end
11
+
12
+ def cat ( revision , path )
13
+ out , err = run_with_err ( "cd '#{ url } ' && bzr cat -r #{ revision } #{ escape ( path ) } " )
14
+ return nil if err =~ / is not present in revision /
15
+ raise RuntimeError . new ( err ) unless err . to_s == ''
16
+ out
17
+ end
18
+
19
+ # Escape bash-significant characters in the filename
20
+ # Example:
21
+ # "Foo Bar & Baz" => "Foo\ Bar\ \&\ Baz"
22
+ def escape ( path )
23
+ path . gsub ( /[ '"&]/ ) { |c | '\\' + c }
24
+ end
25
+ end
26
+ end
Original file line number Diff line number Diff line change @@ -9,3 +9,4 @@ def english_name
9
9
require 'lib/scm/adapters/bzr/validation'
10
10
require 'lib/scm/adapters/bzr/commits'
11
11
require 'lib/scm/adapters/bzr/head'
12
+ require 'lib/scm/adapters/bzr/cat_file'
Original file line number Diff line number Diff line change
1
+ require File . dirname ( __FILE__ ) + '/../test_helper'
2
+
3
+ module Scm ::Adapters
4
+ class BzrCatFileTest < Scm ::Test
5
+
6
+ def test_cat_file
7
+ with_bzr_repository ( 'bzr' ) do |bzr |
8
+ expected = <<-EXPECTED
9
+ first file
10
+ second line
11
+ EXPECTED
12
+ assert_equal expected ,
13
+ bzr . cat_file ( Scm ::Commit ::new ( :token => 6 ) ,
14
+ Scm ::Diff . new ( :path => "file1.txt" ) )
15
+
16
+ # file2.txt has been removed in commit #5
17
+ assert_equal nil , bzr . cat_file ( bzr . head ,
18
+ Scm ::Diff . new ( :path => "file2.txt" ) )
19
+ end
20
+ end
21
+
22
+ def test_cat_file_parent
23
+ with_bzr_repository ( 'bzr' ) do |bzr |
24
+ expected = <<-EXPECTED
25
+ first file
26
+ second line
27
+ EXPECTED
28
+ assert_equal expected ,
29
+ bzr . cat_file_parent ( Scm ::Commit ::new ( :token => 6 ) ,
30
+ Scm ::Diff . new ( :path => "file1.txt" ) )
31
+
32
+ # file2.txt has been removed in commit #5
33
+ expected = <<-EXPECTED
34
+ another file
35
+ EXPECTED
36
+ assert_equal expected ,
37
+ bzr . cat_file_parent ( Scm ::Commit . new ( :token => 5 ) ,
38
+ Scm ::Diff . new ( :path => "file2.txt" ) )
39
+ end
40
+ end
41
+
42
+ end
43
+ end
You can’t perform that action at this time.
0 commit comments