Module: Buildr::Git
- Defined in:
- lib/buildr/core/build.rb
Overview
:nodoc:
Class Method Summary collapse
-
.commit(file, message) ⇒ Object
Commit the given file with a message.
-
.current_branch ⇒ Object
Return the name of the current branch.
-
.git(*args) ⇒ Object
:call-seq: git(*args).
-
.push(remote_repo = remote, remote_branch = current_branch) ⇒ Object
Update the remote refs using local refs.
-
.remote(branch = current_branch) ⇒ Object
Return the name of the remote repository whose branch the current local branch tracks, or nil if none.
-
.uncommitted_files ⇒ Object
Returns list of uncommited/untracked files as reported by git status.
Class Method Details
.commit(file, message) ⇒ Object
Commit the given file with a message. The file has to be known to Git meaning that it has either to have been already committed in the past or freshly added to the index. Otherwise it will fail.
136 137 138 |
# File 'lib/buildr/core/build.rb', line 136 def commit(file, ) git 'commit', '-m', , file end |
.current_branch ⇒ Object
Return the name of the current branch
156 157 158 |
# File 'lib/buildr/core/build.rb', line 156 def current_branch git('branch')[/^\* (.*)$/, 1] end |
.git(*args) ⇒ Object
:call-seq:
git(*args)
Executes a Git command and returns the output. Throws exception if the exit status is not zero. For example:
git 'commit'
git 'remote', 'show', 'origin'
121 122 123 124 125 126 |
# File 'lib/buildr/core/build.rb', line 121 def git(*args) cmd = "git #{args.shift} #{args.map { |arg| arg.inspect }.join(' ')}" output = `#{cmd}` fail "GIT command \"#{cmd}\" failed with status #{$?.exitstatus}\n#{output}" unless $?.exitstatus == 0 return output end |
.push(remote_repo = remote, remote_branch = current_branch) ⇒ Object
Update the remote refs using local refs
By default, the “remote” destination of the push is the the remote repo linked to the current branch. The default remote branch is the current local branch.
144 145 146 |
# File 'lib/buildr/core/build.rb', line 144 def push(remote_repo = remote, remote_branch = current_branch) git 'push', remote, current_branch end |
.remote(branch = current_branch) ⇒ Object
Return the name of the remote repository whose branch the current local branch tracks, or nil if none.
150 151 152 153 |
# File 'lib/buildr/core/build.rb', line 150 def remote(branch = current_branch) remote = git('config', '--get', "branch.#{branch}.remote").to_s.strip remote if !remote.empty? && git('remote').include?(remote) end |
.uncommitted_files ⇒ Object
Returns list of uncommited/untracked files as reported by git status.
129 130 131 |
# File 'lib/buildr/core/build.rb', line 129 def uncommitted_files `git status`.scan(/^#(\t|\s{7})(\S.*)$/).map { |match| match.last.split.last } end |