Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pulls For Issues 8, 10, 11 #13

Merged
merged 4 commits into from
Nov 5, 2012
Merged
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
8 changes: 4 additions & 4 deletions lib/divergence/cache_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -43,13 +43,13 @@ 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('/', ''))
end
end
end
end
end
end
34 changes: 15 additions & 19 deletions lib/divergence/git_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
end