Class: Raykit::Git::Directory
- Inherits:
-
Object
- Object
- Raykit::Git::Directory
- Defined in:
- lib/raykit/git/directory.rb
Overview
Functionality to manage a local clone of a git repository
Instance Attribute Summary collapse
-
#directory ⇒ Object
The directory name of the local repository clone.
Instance Method Summary collapse
- #branch ⇒ Object
-
#initialize(directory) ⇒ Directory
constructor
A new instance of Directory.
- #last_modified_time ⇒ Object
-
#latest_tag(branch) ⇒ Object
The latest tag for a branch of the repository.
- #outstanding_commit? ⇒ Boolean
- #pull ⇒ Object
- #rake(task) ⇒ Object
- #remote ⇒ Object
- #repository ⇒ Object
- #user_can_commit ⇒ Object
- #user_email ⇒ Object
- #user_name ⇒ Object
Constructor Details
#initialize(directory) ⇒ Directory
Returns a new instance of Directory.
9 10 11 |
# File 'lib/raykit/git/directory.rb', line 9 def initialize(directory) @directory=directory end |
Instance Attribute Details
#directory ⇒ Object
The directory name of the local repository clone
6 7 8 |
# File 'lib/raykit/git/directory.rb', line 6 def directory @directory end |
Instance Method Details
#branch ⇒ Object
94 95 96 97 98 99 100 |
# File 'lib/raykit/git/directory.rb', line 94 def branch Dir.chdir(directory) do scan=`git branch`.scan(/\*\s([\w\.-]+)/) return scan[0][0].to_s if(!scan.nil? && scan.length > 0 && scan[0].length > 0) end 'master' end |
#last_modified_time ⇒ Object
66 67 68 69 70 |
# File 'lib/raykit/git/directory.rb', line 66 def last_modified_time Dir.chdir(@directory) do File.mtime(Dir.glob("**/*.*").select{|f| File.file?(f)}.max_by {|f| File.mtime(f)}) end end |
#latest_tag(branch) ⇒ Object
The latest tag for a branch of the repository
73 74 75 76 77 78 |
# File 'lib/raykit/git/directory.rb', line 73 def latest_tag(branch) Dir.chdir(directory) do return `git describe --abbrev=0`.strip end '' end |
#outstanding_commit? ⇒ Boolean
13 14 15 16 17 18 19 20 21 |
# File 'lib/raykit/git/directory.rb', line 13 def outstanding_commit? Dir.chdir(directory) do if(user_can_commit) return !`git status`.include?('nothing to commit,') else return false end end end |
#pull ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/raykit/git/directory.rb', line 23 def pull Dir.chdir(directory) do diff=`git diff`.strip status=`git status`.strip if(diff.length == 0 && status.include?('nothing to commit')) PROJECT.run('git pull',false) end end end |
#rake(task) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/raykit/git/directory.rb', line 33 def rake(task) if(!Dir.exist?(@directory)) puts 'directory not found.' return 1 end debug=false sub_dir='work' sub_dir='make' if(@directory.include?('/make/')) rake_log=repository.get_dev_dir('log') + "/#{sub_dir}.rake.#{task}.json" puts "log filename #{rake_log}" if(debug) if(File.exist?(rake_log)) if(File.mtime(rake_log) > last_modified_time) puts "using logged data" if(debug) cmd=Raykit::Command::parse(File.read(rake_log)) cmd.summary return end end Dir.chdir(@directory) do if(File.exist?('rakefile.rb')) cmd = Raykit::Command.new("rake #{task}") cmd.summary FileUtils.mkdir_p(File.dirname(rake_log)) File.open(rake_log, 'w') {|f| f.write(JSON.generate(cmd.to_hash)) } else puts 'rakefile.rb not found' end end end |
#remote ⇒ Object
109 110 111 112 113 114 115 116 117 118 |
# File 'lib/raykit/git/directory.rb', line 109 def remote if(Dir.exist?(directory)) Dir.chdir(directory) do if(Dir.exist?('.git')) return Command.new('git config --get remote.origin.url').output.strip end end end "" end |
#repository ⇒ Object
102 103 104 105 106 107 |
# File 'lib/raykit/git/directory.rb', line 102 def repository if(@repository.nil?) @repository = Raykit::Git::Repository.new(remote) end @repository end |
#user_can_commit ⇒ Object
88 89 90 91 92 |
# File 'lib/raykit/git/directory.rb', line 88 def user_can_commit return false if(user_name.length == 0) return false if(user_email.length == 0) return true end |
#user_email ⇒ Object
84 85 86 |
# File 'lib/raykit/git/directory.rb', line 84 def user_email `git config --get user.email`.strip end |
#user_name ⇒ Object
80 81 82 |
# File 'lib/raykit/git/directory.rb', line 80 def user_name `git config --get user.name`.strip end |