Skip to content
This repository was archived by the owner on May 11, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/giternal
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ end
require 'giternal'

action = ARGV[0]
available_actions = %w(update freeze unfreeze)
available_actions = %w(update freeze unfreeze thaw status)
unless available_actions.include?(action)
puts "Usage: giternal (#{available_actions.join(':')})"
puts ""
Expand Down
53 changes: 23 additions & 30 deletions lib/giternal/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,38 +16,17 @@ def update(*dirs)
end
end

def freezify(*dirs)
if dirs.empty?
config.each_repo {|r| r.freezify }
else
dirs.each do |dir|
if repo = config.find_repo(dir)
repo.freezify
end
end
end
end

def unfreezify(*dirs)
if dirs.empty?
config.each_repo {|r| r.unfreezify }
else
dirs.each do |dir|
if repo = config.find_repo(dir)
repo.unfreezify
end
end
end
end

def run(action, *args)
case action
when "freeze"
freezify(*args)
when "unfreeze"
unfreezify(*args)
else
send(action, *args)
when "freeze"
_do_repo_action('freezify', *args)
when "unfreeze", "thaw"
_do_repo_action('unfreezify', *args)
when "status"
puts "Frozen?"
_do_repo_action('show_status', *args)
else
send(action, *args)
end
end

Expand All @@ -65,5 +44,19 @@ def config

@config = YamlConfig.new(@base_dir, File.read(config_file))
end



def _do_repo_action(action, *dirs)
if dirs.empty?
config.each_repo {|r| r.send(action)}
else
dirs.each do |dir|
if repo = config.find_repo(dir)
repo.send(action)
end
end
end
end
end
end
13 changes: 9 additions & 4 deletions lib/giternal/repository.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'fileutils'
require 'optparse/shellwords'

module Giternal
class Repository
Expand All @@ -24,10 +25,10 @@ def update
if !File.exist?(repo_path + '/.git')
raise "Directory '#{@name}' exists but is not a git repository"
else
update_output { `cd #{repo_path} && git pull 2>&1` }
update_output { `cd #{repo_path.shellescape} && git pull 2>&1` }
end
else
update_output { `cd #{checkout_path} && git clone #{@repo_url} #{@name}` }
update_output { `cd #{checkout_path.shellescape} && git clone #{@repo_url} #{@name}` }
end
true
end
Expand All @@ -39,7 +40,7 @@ def freezify
`tar czf .git.frozen.tgz .git`
FileUtils.rm_r('.git')
end
`cd #{@base_dir} && git add -f #{rel_repo_path}`
`cd #{@base_dir.shellescape} && git add -f #{rel_repo_path.shellescape}`
true
end

Expand All @@ -50,10 +51,14 @@ def unfreezify
`tar xzf .git.frozen.tgz`
FileUtils.rm('.git.frozen.tgz')
end
`cd #{@base_dir} && git rm -r --cached #{rel_repo_path}`
`cd #{@base_dir.shellescape} && git rm -r --cached #{rel_repo_path.shellescape}`
true
end

def show_status
puts "#{@name}: " + (if frozen? then 'YES' else 'NO' end)
end

def frozen?
File.exist?(repo_path + '/.git.frozen.tgz')
end
Expand Down