public
Description: Piston is a utility that eases vendor branch management. This repository is a complete reimplementation of Piston to provide different backends, depending on the repositories and working copies you pistonize from.
Homepage: http://piston.rubyforge.org/
Clone URL: git://github.com/francois/piston.git
Search Repo:
Piston will now guess the repository's basename for the import directory.

Moved repository/revision and working_copy instantiation code from cli.rb 
to import.rb.
francois (author)
Mon Mar 24 19:48:52 -0700 2008
commit  9d6ac05f264f5275f4609b4690a37b4f8481f7b8
tree    44d13a49818c595c76a6f2d221b31fc4dded07f6
parent  f159782db5d976475ab12cc5db883ac84f439fb9
...
50
51
52
53
 
54
55
56
...
72
73
74
75
76
77
78
79
 
80
81
82
...
50
51
52
 
53
54
55
56
...
72
73
74
 
 
 
 
 
75
76
77
78
0
@@ -50,7 +50,7 @@
0
 
0
     argument "directory" do
0
       optional
0
- default :repository
0
+ default nil
0
       description "Where to put the Pistonized repository"
0
     end
0
 
0
@@ -72,11 +72,7 @@
0
                                          :quiet => params["quiet"].value,
0
                                          :force => params["force"].value,
0
                                          :dry_run => params["dry-run"].value)
0
- repository = Piston::Repository.guess(params[:repository].value)
0
- revision = repository.at(self.target_revision)
0
- working_copy = Piston::WorkingCopy.guess(params[:directory].value)
0
-
0
- cmd.run(revision, working_copy)
0
+ cmd.run(params[:repository].value, self.target_revision, params[:directory].value)
0
     end
0
   end
0
 
...
9
10
11
12
 
 
 
 
 
 
 
 
13
14
15
...
9
10
11
 
12
13
14
15
16
17
18
19
20
21
22
0
@@ -9,7 +9,14 @@
0
         working_copy.path.parent + ".#{working_copy.path.basename}.tmp"
0
       end
0
 
0
- def run(revision, working_copy)
0
+ def run(repository_url, target_revision, wcdir)
0
+ repository = Piston::Repository.guess(repository_url)
0
+ revision = repository.at(target_revision)
0
+
0
+ wcdir = wcdir.nil? ? repository.basename : wcdir
0
+ debug {"repository_url: #{repository_url.inspect}, target_revision: #{target_revision.inspect}, wcdir: #{wcdir.inspect}"}
0
+ working_copy = Piston::WorkingCopy.guess(wcdir)
0
+
0
         tmpdir = temp_dir_name(working_copy)
0
 
0
         abort("Path #{working_copy} already exists and --force not given. Aborting...") if working_copy.exist? && !force
...
32
33
34
 
 
 
 
35
36
37
...
32
33
34
35
36
37
38
39
40
41
0
@@ -32,6 +32,10 @@
0
           Piston::Git::Commit.new(self, commit)
0
         end
0
       end
0
+
0
+ def basename
0
+ self.url.split("/").last.sub(".git", "")
0
+ end
0
     end
0
   end
0
 end
...
45
46
47
 
 
 
 
 
 
 
 
48
49
50
...
45
46
47
48
49
50
51
52
53
54
55
56
57
58
0
@@ -45,6 +45,14 @@
0
 
0
         Piston::Svn::Revision.new(self, rev)
0
       end
0
+
0
+ def basename
0
+ if self.url =~ /trunk|branches|tags/ then
0
+ self.url.sub(%r{/(?:trunk|branches|tags).*$}, "").split("/").last
0
+ else
0
+ self.url.split("/").last
0
+ end
0
+ end
0
     end
0
   end
0
 end
...
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
0
@@ -1 +1,8 @@
0
+---
0
+format: 1
0
+handler:
0
+ piston:remote-revision: 9088
0
+ piston:root: http://dev.rubyonrails.org/svn/rails/plugins/ssl_requirement
0
+ piston:uuid: 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
0
+lock: false
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
0
@@ -1 +1,44 @@
0
+SSL Requirement
0
+===============
0
+
0
+SSL requirement adds a declarative way of specifying that certain actions
0
+should only be allowed to run under SSL, and if they're accessed without it,
0
+they should be redirected.
0
+
0
+Example:
0
+
0
+ class ApplicationController < ActiveRecord::Base
0
+ include SslRequirement
0
+ end
0
+
0
+ class AccountController < ApplicationController
0
+ ssl_required :signup, :payment
0
+ ssl_allowed :index
0
+
0
+ def signup
0
+ # Non-SSL access will be redirected to SSL
0
+ end
0
+
0
+ def payment
0
+ # Non-SSL access will be redirected to SSL
0
+ end
0
+
0
+ def index
0
+ # This action will work either with or without SSL
0
+ end
0
+
0
+ def other
0
+ # SSL access will be redirected to non-SSL
0
+ end
0
+ end
0
+
0
+You can overwrite the protected method ssl_required? to rely on other things
0
+than just the declarative specification. Say, only premium accounts get SSL.
0
+
0
+P.S.: Beware when you include the SslRequirement module. At the time of
0
+inclusion, it'll add the before_filter that validates the declarations. Some
0
+times you'll want to run other before_filters before that. They should then be
0
+declared ahead of including this module.
0
+
0
+Copyright (c) 2005 David Heinemeier Hansson, released under the MIT license
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
0
@@ -1 +1,63 @@
0
+# Copyright (c) 2005 David Heinemeier Hansson
0
+#
0
+# Permission is hereby granted, free of charge, to any person obtaining
0
+# a copy of this software and associated documentation files (the
0
+# "Software"), to deal in the Software without restriction, including
0
+# without limitation the rights to use, copy, modify, merge, publish,
0
+# distribute, sublicense, and/or sell copies of the Software, and to
0
+# permit persons to whom the Software is furnished to do so, subject to
0
+# the following conditions:
0
+#
0
+# The above copyright notice and this permission notice shall be
0
+# included in all copies or substantial portions of the Software.
0
+#
0
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
0
+# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
0
+# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
0
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
0
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
0
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
0
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
0
+module SslRequirement
0
+ def self.included(controller)
0
+ controller.extend(ClassMethods)
0
+ controller.before_filter(:ensure_proper_protocol)
0
+ end
0
+
0
+ module ClassMethods
0
+ # Specifies that the named actions requires an SSL connection to be performed (which is enforced by ensure_proper_protocol).
0
+ def ssl_required(*actions)
0
+ write_inheritable_array(:ssl_required_actions, actions)
0
+ end
0
+
0
+ def ssl_allowed(*actions)
0
+ write_inheritable_array(:ssl_allowed_actions, actions)
0
+ end
0
+ end
0
+
0
+ protected
0
+ # Returns true if the current action is supposed to run as SSL
0
+ def ssl_required?
0
+ (self.class.read_inheritable_attribute(:ssl_required_actions) || []).include?(action_name.to_sym)
0
+ end
0
+
0
+ def ssl_allowed?
0
+ (self.class.read_inheritable_attribute(:ssl_allowed_actions) || []).include?(action_name.to_sym)
0
+ end
0
+
0
+ private
0
+ def ensure_proper_protocol
0
+ return true if ssl_allowed?
0
+
0
+ if ssl_required? && !request.ssl?
0
+ redirect_to "https://" + request.host + request.request_uri
0
+ flash.keep
0
+ return false
0
+ elsif request.ssl? && !ssl_required?
0
+ redirect_to "http://" + request.host + request.request_uri
0
+ flash.keep
0
+ return false
0
+ end
0
+ end
0
+end
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
0
@@ -1 +1,133 @@
0
+begin
0
+ require 'action_controller'
0
+rescue LoadError
0
+ if ENV['ACTIONCONTROLLER_PATH'].nil?
0
+ abort <<MSG
0
+Please set the ACTIONCONTROLLER_PATH environment variable to the directory
0
+containing the action_controller.rb file.
0
+MSG
0
+ else
0
+ $LOAD_PATH.unshift << ENV['ACTIONCONTROLLER_PATH']
0
+ begin
0
+ require 'action_controller'
0
+ rescue LoadError
0
+ abort "ActionController could not be found."
0
+ end
0
+ end
0
+end
0
+
0
+require 'action_controller/test_process'
0
+require 'test/unit'
0
+require "#{File.dirname(__FILE__)}/../lib/ssl_requirement"
0
+
0
+ActionController::Base.logger = nil
0
+ActionController::Routing::Routes.reload rescue nil
0
+
0
+class SslRequirementController < ActionController::Base
0
+ include SslRequirement
0
+
0
+ ssl_required :a, :b
0
+ ssl_allowed :c
0
+
0
+ def a
0
+ render :nothing => true
0
+ end
0
+
0
+ def b
0
+ render :nothing => true
0
+ end
0
+
0
+ def c
0
+ render :nothing => true
0
+ end
0
+
0
+ def d
0
+ render :nothing => true
0
+ end
0
+
0
+ def set_flash
0
+ flash[:foo] = "bar"
0
+ end
0
+end
0
+
0
+class SslRequirementTest < Test::Unit::TestCase
0
+ def setup
0
+ @controller = SslRequirementController.new
0
+ @request = ActionController::TestRequest.new
0
+ @response = ActionController::TestResponse.new
0
+ end
0
+
0
+ def test_redirect_to_https_preserves_flash
0
+ get :set_flash
0
+ get :b
0
+ assert_response :redirect
0
+ assert_equal "bar", flash[:foo]
0
+ end
0
+
0
+ def test_not_redirecting_to_https_does_not_preserve_the_flash
0
+ get :set_flash
0
+ get :d
0
+ assert_response :success
0
+ assert_nil flash[:foo]
0
+ end
0
+
0
+ def test_redirect_to_http_preserves_flash
0
+ get :set_flash
0
+ @request.env['HTTPS'] = "on"
0
+ get :d
0
+ assert_response :redirect
0
+ assert_equal "bar", flash[:foo]
0
+ end
0
+
0
+ def test_not_redirecting_to_http_does_not_preserve_the_flash
0
+ get :set_flash
0
+ @request.env['HTTPS'] = "on"
0
+ get :a
0
+ assert_response :success
0
+ assert_nil flash[:foo]
0
+ end
0
+
0
+ def test_required_without_ssl
0
+ assert_not_equal "on", @request.env["HTTPS"]
0
+ get :a
0
+ assert_response :redirect
0
+ assert_match %r{^https://}, @response.headers['Location']
0
+ get :b
0
+ assert_response :redirect
0
+ assert_match %r{^https://}, @response.headers['Location']
0
+ end
0
+
0
+ def test_required_with_ssl
0
+ @request.env['HTTPS'] = "on"
0
+ get :a
0
+ assert_response :success
0
+ get :b
0
+ assert_response :success
0
+ end
0
+
0
+ def test_disallowed_without_ssl
0
+ assert_not_equal "on", @request.env["HTTPS"]
0
+ get :d
0
+ assert_response :success
0
+ end
0
+
0
+ def test_disallowed_with_ssl
0
+ @request.env['HTTPS'] = "on"
0
+ get :d
0
+ assert_response :redirect
0
+ assert_match %r{^http://}, @response.headers['Location']
0
+ end
0
+
0
+ def test_allowed_without_ssl
0
+ assert_not_equal "on", @request.env["HTTPS"]
0
+ get :c
0
+ assert_response :success
0
+ end
0
+
0
+ def test_allowed_with_ssl
0
+ @request.env['HTTPS'] = "on"
0
+ get :c
0
+ assert_response :success
0
+ end
0
+end
...
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
0
@@ -1 +1,13 @@
0
+require File.dirname(__FILE__) + "/../test_helper"
0
+
0
+class TestGitRepositoryBasename < Test::Unit::TestCase
0
+ def test_basename_is_urls_last_component_minus_dot_git
0
+ assert_equal "piston", basename("git://github.com/francois/piston.git")
0
+ end
0
+
0
+ private
0
+ def basename(url)
0
+ Piston::Git::Repository.new(url).basename
0
+ end
0
+end
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
0
@@ -1 +1,25 @@
0
+require File.dirname(__FILE__) + "/../test_helper"
0
+
0
+class TestSvnRepositoryBasename < Test::Unit::TestCase
0
+ def test_basename_is_urls_path_last_component
0
+ assert_equal "piston", basename("http://svn.rubyforge.org/var/svn/piston")
0
+ end
0
+
0
+ def test_basename_is_urls_path_last_component_minus_trunk
0
+ assert_equal "attachment_fu", basename("svn+ssh://some.host.com/svn/attachment_fu/trunk")
0
+ end
0
+
0
+ def test_basename_is_urls_path_last_component_before_branches
0
+ assert_equal "rails", basename("svn://some.host.com/svn/rails/branches/stable")
0
+ end
0
+
0
+ def test_basename_is_urls_path_last_component_before_tags
0
+ assert_equal "plugin", basename("https://some.host.com/svn/plugin/tags/stable")
0
+ end
0
+
0
+ private
0
+ def basename(url)
0
+ Piston::Svn::Repository.new(url).basename
0
+ end
0
+end

Comments

    No one has commented yet.