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.
157 158 159 |
# File 'lib/buildr/core/build.rb', line 157 def commit(file, ) git 'commit', '-m', , file end |
.current_branch ⇒ Object
Return the name of the current branch
177 178 179 |
# File 'lib/buildr/core/build.rb', line 177 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'
142 143 144 145 146 147 |
# File 'lib/buildr/core/build.rb', line 142 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.
165 166 167 |
# File 'lib/buildr/core/build.rb', line 165 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.
171 172 173 174 |
# File 'lib/buildr/core/build.rb', line 171 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.
150 151 152 |
# File 'lib/buildr/core/build.rb', line 150 def uncommitted_files `git status`.scan(/^#(\t|\s{7})(\S.*)$/).map { |match| match.last.split.last } end |