lib/origen/revision_control/git.rb in origen-0.0.4 vs lib/origen/revision_control/git.rb in origen-0.0.5
- old
+ new
@@ -1,10 +1,10 @@
module Origen
module RevisionControl
class Git < Base
- def build
- if Dir["#{local}/*"].empty?
+ def build(options = {})
+ if Dir["#{local}/*"].empty? || options[:force]
FileUtils.rm_rf(local.to_s)
# Not using the regular 'git' method here since the local dir doesn't exist to CD into
system "git clone #{remote} #{local}"
else
fail "The requested workspace is not empty: #{local}"
@@ -72,11 +72,15 @@
# Then proceed with checking them in as latest
else
checkout unless options[:initial]
end
cmd = 'add'
- cmd += ' -u' unless options[:unmanaged]
+ if options[:unmanaged]
+ cmd += ' -A'
+ else
+ cmd += ' -u' unless options[:unmanaged]
+ end
cmd += " #{paths.join(' ')}"
git cmd, options
if changes_pending_commit?
cmd = 'commit'
if options[:comment] && !options[:comment].strip.empty?
@@ -99,10 +103,19 @@
end
git "push origin #{current_branch}" unless options[:local]
paths
end
+ # Returns true if the current user can checkin to the given repo (means has permission
+ # to push in Git terms)
+ def can_checkin?
+ git('push --dry-run', verbose: false)
+ true
+ rescue
+ false
+ end
+
def changes(dir = nil, options = {})
paths, options = clean_path(dir, options)
options = {
verbose: false
}.merge(options)
@@ -174,12 +187,29 @@
git('fetch', verbose: false) unless @all_tags_fetched
@all_tags_fetched = true
git('tag', verbose: false).include?(tag.to_s)
end
+ def initialized?
+ File.exist?("#{local}/.git") &&
+ git('remote -v', verbose: false).any? { |r| r =~ /#{remote_without_protocol}/ } &&
+ !git('status', verbose: false).any? { |l| l == 'Initial commit' }
+ end
+
+ # Delete everything in the given directory, or the whole repo
+ def delete_all(dir = nil, options = {})
+ paths, options = clean_path(dir, options)
+ files = git("ls-files #{paths.first}")
+ FileUtils.rm_f files
+ end
+
private
+ def remote_without_protocol
+ Pathname.new(remote.sub(/^.*:\/\//, ''))
+ end
+
def create_gitignore
c = Origen::Generator::Compiler.new
c.compile "#{Origen.top}/templates/git/gitignore.erb",
output_directory: local,
quiet: true,
@@ -200,13 +230,9 @@
unless initialized?
Origen.log.debug "Initializing Git workspace at #{local}"
git 'init'
git "remote add origin #{remote}"
end
- end
-
- def initialized?
- File.exist?("#{local}/.git")
end
# Execute a git operation, the resultant output is returned in an array
def git(command, options = {})
options = {