From 368d33ab7bc088d57e6d505f91c938caaed055e8 Mon Sep 17 00:00:00 2001 From: Gant Date: Wed, 15 May 2013 14:59:10 -0500 Subject: [PATCH 1/9] beginning in template --- lib/motion/project/template.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/motion/project/template.rb b/lib/motion/project/template.rb index 46014121..4e568f91 100644 --- a/lib/motion/project/template.rb +++ b/lib/motion/project/template.rb @@ -49,6 +49,8 @@ module Motion; module Project @name = @app_name = app_name @template_name = template_name.to_s + handle_git if @template_name.is_git? + @template_directory = self.class.all_templates[@template_name] unless @template_directory $stderr.puts "Cannot find template `#{@template_name}' in #{Paths.join(' or ')}" @@ -115,5 +117,16 @@ module Motion; module Project file_name = file_name.sub("{name}", "#{@name}") file_name end + + def handle_git + puts "Handling git" + end + end + + class String + def is_git? + puts "Checking for git" + false + end end end; end From f35a03bfac50bd183a51d615761a78300515f592 Mon Sep 17 00:00:00 2001 From: Gant Laborde Date: Wed, 15 May 2013 16:30:28 -0400 Subject: [PATCH 2/9] Adding info on how to use forked RM for motion changes. current documentation is great for rake, but neglects motion. Documenting this for others. --- README.rdoc | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/README.rdoc b/README.rdoc index 477e3cfd..66eadf30 100644 --- a/README.rdoc +++ b/README.rdoc @@ -30,6 +30,19 @@ Then, simply set the RUBYMOTION_LIB environment variable when using +rake+. $ cd MyProject $ RUBYMOTION_LIB=~/src/RubyMotion/lib rake + +--------------- +If you are looking to modify the +motion+ command, you'll need to mimick your existing +/usr/bin/motion+ + +E.G. + $ sudo cp /usr/bin/motion /usr/bing/motionme + +change ownership of the resulting file if needed. + +Edit +motionme+ and point the $motion_libdir variable at your local git repo. + $motion_libdir = '/Absolute/Path/To/Forked/RubyMotion/lib/' + +Now using +motionme+ instead of +motion+ will use the forked RubyMotion == Contributions From c6cc46aafef929fec15f105539476b46ca23b427 Mon Sep 17 00:00:00 2001 From: Gant Date: Wed, 15 May 2013 16:10:00 -0500 Subject: [PATCH 3/9] Regex checks for git --- lib/motion/project/template.rb | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/motion/project/template.rb b/lib/motion/project/template.rb index 4e568f91..01495bf2 100644 --- a/lib/motion/project/template.rb +++ b/lib/motion/project/template.rb @@ -49,7 +49,7 @@ module Motion; module Project @name = @app_name = app_name @template_name = template_name.to_s - handle_git if @template_name.is_git? + handle_git if is_git? @template_name @template_directory = self.class.all_templates[@template_name] unless @template_directory @@ -121,12 +121,11 @@ module Motion; module Project def handle_git puts "Handling git" end - end - class String - def is_git? - puts "Checking for git" - false + def is_git? template + #template[0,4].downcase == "git@" + template.match(/git@.+:.+\.git/i) end end + end; end From a6addd6ec0bcd032e173c131bfced3288f31a0e8 Mon Sep 17 00:00:00 2001 From: Gant Date: Thu, 16 May 2013 10:07:50 -0500 Subject: [PATCH 4/9] detecting git --- lib/motion/project/template.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/motion/project/template.rb b/lib/motion/project/template.rb index 01495bf2..e7e83b11 100644 --- a/lib/motion/project/template.rb +++ b/lib/motion/project/template.rb @@ -123,7 +123,6 @@ module Motion; module Project end def is_git? template - #template[0,4].downcase == "git@" template.match(/git@.+:.+\.git/i) end end From 0a925134c0603088c405ba86c32417b0d5f45da0 Mon Sep 17 00:00:00 2001 From: Gant Date: Thu, 16 May 2013 13:59:00 -0500 Subject: [PATCH 5/9] Really close, just need to figure out the cache issue on new create --- lib/motion/project/template.rb | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/lib/motion/project/template.rb b/lib/motion/project/template.rb index e7e83b11..b5f101ac 100644 --- a/lib/motion/project/template.rb +++ b/lib/motion/project/template.rb @@ -49,7 +49,11 @@ module Motion; module Project @name = @app_name = app_name @template_name = template_name.to_s - handle_git if is_git? @template_name + if @git_name = find_git(@template_name) + App.log 'Git', "Getting template #{@git_name}" + handle_git + @template_name = @git_name + end @template_directory = self.class.all_templates[@template_name] unless @template_directory @@ -119,11 +123,24 @@ module Motion; module Project end def handle_git - puts "Handling git" + path = self.class.all_templates[@git_name] + # check if directory exists + if path + # directory exists just do a pull + App.log 'Git', "#{@git_name} exists performing a pull" + system("GIT_DIR=#{path}/.git git pull origin master") + else + # no directory exists so clone + system("git clone #{@template_name} ~/Library/RubyMotion/template/#{@git_name}") + #clear @all_templates cache + #self.instance_variable_set(:@all_templates, nil) + self.instance_eval('@all_templates = nil') + end end - def is_git? template - template.match(/git@.+:.+\.git/i) + def find_git template + # regex play http://rubular.com/r/z14JRrkqXa + template =~ /git@.+:.+\/(.+)\.git/i ? $1 : false end end From 6091814b65e025bec8672071f6f1b2e8a4ccd6d1 Mon Sep 17 00:00:00 2001 From: Gant Date: Thu, 16 May 2013 14:09:43 -0500 Subject: [PATCH 6/9] Cache issue resolved, git works --- lib/motion/project/template.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/motion/project/template.rb b/lib/motion/project/template.rb index b5f101ac..7dc692bf 100644 --- a/lib/motion/project/template.rb +++ b/lib/motion/project/template.rb @@ -133,8 +133,7 @@ module Motion; module Project # no directory exists so clone system("git clone #{@template_name} ~/Library/RubyMotion/template/#{@git_name}") #clear @all_templates cache - #self.instance_variable_set(:@all_templates, nil) - self.instance_eval('@all_templates = nil') + self.class.instance_variable_set(:@all_templates, nil) end end From be5d697fd7ff7d7c987e586628841fc360fd96c2 Mon Sep 17 00:00:00 2001 From: Matt Garrison Date: Fri, 17 May 2013 09:49:31 -0500 Subject: [PATCH 7/9] Update README.rdoc --- README.rdoc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.rdoc b/README.rdoc index 66eadf30..f0030480 100644 --- a/README.rdoc +++ b/README.rdoc @@ -32,12 +32,12 @@ Then, simply set the RUBYMOTION_LIB environment variable when using +rake+. $ RUBYMOTION_LIB=~/src/RubyMotion/lib rake --------------- -If you are looking to modify the +motion+ command, you'll need to mimick your existing +/usr/bin/motion+ -E.G. - $ sudo cp /usr/bin/motion /usr/bing/motionme +If you are looking to modify the +motion+ command itself, you'll need to mimick your existing +/usr/bin/motion+ -change ownership of the resulting file if needed. +An easy way is to just make a copy somewhere on your $PATH and use that for testing + + $ sudo cp /usr/bin/motion /usr/bin/motionme Edit +motionme+ and point the $motion_libdir variable at your local git repo. $motion_libdir = '/Absolute/Path/To/Forked/RubyMotion/lib/' From 6273ecece045f8c1dc1f5fe49b4eb1bed28b232c Mon Sep 17 00:00:00 2001 From: Matt Garrison Date: Fri, 17 May 2013 11:03:52 -0500 Subject: [PATCH 8/9] added more robust repo name extraction, refactored names to be more descriptive --- lib/motion/project/template.rb | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/motion/project/template.rb b/lib/motion/project/template.rb index 7dc692bf..d6aaa321 100644 --- a/lib/motion/project/template.rb +++ b/lib/motion/project/template.rb @@ -48,10 +48,11 @@ module Motion; module Project def initialize(app_name, template_name) @name = @app_name = app_name @template_name = template_name.to_s + @git_name = extract_repo_name(@template_name) - if @git_name = find_git(@template_name) - App.log 'Git', "Getting template #{@git_name}" - handle_git + if @git_name + App.log 'Git', "Cloning #{@git_name} template" + clone_template_repository @template_name = @git_name end @@ -122,7 +123,7 @@ module Motion; module Project file_name end - def handle_git + def clone_template_repository path = self.class.all_templates[@git_name] # check if directory exists if path @@ -137,9 +138,11 @@ module Motion; module Project end end - def find_git template - # regex play http://rubular.com/r/z14JRrkqXa - template =~ /git@.+:.+\/(.+)\.git/i ? $1 : false + # Extract repo name from HTTP, SSH or Git URLs: + def extract_repo_name template + http_template = template =~ /\w+:\/\/.+@*[\w\d\.]+\/.+\/(.+).git/i ? $1 : false + git_template = template =~ /git@.+:.+\/(.+)\.git/i ? $1 : false + http_template || git_template end end From 3242325a9f8aa047b23d30f69edfb9b12f2768ee Mon Sep 17 00:00:00 2001 From: Matt Garrison Date: Fri, 17 May 2013 11:10:15 -0500 Subject: [PATCH 9/9] added conditional for failed repo clones --- lib/motion/project/template.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/motion/project/template.rb b/lib/motion/project/template.rb index d6aaa321..ff969b04 100644 --- a/lib/motion/project/template.rb +++ b/lib/motion/project/template.rb @@ -128,12 +128,16 @@ module Motion; module Project # check if directory exists if path # directory exists just do a pull - App.log 'Git', "#{@git_name} exists performing a pull" + App.log 'Git', "#{@git_name} already exists, performing a pull" system("GIT_DIR=#{path}/.git git pull origin master") else # no directory exists so clone - system("git clone #{@template_name} ~/Library/RubyMotion/template/#{@git_name}") - #clear @all_templates cache + result = system("git clone #{@template_name} ~/Library/RubyMotion/template/#{@git_name}") + unless result + App.log 'Git', "Unable to clone #{@template_name}" + end + # clear @all_templates cache, which should cause the motion command to fail + # without blowing up, regardless of the clone result self.class.instance_variable_set(:@all_templates, nil) end end