trout 0.1 → 0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +6 -0
- data/Gemfile.lock +28 -0
- data/README.textile +44 -0
- data/features/help.feature +60 -0
- data/features/sync_gemfile.feature +30 -3
- data/lib/trout/cli.rb +83 -9
- data/lib/trout/managed_file.rb +15 -8
- metadata +16 -12
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
aruba (0.2.1)
|
5
|
+
builder (2.1.2)
|
6
|
+
cucumber (0.8.5)
|
7
|
+
builder (~> 2.1.2)
|
8
|
+
diff-lcs (~> 1.1.2)
|
9
|
+
gherkin (~> 2.1.4)
|
10
|
+
json_pure (~> 1.4.3)
|
11
|
+
term-ansicolor (~> 1.0.4)
|
12
|
+
diff-lcs (1.1.2)
|
13
|
+
gherkin (2.1.5)
|
14
|
+
trollop (~> 1.16.2)
|
15
|
+
json_pure (1.4.6)
|
16
|
+
rake (0.8.7)
|
17
|
+
rspec (1.3.0)
|
18
|
+
term-ansicolor (1.0.5)
|
19
|
+
trollop (1.16.2)
|
20
|
+
|
21
|
+
PLATFORMS
|
22
|
+
ruby
|
23
|
+
|
24
|
+
DEPENDENCIES
|
25
|
+
aruba
|
26
|
+
cucumber
|
27
|
+
rake
|
28
|
+
rspec
|
data/README.textile
CHANGED
@@ -46,3 +46,47 @@ h2. Author
|
|
46
46
|
|
47
47
|
Copyright 2010 Joe Ferris
|
48
48
|
|
49
|
+
<pre>
|
50
|
+
;t
|
51
|
+
jfLLf
|
52
|
+
tLfGfGL
|
53
|
+
tLjjEffGDt
|
54
|
+
fjfjfffLfGL;
|
55
|
+
GffffLLLLLGLGGGGLDL;
|
56
|
+
.GfffLLGGGLDLfffffGLGEGGLGf
|
57
|
+
:GGGDGLLLLGfLfffGLELEfLfLGLLG
|
58
|
+
ffDLLLDGLffDDjjjjjLGffEfLLfELGGLLGL,
|
59
|
+
tLfffGfjjLfffjjjjjjjjjjjjjLjDffLELffLLLfLDG
|
60
|
+
jj: ffLjjGtiittfitGifttfftttDtjtjGtDjjGjjjLfLjffffLG
|
61
|
+
jDGj GDjtjGi;;;t;tt,,it;;Liij;iiGtttttiftLtjjtjjjffffLfffL.
|
62
|
+
,fLfftjti,;:..:.:.:,G;,G,i;,;t;tijtititLtitjftjGttjjLDffLLLD
|
63
|
+
tjfjL;,:..i.,. .: t::i,,j:,;;;;ii;;tii;fiiDitttGtitttfjjjfDfLG
|
64
|
+
Lfffij.... .i .;:..;;j,;i,,i;;;;t;iGiiiDititiLijttftijttLjfGLGt
|
65
|
+
;Gf; fLfjj,,:tt...::,:,::,G,,,fti;iiiti;iiititftjttttjtitiftjiftititfLGLDD
|
66
|
+
fEKDGELt LLDt;;;;,,,,t,i;ii;;;;i;,iittttttjtjjjtttttttjjttjjjjLjtttitiGtGtffiLGDD,
|
67
|
+
DDGGGffL,ijLLii;jji;titifijjtiti;ifi;i;ij;ttt;tttijtttDtttjjttjjjfjjfjDjttitjGjGGGDEDD.
|
68
|
+
KGDLffLLfLjiijiiijtttjjjjjttiti;ttt;;ttit,i;i;titittjttfttGitDttjjjjjttjjjtffjffjGLDDDDE:
|
69
|
+
EGDLLEGLftLtLtiLjtLjjjjttittiiiiititittiiiittijititttjtitftttittjtttjffjfffjjfLLjLLLGGGEDD
|
70
|
+
iDGLDDDGjjtEjjjtffjfjjjttjjittitttit;tiii;tttttitiijtiittjtttttttGttGjtjffjffLfifLffGGGDGEEKj
|
71
|
+
DGGGGGLfLfjfjjfjjjtttjjjtjttjttjjttitiittiiittitttiiitttttjtjjtititjttjfLLffGtffLffLLLGGDGGGE
|
72
|
+
GGEGLLffjjjfDjfjfjjjjfffffjjtttjttitititttttjttttitttttjjjtitjtfttttjfftGLLGffLLLGGLLtjfffGLLL.
|
73
|
+
LDDGGLfLfffjjtjfLD. ;LLffLLfjjtjtttitittitttttittti;tttiitttttttttjjfffLLLLfjLGLLGLDLffjffLjtL:
|
74
|
+
KDLEGGjfjfjjffG ttjtLttjfLffjjtttttjttttjttttttjtttttiittttttttjjjLLLGLtLfLLLLLGEGGftLjjt;t
|
75
|
+
jELDEfffjjffj tttjjtjfitjfffjjjjjjjjjjjtjtttjtttttttttttjjtjjjfftfGLL;GLGLLLLGLf;tLj,G.
|
76
|
+
GDDDLfffjfj ,ittfjfit GLfLLLLLLLLLffjttttttttttttttttttjjfjfjjfLGiGLGLLffj;,LjiiG
|
77
|
+
KGKGDLffff ;iitjff .fGLGGGijjjjjjttttttttttttttjjfLff,LGjLGDGLLi,;fftDG
|
78
|
+
DELLfjLLL ,;ijff DiftjjLffjjjjtttttttjjjjfffjD,itGfGLLfj:tLjtfG
|
79
|
+
;EfEELfLj ,;itj Ljitt EDfLGLffjjjjjjjjjjffLjjtD:fLGijftifjtt;j;t.t.:;t
|
80
|
+
LfKfGDG :;ij .,tttfi :fLLLLLfffffffLfftGGjfffEGGftfi;i;:iLjjit
|
81
|
+
tfDffDf :i ,;;itft ,LLLLLGLfLLGfGGLi.,tKKDffLLGDDGLLL
|
82
|
+
GLEfDf ;;itjj jGGGGDfLLGL.:tjGLLLG,
|
83
|
+
DDGDGL ;;iijj tjLGGDDKKKKDLGt,: .
|
84
|
+
jfGEj ,;it: tjffLGDLKKKWKK
|
85
|
+
GEfL .:;; tjjffLGjEKEEKKK
|
86
|
+
GLf, . ;jjjjfLfEEEEEKW
|
87
|
+
.Lf .tjjjjfiDDEEEEK
|
88
|
+
L ttjjjf LEEEE:
|
89
|
+
tjjjf ;ED
|
90
|
+
ittj
|
91
|
+
:
|
92
|
+
</pre>
|
@@ -0,0 +1,60 @@
|
|
1
|
+
Feature: get help on using trout
|
2
|
+
|
3
|
+
Scenario Outline: Specify an unknown command
|
4
|
+
When I run "trout <arguments>"
|
5
|
+
Then the output should contain:
|
6
|
+
"""
|
7
|
+
I don't know how to "<command>."
|
8
|
+
Run "trout help" for usage information.
|
9
|
+
"""
|
10
|
+
Examples:
|
11
|
+
| arguments | command |
|
12
|
+
| swim | swim |
|
13
|
+
| help swim | swim |
|
14
|
+
|
15
|
+
Scenario Outline: Run an invalid command
|
16
|
+
When I run "<invalid command>"
|
17
|
+
Then the output should contain:
|
18
|
+
"""
|
19
|
+
I don't understand the options you provided.
|
20
|
+
Run "<help command>" for usage information.
|
21
|
+
"""
|
22
|
+
Examples:
|
23
|
+
| invalid command | help command |
|
24
|
+
| trout checkout | trout help checkout |
|
25
|
+
| trout checkout file | trout help checkout |
|
26
|
+
| trout checkout file url extra | trout help checkout |
|
27
|
+
| trout update | trout help update |
|
28
|
+
| trout update file extra | trout help update |
|
29
|
+
|
30
|
+
Scenario Outline: Ask for help
|
31
|
+
When I run "<help command>"
|
32
|
+
Then the output should contain:
|
33
|
+
"""
|
34
|
+
trout helps you sync individual files from other git repositories.
|
35
|
+
"""
|
36
|
+
And the output should contain:
|
37
|
+
"""
|
38
|
+
Commands:
|
39
|
+
"""
|
40
|
+
And the output should not contain:
|
41
|
+
"""
|
42
|
+
I don't know how
|
43
|
+
"""
|
44
|
+
Examples:
|
45
|
+
| help command |
|
46
|
+
| trout |
|
47
|
+
| trout help |
|
48
|
+
| trout -h |
|
49
|
+
| trout --help |
|
50
|
+
|
51
|
+
Scenario Outline: Ask for usage for a particular command
|
52
|
+
When I run "trout help <command>"
|
53
|
+
Then the output should contain:
|
54
|
+
"""
|
55
|
+
Usage: trout <command> <usage>
|
56
|
+
"""
|
57
|
+
Examples:
|
58
|
+
| command | usage |
|
59
|
+
| checkout | filename git_url |
|
60
|
+
| update | filename |
|
@@ -1,6 +1,5 @@
|
|
1
1
|
Feature: sync a Gemfile between two repositories
|
2
2
|
|
3
|
-
@puts @announce
|
4
3
|
Scenario: sync a Gemfile
|
5
4
|
Given a directory named "upstream_repo"
|
6
5
|
And a directory named "child_repo"
|
@@ -16,6 +15,10 @@ Feature: sync a Gemfile between two repositories
|
|
16
15
|
And I run "git commit -m 'Added gemfile'"
|
17
16
|
And I cd to "../child_repo"
|
18
17
|
And I run "trout checkout Gemfile ../upstream_repo"
|
18
|
+
Then the output should contain:
|
19
|
+
"""
|
20
|
+
Checked out Gemfile from ../upstream_repo.
|
21
|
+
"""
|
19
22
|
And I run "cat Gemfile"
|
20
23
|
Then the output should contain:
|
21
24
|
"""
|
@@ -39,7 +42,11 @@ Feature: sync a Gemfile between two repositories
|
|
39
42
|
gem "redcloth"
|
40
43
|
"""
|
41
44
|
When I run "trout update Gemfile"
|
42
|
-
|
45
|
+
Then the output should contain:
|
46
|
+
"""
|
47
|
+
Merged changes to Gemfile.
|
48
|
+
"""
|
49
|
+
When I run "cat Gemfile"
|
43
50
|
Then the output should contain:
|
44
51
|
"""
|
45
52
|
source "http://rubygems.org"
|
@@ -49,6 +56,26 @@ Feature: sync a Gemfile between two repositories
|
|
49
56
|
gem "redcloth"
|
50
57
|
=======
|
51
58
|
gem "postgresql"
|
52
|
-
>>>>>>>
|
59
|
+
>>>>>>> /tmp/upstream
|
60
|
+
"""
|
61
|
+
When I write to "Gemfile" with:
|
62
|
+
"""
|
63
|
+
source "http://rubygems.org"
|
64
|
+
gem "rails"
|
65
|
+
gem "mysql"
|
66
|
+
gem "redcloth"
|
67
|
+
"""
|
68
|
+
When I run "trout update Gemfile"
|
69
|
+
Then the output should contain:
|
70
|
+
"""
|
71
|
+
Gemfile already up to date.
|
72
|
+
"""
|
73
|
+
And I run "cat Gemfile"
|
74
|
+
Then the output should contain:
|
75
|
+
"""
|
76
|
+
source "http://rubygems.org"
|
77
|
+
gem "rails"
|
78
|
+
gem "mysql"
|
79
|
+
gem "redcloth"
|
53
80
|
"""
|
54
81
|
|
data/lib/trout/cli.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'optparse'
|
1
2
|
require 'trout/managed_file'
|
2
3
|
|
3
4
|
module Trout
|
@@ -6,31 +7,104 @@ module Trout
|
|
6
7
|
new(arguments).run
|
7
8
|
end
|
8
9
|
|
9
|
-
|
10
|
+
attr_accessor :command, :option_parser, :arguments, :file
|
10
11
|
|
11
12
|
def initialize(arguments)
|
12
|
-
self.arguments
|
13
|
-
self.
|
13
|
+
self.arguments = arguments
|
14
|
+
self.option_parser = parse_options
|
14
15
|
end
|
15
16
|
|
16
17
|
def run
|
17
18
|
case command
|
18
19
|
when 'checkout'
|
19
|
-
|
20
|
+
build_file
|
21
|
+
git_url = next_argument
|
22
|
+
end_arguments
|
20
23
|
file.copy_from(git_url)
|
21
24
|
when 'update'
|
25
|
+
build_file
|
26
|
+
end_arguments
|
22
27
|
file.update
|
28
|
+
when 'help', nil
|
29
|
+
puts option_parser
|
30
|
+
if arguments_left?
|
31
|
+
puts
|
32
|
+
usage_for(next_argument)
|
33
|
+
end
|
34
|
+
else
|
35
|
+
unknown_command(command)
|
23
36
|
end
|
24
37
|
end
|
25
38
|
|
26
39
|
private
|
27
40
|
|
28
|
-
def
|
29
|
-
|
30
|
-
|
31
|
-
|
41
|
+
def parse_options
|
42
|
+
option_parser = OptionParser.new do |parser|
|
43
|
+
parser.banner =
|
44
|
+
"trout helps you sync individual files from other git repositories.\n\n" +
|
45
|
+
"Usage: trout [options] command arguments"
|
46
|
+
|
47
|
+
parser.separator ""
|
48
|
+
parser.separator "Options:"
|
49
|
+
parser.separator ""
|
50
|
+
|
51
|
+
parser.on("-h", "--help", "View this help document")
|
52
|
+
|
53
|
+
parser.separator ""
|
54
|
+
parser.separator "Commands:"
|
55
|
+
parser.separator ""
|
56
|
+
parser.separator " checkout - start tracking a file from another repository"
|
57
|
+
parser.separator " help - get usage details for a specific command"
|
58
|
+
parser.separator " update - synchronize changes to a tracked file"
|
59
|
+
end
|
60
|
+
|
61
|
+
option_parser.parse!(arguments)
|
62
|
+
|
63
|
+
if arguments_left?
|
64
|
+
self.command = next_argument
|
65
|
+
else
|
66
|
+
self.command = 'help'
|
67
|
+
end
|
68
|
+
|
69
|
+
option_parser
|
70
|
+
end
|
71
|
+
|
72
|
+
def next_argument
|
73
|
+
arguments.shift or invalid_arguments
|
32
74
|
end
|
33
75
|
|
34
|
-
|
76
|
+
def arguments_left?
|
77
|
+
!arguments.empty?
|
78
|
+
end
|
79
|
+
|
80
|
+
def invalid_arguments
|
81
|
+
puts "I don't understand the options you provided."
|
82
|
+
puts %{Run "trout help #{command}" for usage information.}
|
83
|
+
exit
|
84
|
+
end
|
85
|
+
|
86
|
+
def end_arguments
|
87
|
+
invalid_arguments if arguments_left?
|
88
|
+
end
|
89
|
+
|
90
|
+
def build_file
|
91
|
+
self.file = ManagedFile.new(next_argument)
|
92
|
+
end
|
93
|
+
|
94
|
+
def usage_for(command)
|
95
|
+
case command
|
96
|
+
when 'checkout'
|
97
|
+
puts "Usage: trout checkout filename git_url"
|
98
|
+
when 'update'
|
99
|
+
puts "Usage: trout update filename"
|
100
|
+
else
|
101
|
+
unknown_command(command)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def unknown_command(command)
|
106
|
+
puts %{I don't know how to "#{command}."}
|
107
|
+
puts %{Run "trout help" for usage information.}
|
108
|
+
end
|
35
109
|
end
|
36
110
|
end
|
data/lib/trout/managed_file.rb
CHANGED
@@ -13,13 +13,20 @@ module Trout
|
|
13
13
|
checkout(git_url)
|
14
14
|
copy_to_destination
|
15
15
|
write_url_and_version
|
16
|
+
puts "Checked out #{filename} from #{git_url}."
|
16
17
|
ensure
|
17
18
|
cleanup
|
18
19
|
end
|
19
20
|
|
20
21
|
def update
|
21
22
|
checkout(previous_git_url)
|
22
|
-
|
23
|
+
if up_to_date?
|
24
|
+
puts "#{filename} already up to date."
|
25
|
+
else
|
26
|
+
merge_to_destination
|
27
|
+
write_url_and_version
|
28
|
+
puts "Merged changes to #{filename}."
|
29
|
+
end
|
23
30
|
ensure
|
24
31
|
cleanup
|
25
32
|
end
|
@@ -65,10 +72,6 @@ module Trout
|
|
65
72
|
FileUtils.mkdir(working_root)
|
66
73
|
end
|
67
74
|
|
68
|
-
def working_root
|
69
|
-
'.trout'
|
70
|
-
end
|
71
|
-
|
72
75
|
def write_url_and_version
|
73
76
|
version_list.update(filename,
|
74
77
|
'git_url' => checked_out_url,
|
@@ -76,7 +79,7 @@ module Trout
|
|
76
79
|
end
|
77
80
|
|
78
81
|
def checked_out_version
|
79
|
-
git_command("rev-parse
|
82
|
+
git_command("rev-parse master")
|
80
83
|
end
|
81
84
|
|
82
85
|
def checkout_last_version
|
@@ -95,12 +98,16 @@ module Trout
|
|
95
98
|
version_list.version_for(filename)
|
96
99
|
end
|
97
100
|
|
101
|
+
def up_to_date?
|
102
|
+
previous_git_version == checked_out_version
|
103
|
+
end
|
104
|
+
|
98
105
|
def version_list
|
99
|
-
@version_list ||= VersionList.new(
|
106
|
+
@version_list ||= VersionList.new('.trout')
|
100
107
|
end
|
101
108
|
|
102
109
|
def working(*paths)
|
103
|
-
File.join(
|
110
|
+
File.join('/tmp', *paths)
|
104
111
|
end
|
105
112
|
|
106
113
|
def enforce_newline(path)
|
metadata
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: trout
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 15
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: "0.
|
8
|
+
- 2
|
9
|
+
version: "0.2"
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Joe Ferris
|
@@ -14,13 +14,11 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-09-
|
17
|
+
date: 2010-09-21 00:00:00 -04:00
|
18
18
|
default_executable: trout
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
|
-
|
22
|
-
prerelease: false
|
23
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
21
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
24
22
|
none: false
|
25
23
|
requirements:
|
26
24
|
- - ">="
|
@@ -29,12 +27,12 @@ dependencies:
|
|
29
27
|
segments:
|
30
28
|
- 0
|
31
29
|
version: "0"
|
30
|
+
requirement: *id001
|
32
31
|
type: :development
|
33
|
-
|
34
|
-
- !ruby/object:Gem::Dependency
|
35
|
-
name: aruba
|
32
|
+
name: cucumber
|
36
33
|
prerelease: false
|
37
|
-
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
38
36
|
none: false
|
39
37
|
requirements:
|
40
38
|
- - ">="
|
@@ -43,8 +41,10 @@ dependencies:
|
|
43
41
|
segments:
|
44
42
|
- 0
|
45
43
|
version: "0"
|
44
|
+
requirement: *id002
|
46
45
|
type: :development
|
47
|
-
|
46
|
+
name: aruba
|
47
|
+
prerelease: false
|
48
48
|
description: |-
|
49
49
|
Trout allows you to maintain a base version of special
|
50
50
|
files (like Gemfile) in one repository, and then syncronize just that
|
@@ -60,6 +60,8 @@ extensions: []
|
|
60
60
|
extra_rdoc_files: []
|
61
61
|
|
62
62
|
files:
|
63
|
+
- Gemfile
|
64
|
+
- Gemfile.lock
|
63
65
|
- LICENSE
|
64
66
|
- Rakefile
|
65
67
|
- README.textile
|
@@ -67,6 +69,7 @@ files:
|
|
67
69
|
- lib/trout/managed_file.rb
|
68
70
|
- lib/trout/version_list.rb
|
69
71
|
- lib/trout.rb
|
72
|
+
- features/help.feature
|
70
73
|
- features/support/env.rb
|
71
74
|
- features/sync_gemfile.feature
|
72
75
|
- bin/trout
|
@@ -105,5 +108,6 @@ signing_key:
|
|
105
108
|
specification_version: 3
|
106
109
|
summary: So your common files can swim upstream.
|
107
110
|
test_files:
|
111
|
+
- features/help.feature
|
108
112
|
- features/support/env.rb
|
109
113
|
- features/sync_gemfile.feature
|