From 4e9a9d0118c39d5fa2e64d160f66877e7039437e Mon Sep 17 00:00:00 2001 From: Paulie Pena Date: Sun, 4 Nov 2012 19:21:58 -0500 Subject: [PATCH 1/3] removed Dir.chdir calls --- lib/divergence/git_manager.rb | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/lib/divergence/git_manager.rb b/lib/divergence/git_manager.rb index 7291217..96c6f33 100644 --- a/lib/divergence/git_manager.rb +++ b/lib/divergence/git_manager.rb @@ -61,15 +61,13 @@ def current_branch end def is_branch?(branch) - Dir.chdir @git_path do - # This is fast, but only works on locally checked out branches - `git show-ref --verify --quiet 'refs/heads/#{branch}'` - return true if $?.exitstatus == 0 - - # This is slow and will only get called for remote branches. - result = `git ls-remote --heads origin 'refs/heads/#{branch}'` - return result.strip.length != 0 - end + # This is fast, but only works on locally checked out branches + `git --git-dir #{@git_path}/.git show-ref --verify --quiet 'refs/heads/#{branch}'` + return true if $?.exitstatus == 0 + + # This is slow and will only get called for remote branches. + result = `git --git-dir #{@git_path}/.git ls-remote --heads origin 'refs/heads/#{branch}'` + return result.strip.length != 0 end def pull(branch) @@ -106,17 +104,15 @@ def fetch end def git(cmd) - Dir.chdir @git_path do - @log.info "git #{cmd.to_s}" - out = `git #{cmd.to_s} 2>&1` + @log.info "git --work-tree #{@git_path} --git-dir #{@git_path}/.git #{cmd.to_s}" + out = `git --work-tree #{@git_path} --git-dir #{@git_path}/.git #{cmd.to_s} 2>&1` - if $?.exitstatus != 0 - Application.log.error "git #{cmd.to_s} failed" - Application.log.error out - end - - return out + if $?.exitstatus != 0 + Application.log.error "git --work-tree #{@git_path} --git-dir #{@git_path}/.git #{cmd.to_s} failed" + Application.log.error out end + + return out end end -end \ No newline at end of file +end From c66ebea2d1e5f3e500485537796a7a2252367cee Mon Sep 17 00:00:00 2001 From: Paulie Pena Date: Sun, 4 Nov 2012 19:27:12 -0500 Subject: [PATCH 2/3] escape line breaks between object and method for ruby 1.8 support --- lib/divergence/cache_manager.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/divergence/cache_manager.rb b/lib/divergence/cache_manager.rb index eda5fd9..8014c25 100644 --- a/lib/divergence/cache_manager.rb +++ b/lib/divergence/cache_manager.rb @@ -43,8 +43,8 @@ def prune_cache! branches = Dir.glob('*/') return if branches.nil? or branches.length <= @cache_num - branches - .sort_by {|f| File.mtime(f)}[@cache_num..-1] + branches \ + .sort_by {|f| File.mtime(f)}[@cache_num..-1] \ .each do|dir| FileUtils.rm_rf(dir) @cached_branches.delete(dir.gsub('/', '')) @@ -52,4 +52,4 @@ def prune_cache! end end end -end \ No newline at end of file +end From ce3066ff5c7deec8ae3a518e629f5f5e1695d0bd Mon Sep 17 00:00:00 2001 From: Paulie Pena Date: Sun, 4 Nov 2012 19:29:18 -0500 Subject: [PATCH 3/3] also rsync non-git hidden files, like .htaccess --- lib/divergence/cache_manager.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/divergence/cache_manager.rb b/lib/divergence/cache_manager.rb index 8014c25..0797585 100644 --- a/lib/divergence/cache_manager.rb +++ b/lib/divergence/cache_manager.rb @@ -28,7 +28,7 @@ def add(branch, src_path) end def sync(branch, src_path) - `rsync -a --delete #{src_path}/* #{path(branch)}` + `rsync -a --delete --exclude .git --exclude .gitignore #{src_path}/ #{path(branch)}` end def path(branch)