fastlane/lib/fastlane/actions/git_add.rb in fastlane-2.90.0.beta.20180406050006 vs fastlane/lib/fastlane/actions/git_add.rb in fastlane-2.90.0.beta.20180407050037

- old
+ new

@@ -1,17 +1,21 @@ module Fastlane module Actions class GitAddAction < Action def self.run(params) + should_escape = params[:shell_escape] + if params[:pathspec] paths = params[:pathspec] UI.success("Successfully added from \"#{paths}\" 💾.") elsif params[:path] if params[:path].kind_of?(String) - paths = params[:path].shellescape - else - paths = params[:path].map(&:shellescape).join(' ') + paths = shell_escape(params[:path], should_escape) + elsif params[:path].kind_of?(Array) + paths = params[:path].map do |p| + shell_escape(p, should_escape) + end.join(' ') end UI.success("Successfully added \"#{paths}\" 💾.") else paths = "." UI.success("Successfully added all files 💾.") @@ -19,10 +23,15 @@ result = Actions.sh("git add #{paths}", log: FastlaneCore::Globals.verbose?).chomp return result end + def self.shell_escape(path, should_escape) + path = path.shellescape if should_escape + path + end + ##################################################### # @!group Documentation ##################################################### def self.description @@ -30,28 +39,26 @@ end def self.available_options [ FastlaneCore::ConfigItem.new(key: :path, - description: "The file you want to add", + description: "The file(s) and path(s) you want to add", is_string: false, conflicting_options: [:pathspec], - optional: true, - verify_block: proc do |value| - if value.kind_of?(String) - UI.user_error!("Couldn't find file at path '#{value}'") unless File.exist?(value) - else - value.each do |x| - UI.user_error!("Couldn't find file at path '#{x}'") unless File.exist?(x) - end - end - end), + optional: true), + FastlaneCore::ConfigItem.new(key: :shell_escape, + description: "Shell escapes paths (set to false if using wildcards or manually escaping spaces in :path)", + is_string: false, + default_value: true, + optional: true), + # Deprecated FastlaneCore::ConfigItem.new(key: :pathspec, description: "The pathspec you want to add files from", is_string: true, conflicting_options: [:path], - optional: true) + optional: true, + deprecated: "Use --path instead") ] end def self.return_value nil @@ -68,11 +75,13 @@ def self.example_code [ 'git_add', 'git_add(path: "./version.txt")', 'git_add(path: ["./version.txt", "./changelog.txt"])', - 'git_add(pathspec: "./Frameworks/*")', - 'git_add(pathspec: "*.txt")' + 'git_add(path: "./Frameworks/*", shell_escape: false', + 'git_add(path: ["*.h", "*.m"], shell_escape: false)', + 'git_add(path: "./Frameworks/*", shell_escape: false)', + 'git_add(path: "*.txt", shell_escape: false)' ] end def self.category :source_control