Module: Vtasks::Utils::Git
- Included in:
- Docker::Image, Docker::Image::Build, Puppet, Release
- Defined in:
- lib/vtasks/utils/git.rb
Overview
Git module
Constant Summary collapse
- GITHUB_TOKEN =
ENV['GITHUB_TOKEN']
Instance Method Summary collapse
-
#git_branch ⇒ Object
Get the branch name.
-
#git_ci_status(branch = 'master') ⇒ Object
Get the CI Status (needs hub.github.com/).
-
#git_clean_repo ⇒ Object
Check if the repo is clean.
-
#git_commit ⇒ Object
Get git short commit hash.
-
#git_deepen_repo ⇒ Object
Deepen repository history In case there is a shallow clone (only the tip of the specified branch).
-
#git_url ⇒ Object
Get the URL of the origin remote.
Instance Method Details
#git_branch ⇒ Object
Get the branch name
13 14 15 16 17 18 |
# File 'lib/vtasks/utils/git.rb', line 13 def git_branch return ENV['GIT_BRANCH'] if ENV['GIT_BRANCH'] return ENV['TRAVIS_BRANCH'] if ENV['TRAVIS_BRANCH'] return ENV['CIRCLE_BRANCH'] if ENV['CIRCLE_BRANCH'] `git symbolic-ref HEAD --short 2>/dev/null`.strip end |
#git_ci_status(branch = 'master') ⇒ Object
Get the CI Status (needs hub.github.com/)
26 27 28 |
# File 'lib/vtasks/utils/git.rb', line 26 def git_ci_status(branch = 'master') `hub ci-status #{branch}`.strip end |
#git_clean_repo ⇒ Object
Check if the repo is clean
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/vtasks/utils/git.rb', line 31 def git_clean_repo # Check if there are uncommitted changes unless system 'git diff --quiet HEAD' abort('ERROR: Commit your changes first.') end # Check if there are untracked files unless `git ls-files --others --exclude-standard`.to_s.empty? abort('ERROR: There are untracked files.') end true end |
#git_commit ⇒ Object
Get git short commit hash
8 9 10 |
# File 'lib/vtasks/utils/git.rb', line 8 def git_commit `git rev-parse --short HEAD`.strip end |
#git_deepen_repo ⇒ Object
Deepen repository history In case there is a shallow clone (only the tip of the specified branch). This has the advantage of minimizing the amount of data transfer necessary from the repository and speeding up the build because it pulls only the minimal code necessary. Because of this, if you need to perform a custom action that relies on a different branch, you won’t be able to checkout that branch, unless you do one of the following:
$ git pull --depth=50
$ git fetch --unshallow origin
50 51 52 53 54 55 56 |
# File 'lib/vtasks/utils/git.rb', line 50 def git_deepen_repo git_dir = `git rev-parse --git-dir`.strip if File.file?("#{git_dir}/shallow") info 'Deepen repository history' sh "git fetch --unshallow origin" end end |
#git_url ⇒ Object
Get the URL of the origin remote
21 22 23 |
# File 'lib/vtasks/utils/git.rb', line 21 def git_url `git config --get remote.origin.url`.strip end |