summaryrefslogtreecommitdiff
path: root/lib/leap_cli/util.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/leap_cli/util.rb')
-rw-r--r--lib/leap_cli/util.rb24
1 files changed, 23 insertions, 1 deletions
diff --git a/lib/leap_cli/util.rb b/lib/leap_cli/util.rb
index 5bab424..155796f 100644
--- a/lib/leap_cli/util.rb
+++ b/lib/leap_cli/util.rb
@@ -74,7 +74,7 @@ module LeapCli
#
def assert_run!(cmd, message=nil)
cmd = cmd + " 2>&1"
- output = `#{cmd}`
+ output = `#{cmd}`.strip
unless $?.success?
exit_status($?.exitstatus)
bail! do
@@ -363,6 +363,28 @@ module LeapCli
ERB.new(string, nil, '%<>-').result(binding)
end
+ ##
+ ## GIT
+ ##
+
+ def is_git_directory?(dir)
+ Dir.chdir(dir) do
+ `which git && git rev-parse 2>/dev/null`
+ return $? == 0
+ end
+ end
+
+ def current_git_branch(dir)
+ Dir.chdir(dir) do
+ branch = `git symbolic-ref HEAD 2>/dev/null`.strip
+ if branch.chars.any?
+ branch.sub /^refs\/heads\//, ''
+ else
+ nil
+ end
+ end
+ end
+
end
end