From 9d7ee5ccf541961dfe0a1d1cd613db01e3032b90 Mon Sep 17 00:00:00 2001 From: Hari Karam Singh Date: Mon, 1 Jul 2013 18:07:49 +0100 Subject: [PATCH 1/2] Adds shellescape to paths in shell commands to accomodate spaces and other dodgy characters --- lib/giternal/repository.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/giternal/repository.rb b/lib/giternal/repository.rb index 7d226a8..870446d 100644 --- a/lib/giternal/repository.rb +++ b/lib/giternal/repository.rb @@ -1,4 +1,5 @@ require 'fileutils' +require 'optparse/shellwords' module Giternal class Repository @@ -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 @@ -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} && git add -f #{rel_repo_path.shellescape}` true end @@ -50,7 +51,7 @@ 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 From 9f1b5bf9f8e22b037c47c7738064bcc8663f69b0 Mon Sep 17 00:00:00 2001 From: Hari Karam Singh Date: Mon, 1 Jul 2013 18:42:30 +0100 Subject: [PATCH 2/2] Adds 'status' command and 'thaw' alias --- bin/giternal | 2 +- lib/giternal/app.rb | 53 +++++++++++++++++--------------------- lib/giternal/repository.rb | 6 ++++- 3 files changed, 29 insertions(+), 32 deletions(-) diff --git a/bin/giternal b/bin/giternal index a6a24a9..ed5651c 100755 --- a/bin/giternal +++ b/bin/giternal @@ -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 "" diff --git a/lib/giternal/app.rb b/lib/giternal/app.rb index f50b212..5780c3e 100644 --- a/lib/giternal/app.rb +++ b/lib/giternal/app.rb @@ -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 @@ -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 diff --git a/lib/giternal/repository.rb b/lib/giternal/repository.rb index 870446d..cbf7a40 100644 --- a/lib/giternal/repository.rb +++ b/lib/giternal/repository.rb @@ -40,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.shellescape}` + `cd #{@base_dir.shellescape} && git add -f #{rel_repo_path.shellescape}` true end @@ -55,6 +55,10 @@ def unfreezify 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