lib/git_p4_sync.rb in git-p4-sync-0.1.0 vs lib/git_p4_sync.rb in git-p4-sync-0.1.1

- old
+ new

@@ -1,17 +1,27 @@ module GitP4Sync - + def run(options) # branch = options[:branch] || "master" branch = "master" git_path = options[:git] p4_path = options[:p4] simulate = options[:simulate] || false pull = options[:pull] || false submit = options[:submit] || false - ignore_list = ( options[:ignore] ? options[:ignore].split(",") : [".git"] ) + @ignore_list = [".git"] + if options[:ignore] + if options[:ignore].include?(":") + @ignore_list = @ignore_list.concat(options[:ignore].split(":")) + elsif options[:ignore].include?(",") + @ignore_list = @ignore_list.concat(options[:ignore].split(",")) + else + @ignore_list = @ignore_list.insert(-1, options[:ignore]) + end + end + git_path = add_slash(File.expand_path(git_path)) p4_path = add_slash(File.expand_path(p4_path)) verify_path_exist!(git_path) verify_path_exist!(p4_path) @@ -21,18 +31,23 @@ puts "Pulling Git from remote server." run_cmd "git pull", simulate end end + if File.exist?(gitignore = File.join(git_path, ".gitignore")) + @ignore_list = @ignore_list.concat(File.read(gitignore).split(/\n/).map {|i| i.gsub("*",".*") } ) + end + diff = diff_dirs(p4_path, git_path) if diff.size > 0 diff.each do |d| action = d[0] file = strip_leading_slash(d[1]) # todo: skip ignored files/directories + next if is_ignored?(file) puts "#{action.to_s.upcase} in Git: #{file}" Dir.chdir(p4_path) do case action @@ -76,9 +91,21 @@ end output = "" output = `#{cmd}` unless simulate [output, $?] + end + + def lambda_ignore(item) + re = Regexp.compile(/#{item}/) + lambda {|diff| diff =~ re } + end + + def is_ignored?(file) + @ignore_list.each {|ignore| + return true if lambda_ignore(ignore).call(file) + } + return false end def add_slash(path) path += "/" unless path[-1..-1] == "/" path