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.
-
#latest_tag(branch) ⇒ Object
The latest tag for a branch of the repository.
- #outstanding_commit? ⇒ Boolean
- #pull ⇒ Object
- #rake(task) ⇒ Object
- #remote ⇒ Object
- #user_can_commit ⇒ Object
- #user_email ⇒ Object
- #user_name ⇒ Object
Constructor Details
#initialize(directory) ⇒ Directory
Returns a new instance of Directory.
8 9 10 |
# File 'lib/raykit/git/directory.rb', line 8 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
60 61 62 63 64 65 66 |
# File 'lib/raykit/git/directory.rb', line 60 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 |
#latest_tag(branch) ⇒ Object
The latest tag for a branch of the repository
39 40 41 42 43 44 |
# File 'lib/raykit/git/directory.rb', line 39 def latest_tag(branch) Dir.chdir(directory) do return `git describe --abbrev=0`.strip end '' end |
#outstanding_commit? ⇒ Boolean
12 13 14 15 16 17 18 19 20 |
# File 'lib/raykit/git/directory.rb', line 12 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
22 23 24 25 26 |
# File 'lib/raykit/git/directory.rb', line 22 def pull Dir.chdir(directory) do PROJECT.run('git pull') end end |
#rake(task) ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/raykit/git/directory.rb', line 28 def rake(task) Dir.chdir(directory) do if(File.exist?('rakefile.rb')) PROJECT.run("rake #{task}") else puts 'rakefile.rb not found' end end end |
#remote ⇒ Object
68 69 70 71 72 73 |
# File 'lib/raykit/git/directory.rb', line 68 def remote Dir.chdir(directory) do return Command.new('git config --get remote.origin.url').output.strip if(Dir.exist?('.git')) end `` end |
#user_can_commit ⇒ Object
54 55 56 57 58 |
# File 'lib/raykit/git/directory.rb', line 54 def user_can_commit return false if(user_name.length == 0) return false if(user_email.length == 0) return true end |
#user_email ⇒ Object
50 51 52 |
# File 'lib/raykit/git/directory.rb', line 50 def user_email `git config --get user.email`.strip end |
#user_name ⇒ Object
46 47 48 |
# File 'lib/raykit/git/directory.rb', line 46 def user_name `git config --get user.name`.strip end |