From 0d4685b067ced771d07525b461c3f170a5adc34f Mon Sep 17 00:00:00 2001 From: LightGuard Date: Mon, 4 Nov 2013 15:42:01 -0700 Subject: [PATCH] Initial commit for issue #77 fix --- helpers/repository.rb | 23 ++++++++++++++++++++++- public_app.rb | 9 +++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/helpers/repository.rb b/helpers/repository.rb index b7a3253..07476d6 100644 --- a/helpers/repository.rb +++ b/helpers/repository.rb @@ -179,6 +179,11 @@ def create_branch(branch_name) system("git checkout -b #{branch_name} upstream/#{upstream_repo.master_branch}") end + def switch_branch(branch_name) + @git_repo.checkout branch_name, {:force => true} + [200, ''] + end + def rebase(overwrite, remote = 'upstream') fetch_remote remote upstream_repo = create_github_client.repository(Octokit::Repository.from_url @settings['repo']) @@ -206,7 +211,23 @@ def remove_branch(branch_name) end def branches - @git_repo.branches + @logger.debug "Fetching local branches and notes" + Open3.popen3('git show --format="||%d||%h||%N" --notes=pull $(git notes --ref=pull | awk "{ print $2 }") | awk "{ if ($1 ~ /\|\|/) { print $0 } }', + :chdir => File.absolute_path(base_repository_path)) do |_, stdout, stderr, wait_thr| + exit_value = wait_thr.value + @logger.debug "fetch exit status: #{exit_value}" + error = stderr.readlines.join "\n" + @logger.debug "fetch error: #{error}" unless error.empty? + + returns = [] + stdout.readlines.each do |line| + _, branches, pull = line.split '||' + branches = branches.strip.gsub(/[()]/, '').split(',').last.strip + returns << {:pull => pull, :branch => branches} + end + + returns + end end def push(remote = 'origin') diff --git a/public_app.rb b/public_app.rb index 2319a2b..156c636 100644 --- a/public_app.rb +++ b/public_app.rb @@ -226,6 +226,15 @@ class PublicApp < Sinatra::Base [200, JSON.dump(json_return)] end + get '/repo/:repo_name/branches' do |repo_name| + repo = create_repo(repo_name) + [200, JSON.dump(repo.branches)] + end + + post '/repo/:repo_name/branches/:branch_name' do |repo_name, branch_name| + repo = create_repo(repo_name).switch_branch branch_name + end + get '/repo/:repo_name/*' do |repo_name, path| repo = create_repo(repo_name) json_return = { :content => repo.file_content(path), :links => links_for_file(repo.file_info(path), repo_name) }