class Gync::Git
Public Class Methods
new(local_path, remote_path)
click to toggle source
# File lib/gync/git.rb, line 3 def initialize(local_path, remote_path) @local_path, @remote_path = local_path, remote_path end
Public Instance Methods
pull()
click to toggle source
# File lib/gync/git.rb, line 7 def pull reopen_repo! @git.fetch @git.merge 'origin/master' end
push()
click to toggle source
# File lib/gync/git.rb, line 13 def push reopen_repo! if not changed_files.empty? or not new_files.empty? or not removed_files.empty? @git.add changed_files unless changed_files.empty? @git.add new_files unless new_files.empty? @git.remove removed_files unless removed_files.empty? @git.commit commit_msg @git.push "origin", "master" end end
Private Instance Methods
changed_files()
click to toggle source
# File lib/gync/git.rb, line 34 def changed_files get_file_names @git.status.changed end
commit_msg()
click to toggle source
# File lib/gync/git.rb, line 46 def commit_msg host = Socket.gethostname if host and not host.empty? "Gync commit from #{host}" else "Gync commit" end end
get_file_names(files)
click to toggle source
# File lib/gync/git.rb, line 55 def get_file_names(files) if RUBY_VERSION =~ /^1.8/ files.map{|f| f.first} else files.keys end end
new_files()
click to toggle source
# File lib/gync/git.rb, line 38 def new_files get_file_names @git.status.untracked end
removed_files()
click to toggle source
# File lib/gync/git.rb, line 42 def removed_files get_file_names @git.status.deleted end
reopen_repo!()
click to toggle source
# File lib/gync/git.rb, line 27 def reopen_repo! @git = ::Git.open(@local_path) rescue ArgumentError @git = ::Git.init(@local_path) @git.add_remote "origin", @remote_path end