repo_manager 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (116) hide show
  1. data/.gemfiles +115 -0
  2. data/.gitattributes +1 -0
  3. data/.gitignore +7 -0
  4. data/.rspec +3 -0
  5. data/.yardopts +11 -0
  6. data/Gemfile +11 -0
  7. data/Gemfile.lock +99 -0
  8. data/Guardfile +63 -0
  9. data/HISTORY.markdown +12 -0
  10. data/LICENSE +20 -0
  11. data/README.markdown +192 -0
  12. data/Rakefile +94 -0
  13. data/TODO.markdown +15 -0
  14. data/VERSION +1 -0
  15. data/bin/repo +151 -0
  16. data/cucumber.yml +28 -0
  17. data/examples/pc_saved_game_backup/.gitignore +2 -0
  18. data/examples/pc_saved_game_backup/INSTALL.markdown +420 -0
  19. data/examples/pc_saved_game_backup/README.markdown +108 -0
  20. data/examples/pc_saved_game_backup/remote/.gitignore +2 -0
  21. data/examples/pc_saved_game_backup/repo_manager/Gemfile +12 -0
  22. data/examples/pc_saved_game_backup/repo_manager/Gemfile.lock +66 -0
  23. data/examples/pc_saved_game_backup/repo_manager/assets/.gitignore +2 -0
  24. data/examples/pc_saved_game_backup/repo_manager/features/support/aruba.rb +15 -0
  25. data/examples/pc_saved_game_backup/repo_manager/features/support/env.rb +11 -0
  26. data/examples/pc_saved_game_backup/repo_manager/features/support/steps.rb +3 -0
  27. data/examples/pc_saved_game_backup/repo_manager/features/tasks/update.feature +144 -0
  28. data/examples/pc_saved_game_backup/repo_manager/global/default/asset.conf +2 -0
  29. data/examples/pc_saved_game_backup/repo_manager/repo.conf +64 -0
  30. data/examples/pc_saved_game_backup/repo_manager/tasks/.gitignore +0 -0
  31. data/examples/pc_saved_game_backup/repo_manager/tasks/remote.rb +57 -0
  32. data/examples/pc_saved_game_backup/repo_manager/tasks/update.rb +65 -0
  33. data/examples/pc_saved_game_backup/saved_games/hearts/save1 +1 -0
  34. data/examples/pc_saved_game_backup/saved_games/hearts/save2 +1 -0
  35. data/examples/pc_saved_game_backup/saved_games/mines/my_profile.ini +1 -0
  36. data/examples/pc_saved_game_backup/saved_games/mines/saves/save1 +1 -0
  37. data/examples/pc_saved_game_backup/saved_games/mines/saves/save2 +1 -0
  38. data/features/actions/git.feature +296 -0
  39. data/features/actions/help.feature +53 -0
  40. data/features/actions/list.feature +624 -0
  41. data/features/actions/path.feature +195 -0
  42. data/features/actions/status.feature +261 -0
  43. data/features/actions/task.feature +127 -0
  44. data/features/assets/configuration.feature +204 -0
  45. data/features/assets/rendering.feature +42 -0
  46. data/features/assets/user_attributes.feature +98 -0
  47. data/features/bin.feature +42 -0
  48. data/features/logger.feature +218 -0
  49. data/features/settings.feature +240 -0
  50. data/features/support/aruba.rb +15 -0
  51. data/features/support/env.rb +11 -0
  52. data/features/support/steps.rb +3 -0
  53. data/features/tasks/add/asset.feature +178 -0
  54. data/features/tasks/generate/init.feature +56 -0
  55. data/lib/repo_manager.rb +36 -0
  56. data/lib/repo_manager/actions.rb +8 -0
  57. data/lib/repo_manager/actions/action_helper.rb +39 -0
  58. data/lib/repo_manager/actions/app_action.rb +30 -0
  59. data/lib/repo_manager/actions/base_action.rb +296 -0
  60. data/lib/repo_manager/actions/git_action.rb +113 -0
  61. data/lib/repo_manager/actions/help_action.rb +52 -0
  62. data/lib/repo_manager/actions/list_action.rb +123 -0
  63. data/lib/repo_manager/actions/path_action.rb +22 -0
  64. data/lib/repo_manager/actions/status_action.rb +192 -0
  65. data/lib/repo_manager/actions/task_action.rb +71 -0
  66. data/lib/repo_manager/app.rb +116 -0
  67. data/lib/repo_manager/assets.rb +3 -0
  68. data/lib/repo_manager/assets/app_asset.rb +15 -0
  69. data/lib/repo_manager/assets/asset_accessors.rb +67 -0
  70. data/lib/repo_manager/assets/asset_configuration.rb +137 -0
  71. data/lib/repo_manager/assets/asset_manager.rb +72 -0
  72. data/lib/repo_manager/assets/base_asset.rb +199 -0
  73. data/lib/repo_manager/assets/repo_asset.rb +30 -0
  74. data/lib/repo_manager/core.rb +2 -0
  75. data/lib/repo_manager/core/array.rb +21 -0
  76. data/lib/repo_manager/core/hash.rb +83 -0
  77. data/lib/repo_manager/errors.rb +10 -0
  78. data/lib/repo_manager/extensions/hash.rb +86 -0
  79. data/lib/repo_manager/git.rb +2 -0
  80. data/lib/repo_manager/git/lib.rb +69 -0
  81. data/lib/repo_manager/git/status.rb +196 -0
  82. data/lib/repo_manager/logger.rb +39 -0
  83. data/lib/repo_manager/settings.rb +98 -0
  84. data/lib/repo_manager/tasks.rb +3 -0
  85. data/lib/repo_manager/tasks/add/asset.rb +213 -0
  86. data/lib/repo_manager/tasks/generate/init.rb +42 -0
  87. data/lib/repo_manager/tasks/generate/templates/config/repo.conf.tt +61 -0
  88. data/lib/repo_manager/tasks/generate/templates/init/assets/.gitignore +0 -0
  89. data/lib/repo_manager/tasks/generate/templates/init/global/default/asset.conf +2 -0
  90. data/lib/repo_manager/tasks/generate/templates/init/tasks/.gitignore +0 -0
  91. data/lib/repo_manager/tasks/task_manager.rb +166 -0
  92. data/lib/repo_manager/tasks/thor_helper.rb +29 -0
  93. data/lib/repo_manager/test/asset_steps.rb +19 -0
  94. data/lib/repo_manager/test/base_steps.rb +152 -0
  95. data/lib/repo_manager/test/repo_api.rb +41 -0
  96. data/lib/repo_manager/test/repo_steps.rb +83 -0
  97. data/lib/repo_manager/test/test_api.rb +88 -0
  98. data/lib/repo_manager/views.rb +2 -0
  99. data/lib/repo_manager/views/app_view.rb +15 -0
  100. data/lib/repo_manager/views/base_view.rb +137 -0
  101. data/lib/repo_manager/views/templates/css/basic.css +26 -0
  102. data/lib/repo_manager/views/templates/default.erb +40 -0
  103. data/lib/repo_manager/views/templates/default.slim +37 -0
  104. data/lib/repo_manager/views/view_helper.rb +55 -0
  105. data/repo_manager.gemspec +75 -0
  106. data/spec/basic_app/actions/action_helper_spec.rb +54 -0
  107. data/spec/basic_app/assets/base_asset_spec.rb +210 -0
  108. data/spec/basic_app/core_spec.rb +78 -0
  109. data/spec/basic_app/settings_spec.rb +64 -0
  110. data/spec/basic_app/views/view_helper_spec.rb +28 -0
  111. data/spec/basic_gem/aruba_helper_spec.rb +33 -0
  112. data/spec/basic_gem/basic_gem_spec.rb +84 -0
  113. data/spec/basic_gem/gemspec_spec.rb +68 -0
  114. data/spec/repo_manager/git_spec.rb +31 -0
  115. data/spec/spec_helper.rb +25 -0
  116. metadata +472 -0
@@ -0,0 +1,57 @@
1
+ require 'fileutils'
2
+
3
+ module RepoManager
4
+
5
+ class Generate < Thor
6
+
7
+ # full path to the remote folder
8
+ REMOTE = File.expand_path('remote')
9
+
10
+ # Create, add, and commit the contents of the current working directory and
11
+ # then push it to a predefined remote folder
12
+ #
13
+ # @example From the repo working
14
+ #
15
+ # cd ~/my_repo_name
16
+ # repo generate:remote my_repo_name
17
+ #
18
+ # @example Specify the path to the working folder
19
+ #
20
+ # repo generate:remote my_repo_name --path=/path/to/my_repo_name
21
+
22
+ method_option :remote, :type => :string, :desc => "remote folder or git host, defaults to '#{REMOTE}'"
23
+ method_option :path, :type => :string, :desc => "path to working folder, defaults to CWD"
24
+
25
+ desc "remote REPO_NAME", "init a git repo in CWD and push to remote '#{REMOTE}'"
26
+ def remote(name)
27
+ path = options[:path] || FileUtils.pwd
28
+ remote = options[:remote] || "#{File.join(REMOTE, name + '.git')}"
29
+
30
+ Dir.chdir path do
31
+ run("git init")
32
+
33
+ # core config with windows in mind but works fine on POSIX
34
+ run("git config core.autocrlf false")
35
+ run("git config core.filemode false")
36
+ exit $?.exitstatus if ($?.exitstatus > 1)
37
+
38
+ # add everthing and commit
39
+ run("git add .")
40
+ run("git commit --message #{shell_quote('initial commit')}")
41
+ exit $?.exitstatus if ($?.exitstatus > 1)
42
+
43
+ # remove old origin first, if it exists
44
+ run("git remote add origin #{remote}")
45
+ run("git config branch.master.remote origin")
46
+ run("git config branch.master.merge refs/heads/master")
47
+ exit $?.exitstatus if ($?.exitstatus > 1)
48
+ end
49
+
50
+ run("git clone --bare #{shell_quote(path)} #{remote}")
51
+ exit $?.exitstatus if ($?.exitstatus > 1)
52
+
53
+ say "init done on '#{name}'", :green
54
+ end
55
+
56
+ end
57
+ end
@@ -0,0 +1,65 @@
1
+ # @see features/tasks/action.feature
2
+ module RepoManager
3
+ class Action < Thor
4
+ namespace :action
5
+ include Thor::Actions
6
+ include RepoManager::ThorHelper
7
+
8
+ class_option :force, :type => :boolean, :desc => "Force overwrite and answer 'yes' to any prompts"
9
+
10
+ method_option :repos, :type => :string, :desc => "Restrict update to comma delimited list of repo names", :banner => "repo1,repo2"
11
+ method_option :message, :type => :string, :desc => "Override 'automatic commit' message"
12
+ method_option 'no-push', :type => :boolean, :default => false, :desc => "Force overwrite of existing config file"
13
+
14
+ desc "update", "run repo add -A, repo commit, and repo push on all modified repos"
15
+ def update
16
+
17
+ initial_filter = options[:repos] ? "--repos=#{options[:repos]}" : ""
18
+ output = run("repo status --short --unmodified=HIDE --no-verbose --no-color #{initial_filter}", :capture => true)
19
+
20
+ case $?.exitstatus
21
+ when 0
22
+ say 'no changed repos', :green
23
+ else
24
+
25
+ unless output
26
+ say "failed to successfully run 'repo status'", :red
27
+ exit $?.exitstatus
28
+ end
29
+
30
+ repos = []
31
+ output = output.split("\n")
32
+ while line = output.shift
33
+ st,repo = line.split("\t")
34
+ repos << repo
35
+ end
36
+ filter = repos.join(',')
37
+
38
+ unless options[:force]
39
+ say "Repo(s) '#{filter}' have changed."
40
+ unless ask("Add, commit and push them? (y/n)") == 'y'
41
+ say "aborting"
42
+ exit 0
43
+ end
44
+ end
45
+
46
+ say "updating #{filter}"
47
+
48
+ run "repo add -A --no-verbose --repos #{filter}"
49
+ exit $?.exitstatus if ($?.exitstatus > 1)
50
+
51
+ commit_message = options[:message] || "automatic commit @ #{Time.now}"
52
+ run "repo commit --message=#{shell_quote(commit_message)} --no-verbose --repos #{filter}"
53
+ exit $?.exitstatus if ($?.exitstatus > 1)
54
+
55
+ unless options['no-push']
56
+ run "repo push --no-verbose --repos #{filter}"
57
+ exit $?.exitstatus if ($?.exitstatus > 1)
58
+ end
59
+
60
+ say "update finished", :green
61
+ end
62
+
63
+ end
64
+ end
65
+ end
@@ -0,0 +1 @@
1
+ # dummy save
@@ -0,0 +1 @@
1
+ # dummy save
@@ -0,0 +1 @@
1
+ # dummy profile data
@@ -0,0 +1,296 @@
1
+ @announce
2
+ Feature: Running an arbitrary git command
3
+
4
+ The application should run an arbitrary git command echoing output and
5
+ collecting status result codes. RepoManager provides alternatives to some of the
6
+ git commands. For example, RepoManager has its own status command that provides
7
+ summary information. To use the native command, you must place the arg 'git'
8
+ in front of the status command.
9
+
10
+ Example:
11
+
12
+ Run the native Git status command
13
+
14
+ repo git status -v
15
+
16
+ Run RepoManager version of the status command
17
+
18
+ repo status -v
19
+
20
+ Add and commit all
21
+
22
+ repo add .
23
+ repo commit -m "automatic add and commit"
24
+
25
+ Since there is no RepoManager version of the 'ls-files' command, these command
26
+ lines are equivalent:
27
+
28
+ repo git ls-files --others --ignored -v
29
+ repo ls-files --others --ignored -v
30
+
31
+ These command lines are also equivalent, note the alias for '--filter' is '--repos':
32
+
33
+ repo add . --filter=test
34
+ repo git add . --filter=test
35
+ repo git add . --repos=test
36
+
37
+ Git native commands do not allow any args that match exactly to a repo name
38
+ unless a filter is specified or args=0. Example, if 'screenshots' is a
39
+ repo name:
40
+
41
+ repo push # OK
42
+ repo push screenshots # error
43
+ repo git push screenshots # error
44
+ repo push -r screenshots # OK
45
+ repo git push -r screenshots # OK
46
+
47
+ Short formatted log information
48
+
49
+ repo git log -1 --pretty=format:"%h committed %cr"
50
+
51
+ Background: A valid config file
52
+ Given a file named "repo.conf" with:
53
+ """
54
+ ---
55
+ folders:
56
+ assets : repo_assets
57
+ commands:
58
+ - diff
59
+ - grep
60
+ - log
61
+ - ls-files
62
+ - show
63
+ - status
64
+ - add
65
+ - commit
66
+ """
67
+ And a repo in folder "test_path_1" with the following:
68
+ | filename | status | content |
69
+ | .gitignore | C | |
70
+ And a repo in folder "test_path_2" with the following:
71
+ | filename | status | content |
72
+ | .gitignore | C | |
73
+ And the folder "repo_assets" with the following asset configurations:
74
+ | name | path |
75
+ | test1 | test_path_1 |
76
+ | test2 | test_path_2 |
77
+
78
+ Scenario: Missing all run arguments
79
+ When I run `repo git`
80
+ Then the exit status should be 1
81
+ And the output should contain:
82
+ """
83
+ no git command given
84
+ """
85
+
86
+ Scenario: Run 'git ls-files' on each repo
87
+ When I run `repo git ls-files`
88
+ Then the exit status should be 0
89
+ And the output should contain:
90
+ """
91
+ test1
92
+ .gitignore
93
+ test2
94
+ .gitignore
95
+ """
96
+
97
+ Scenario: Run 'ls-files' on each repo, 'git' is an optional first argument
98
+ When I run `repo ls-files`
99
+ Then the exit status should be 0
100
+ And the output should contain:
101
+ """
102
+ test1
103
+ .gitignore
104
+ test2
105
+ .gitignore
106
+ """
107
+
108
+ Scenario: Run 'ls-files' on each repo using a filter
109
+ When I run `repo --verbose ls-files --repos=test1`
110
+ Then the exit status should be 0
111
+ And the output should contain:
112
+ """
113
+ test1
114
+ .gitignore
115
+ """
116
+ And the output should not contain:
117
+ """
118
+ test2
119
+ .gitignore
120
+ """
121
+
122
+ Scenario: Run 'ls-files' using a repo name as an argument with no filter
123
+ supplied (failure)
124
+ When I run `repo ls-files test1`
125
+ Then the exit status should be 1
126
+ And the output should contain:
127
+ """
128
+ 'test1' cannot be used as a filter
129
+ """
130
+
131
+ Scenario: Run 'git ls-files' using a repo name as an argument with no filter
132
+ supplied (failure)
133
+ When I run `repo git ls-files test1`
134
+ Then the exit status should be 1
135
+ And the output should contain:
136
+ """
137
+ 'test1' cannot be used as a filter
138
+ """
139
+
140
+ Scenario: Run 'git ls-files' using argument that is not a repo name with no
141
+ filter supplied (success)
142
+ When I run `repo git ls-files .gitignore`
143
+ Then the exit status should be 0
144
+
145
+ Scenario: Run 'git status' on each repo with no changes
146
+ When I run `repo git status`
147
+ Then the exit status should be 0
148
+ And the output should contain:
149
+ """
150
+ test1
151
+ # On branch master
152
+ nothing to commit (working directory clean)
153
+ test2
154
+ # On branch master
155
+ nothing to commit (working directory clean)
156
+ """
157
+
158
+ Scenario: Run 'git status --porcelain' on each repo with no changes shows nothing on stdout
159
+ When I run `repo git status --porcelain`
160
+ Then the exit status should be 0
161
+ And the output should not contain:
162
+ """
163
+ test1: test_path_1
164
+ """
165
+ And the output should not contain:
166
+ """
167
+ test2: test_path_2
168
+ """
169
+
170
+ Scenario: Run native 'git status' on each repo with uncommited change
171
+ Given a repo in folder "test_path_1" with the following:
172
+ | filename | status | content |
173
+ | .gitignore | M | tmp/* |
174
+ When I run `repo --verbose git status --porcelain`
175
+ Then the exit status should be 0
176
+ And the output should contain:
177
+ """
178
+ test1
179
+ M .gitignore
180
+ """
181
+
182
+ Scenario: Run native git status command on an invalid repo
183
+ Given the folder "repo_assets" with the following asset configurations:
184
+ | name | path |
185
+ | test1 | test_path_1 |
186
+ | test2 | test_path_2 |
187
+ | bad_repo | not_a_repo |
188
+ And a directory named "not_a_repo"
189
+ When I run `repo git status --porcelain --repos=test1,test2,bad_repo`
190
+ Then the exit status should be 128
191
+ And the output should contain:
192
+ """
193
+ bad_repo
194
+ fatal: Not a git repository
195
+ """
196
+
197
+ Scenario: Run RepoManager status command on an invalid repo
198
+ Given the folder "repo_assets" with the following asset configurations:
199
+ | name | path |
200
+ | test1 | test_path_1 |
201
+ | test2 | test_path_2 |
202
+ | bad_repo | not_a_repo |
203
+ And a directory named "not_a_repo"
204
+ When I run `repo status --repos=test1,bad_repo --unmodified=SHOW --no-verbose`
205
+ Then the exit status should be 2
206
+ And the normalized output should contain:
207
+ """
208
+ I bad_repo: ./not_a_repo [not a valid repo]
209
+ test1
210
+ """
211
+
212
+ Scenario: Native and repo_manager status command missing repo folder has different
213
+ exit status values
214
+ Given the folder "repo_assets" with the following asset configurations:
215
+ | name | path |
216
+ | bad_repo | bad_repo_path |
217
+ When I run `repo git status --filter=bad_repo --unmodified DOTS --no-verbose`
218
+ Then the exit status should be 0
219
+ And the output should contain exactly:
220
+ """
221
+ bad_repo: ./bad_repo_path [no such path]
222
+
223
+ """
224
+ When I run `repo status --filter=bad_repo --unmodified DOTS --no-verbose`
225
+ Then the exit status should be 1
226
+
227
+ Scenario: Folders with spaces in path
228
+ Given a file named "repo1.conf" with:
229
+ """
230
+ ---
231
+ folders:
232
+ assets : assets1
233
+ """
234
+ And a repo in folder "test 1/test path 1" with the following:
235
+ | filename | status | content |
236
+ | testfile 1.txt | CM | something |
237
+ And the folder "assets1" with the following asset configurations:
238
+ | name | path |
239
+ | test1 | test 1/test path 1 |
240
+ | test2 | test_path_2 |
241
+ When I run `repo git ls-files --config=repo1.conf`
242
+ Then the exit status should be 0
243
+ And the output should contain:
244
+ """
245
+ test1
246
+ testfile 1.txt
247
+ test2
248
+ .gitignore
249
+ """
250
+
251
+ Scenario: Git 'add' on a repo with uncommited change
252
+ Given a repo in folder "test_path_1" with the following:
253
+ | filename | status | content |
254
+ | .gitignore | M | tmp/* |
255
+ When I run `repo add . --repo test1`
256
+ Then the exit status should be 0
257
+ And the output should not contain:
258
+ """
259
+ test1: test_path_1
260
+ """
261
+
262
+ Scenario: Git 'commit' on a repo with an added file
263
+ Given a repo in folder "test_path_1" with the following:
264
+ | filename | status | content |
265
+ | new_stuff.txt | A | tmp/* |
266
+ When I run `repo commit -m 'automatic commit via repo_manager' --repos test1`
267
+ Then the exit status should be 0
268
+ And the output should contain:
269
+ """
270
+ 1 files changed, 1 insertions(+), 0 deletions(-)
271
+ """
272
+
273
+ Scenario: Running a git command that is not whitelisted
274
+ Given a file named "repo.conf" with:
275
+ """
276
+ ---
277
+ folders:
278
+ assets : repo_assets
279
+ commands:
280
+ - diff
281
+ - grep
282
+ - log
283
+ """
284
+ And a repo in folder "test_path_1" with the following:
285
+ | filename | status | content |
286
+ | new_stuff.txt | A | tmp/* |
287
+ When I run `repo commit -m 'automatic commit via repo_manager' --repos test1`
288
+ Then the exit status should be 1
289
+ And the output should not contain:
290
+ """
291
+ 1 files changed, 1 insertions(+), 0 deletions(-)
292
+ """
293
+ And the output should contain:
294
+ """
295
+ repo failed: git command 'commit' is not enabled
296
+ """
@@ -0,0 +1,53 @@
1
+ Feature: Show help on actions
2
+
3
+ Show action specific help to STDOUT for a given action
4
+
5
+ Example usage:
6
+
7
+ repo help list
8
+ repo help task
9
+ repo help help
10
+
11
+ Notes
12
+
13
+ * abbreviated help general app help is available via the --help option
14
+
15
+ Background: Empty configuration file so that we don't read global config locations
16
+ Given an empty file named "repo.conf"
17
+
18
+ Scenario Outline: Valid action, help available
19
+ When I run `repo help <action>`
20
+ Then the exit status should be 0
21
+ And its output should match:
22
+ """
23
+ Usage: repo.* <action>
24
+ """
25
+ And its output should match:
26
+ """
27
+ Options:
28
+ """
29
+
30
+ Examples:
31
+ | action |
32
+ | help |
33
+ | list |
34
+ | task |
35
+ | git |
36
+ | path |
37
+ | status |
38
+
39
+ Scenario: Missing action
40
+ When I run `repo help`
41
+ Then the exit status should be 0
42
+ And the output should contain:
43
+ """
44
+ no action specified
45
+ """
46
+
47
+ Scenario: Invalid action
48
+ When I run `repo help badaction`
49
+ Then the exit status should be 0
50
+ And the output should contain:
51
+ """
52
+ invalid help action
53
+ """