Sha256: 280b0b9f2541e5bc7c66288182dac879c395a90877e7c0c5440686045388019e
Contents?: true
Size: 1.96 KB
Versions: 4
Compression:
Stored size: 1.96 KB
Contents
require 'fileutils' require 'lookfile' # module for help with git module Git module_function BASE_DIR = '~/'.freeze LOOKFILE_DIR = '.lookfile'.freeze def load_git_command(base_dir = BASE_DIR) directory = Lookfile.load_lookfile_dir(base_dir) "git -C '#{directory}'" end def init(base_dir = BASE_DIR) git = load_git_command(base_dir) `#{git} init` end def remote?(base_dir = BASE_DIR) git = load_git_command(base_dir) remote = `#{git} remote` remote.include?('origin') end def set_remote(repository_ssh_name, base_dir = BASE_DIR) git = load_git_command(base_dir) `#{git} remote remove origin` if remote?(base_dir) `#{git} remote add origin #{repository_ssh_name}` end def rebase(base_dir = BASE_DIR) git = load_git_command(base_dir) branchs = `#{git} branch -a` return nil unless branchs.include?('remotes/origin/master') `#{git} fetch origin -p` `#{git} pull origin master` end def status(base_dir = BASE_DIR) git = load_git_command(base_dir) untracked_files = `#{git} ls-files --others --exclude-standard`.split deleted_files = `#{git} ls-files --deleted`.split modified_files = `#{git} ls-files --modified`.split - deleted_files message = Lookfile.show_files("\nAdded files:", untracked_files) message += Lookfile.show_files("\nModified files:", modified_files) message += Lookfile.show_files("\nDeleted files:", deleted_files) message.strip end def commit(base_dir = BASE_DIR) git = load_git_command(base_dir) message = status(base_dir) `#{git} add --all` return nil if !make_commit?(message, base_dir) || message.empty? message end def push(base_dir = BASE_DIR) git = load_git_command(base_dir) `#{git} push origin master` end def make_commit?(message, base_dir = BASE_DIR) git = load_git_command(base_dir) commit = `#{git} commit -m "#{message}"` return false if commit.include?('nothing to commit') true end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
lookfile-0.1.5 | lib/git.rb |
lookfile-0.1.4 | lib/git.rb |
lookfile-0.1.3 | lib/git.rb |
lookfile-0.1.2 | lib/git.rb |