-
Notifications
You must be signed in to change notification settings - Fork 145
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
Custom repo names #382
base: master
Are you sure you want to change the base?
Custom repo names #382
Changes from all commits
8b82896
6b6774d
551fc3f
e8246ab
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
[submodule "test/fixtures/test_git_repo"] | ||
path = test/fixtures/test_git_repo | ||
url = git://github.com/ooyala/barkeep_integration_tests.git | ||
[submodule "test/fixtures/base/test_git_repo"] | ||
path = test/fixtures/base/test_git_repo | ||
url = [email protected]:michaelstorm/barkeep_compound_name_integration_tests.git |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,27 +26,41 @@ def configure(logger, repos_root) | |
attr_reader :repos | ||
|
||
def initialize(repos_root) | ||
@repos_root = repos_root | ||
@repos_root = Pathname.new(repos_root).realdirpath.to_s | ||
Thread.abort_on_exception = true | ||
load_repos | ||
end | ||
|
||
# Loads in any new repos from the repos_root. | ||
def scan_for_new_repos() load_repos if repos_out_of_date? end | ||
|
||
def all_repo_names_recurse(path) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe you can find all .git folders using Dir.glob, and then you can just iterate over the matches, obviating the need for a recursive helper. |
||
if File.exist?("#{path}/.git") | ||
[Pathname.new(path).relative_path_from(Pathname.new(@repos_root)).to_s] | ||
else | ||
names = [] | ||
repo_paths = Dir.glob("#{path}/*/") | ||
repo_paths.each do |sub_path| | ||
names += all_repo_names_recurse(sub_path) | ||
end | ||
names | ||
end | ||
end | ||
|
||
def all_repo_names | ||
all_repo_names_recurse(@repos_root) | ||
end | ||
|
||
def load_repos | ||
@repos = [] | ||
@repo_names_and_ids_to_repos = {} | ||
@repo_name_to_id = {} | ||
|
||
repo_paths = Dir.glob("#{@repos_root}/*/") | ||
|
||
repo_paths.each do |path| | ||
path = Pathname.new(path).realpath.to_s # Canonical path | ||
name = File.basename(path) | ||
all_repo_names.each do |name| | ||
path = Pathname.new("#{@repos_root}/#{name}").realpath.to_s # Canonical path | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just curious, why |
||
id = GitRepo.find_or_create(:name => name, :path => path).id | ||
grit_repo = create_grit_repo_for_name(name) | ||
next unless grit_repo && grit_repo.has_refs? | ||
return unless grit_repo && grit_repo.has_refs? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why |
||
@repos << grit_repo | ||
@repo_name_to_id[name] = id | ||
@repo_names_and_ids_to_repos[name] = grit_repo | ||
|
@@ -70,7 +84,7 @@ def grit_commit(repo_name_or_id, sha) | |
grit_commit = grit_repo.commit(sha) | ||
return nil unless grit_commit | ||
|
||
grit_commit.repo_name = File.basename(grit_repo.working_dir) | ||
grit_commit.repo_name = Pathname.new(grit_repo.working_dir).relative_path_from(Pathname.new(@repos_root)).to_s | ||
grit_commit | ||
end | ||
|
||
|
@@ -353,8 +367,7 @@ def self.git_command_options(search_options) | |
private | ||
|
||
def repos_out_of_date? | ||
repo_names = Dir.glob("#{@repos_root}/*/").map { |path| File.basename(path) } | ||
Set.new(repo_names) != Set.new(@repos.map(&:name)) | ||
Set.new(all_repo_names) != Set.new(@repos.map(&:name)) | ||
end | ||
|
||
# Creates a new Grit::Repo object for the given path. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,14 +2,26 @@ window.Repos = | |
init: -> | ||
$("button#clone").click => | ||
repoUrl = $("#newRepoUrl").val() | ||
repoName = $("#newRepoName").val() | ||
$.ajax | ||
type: "post" | ||
url: "/admin/repos/create_new_repo" | ||
data: { url: repoUrl } | ||
data: { url: repoUrl, name: repoName } | ||
dataType: "json" | ||
success: => @showConfirmationMessage("#{repoUrl} has been scheduled to be cloned.") | ||
success: => @showConfirmationMessage("#{repoUrl} has been scheduled to be cloned as #{repoName}.") | ||
error: (response) => @showConfirmationMessage(response.responseText) | ||
|
||
$("#newRepoUrl").bind "propertychange keyup input paste", => | ||
repoUrl = $("#newRepoUrl").val() | ||
match = /.*(?:\/|:)([^/:]+)\/*$/.exec repoUrl | ||
if match | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change this to a circuit: |
||
name = match[1] | ||
name = (/\s*([^\s]+)/.exec name)[1] | ||
suffix_match = /(.*)\.git$/.exec name | ||
if suffix_match | ||
name = suffix_match[1] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Combine the if and its body into one line. |
||
$("#newRepoName").val(name) | ||
|
||
$(".trash").click (e) => | ||
repoRow = $(e.target).closest("tr") | ||
repoName = repoRow.find("td:nth-of-type(1)").html() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,38 +10,42 @@ class CloneNewRepoIntegrationTest < Scope::TestCase | |
include IntegrationTestHelper | ||
|
||
setup_once do | ||
@@test_repo_name = "clone_repo_integration_test" | ||
@@test_repo_names = ["clone_repo_integration_test", "base/clone_repo_integration_test"] | ||
@@bad_test_repo_names = ["bad_repo_integration_test", "bad_base/bad_repo_integration_test"] | ||
|
||
# We could also clone this repo from [email protected]:ooyala/barkeep_integration_tests.git, but that takes | ||
# about 5 seconds. Cloning from the local disk is much faster. | ||
@@test_repo_url = File.expand_path(File.join(File.dirname(__FILE__), "../fixtures/test_git_repo")) | ||
|
||
delete_repo(@@test_repo_name) | ||
@@test_repo_names.each { |repo_name| delete_repo(repo_name) } | ||
end | ||
|
||
teardown_once do | ||
delete_repo(@@test_repo_name) | ||
@@test_repo_names.each { |repo_name| delete_repo(repo_name) } | ||
end | ||
|
||
should "clone a new repo to the correct place on disk" do | ||
assert_equal false, File.exists?(repo_path(@@test_repo_name)) | ||
CloneNewRepo.perform(@@test_repo_name, @@test_repo_url) | ||
assert File.exists?(repo_path(@@test_repo_name)), "repo should've been cloned, but it's not on disk." | ||
|
||
# Ensure it successfully completed a full clone (i.e. commits can now be read by Grit). | ||
first_commit = "65a0045e7ac5329d76e6644aa2fb427b78100a7b" | ||
grit = Grit::Repo.new(repo_path(@@test_repo_name)) | ||
assert_equal 1, grit.commits(first_commit).size | ||
@@test_repo_names.each do |repo_name| | ||
assert_equal false, File.exists?(repo_path(repo_name)) | ||
CloneNewRepo.perform(repo_name, @@test_repo_url) | ||
assert File.exists?(repo_path(repo_name)), "repo should've been cloned, but it's not on disk." | ||
|
||
# Ensure it successfully completed a full clone (i.e. commits can now be read by Grit). | ||
first_commit = "65a0045e7ac5329d76e6644aa2fb427b78100a7b" | ||
grit = Grit::Repo.new(repo_path(repo_name)) | ||
assert_equal 1, grit.commits(first_commit).size | ||
end | ||
end | ||
|
||
should "if a repo cannot be cloned, no trace of it should be left on disk" do | ||
repo_name = "bad_repo_integration_test" | ||
FileUtils.rm_rf(repo_path(repo_name)) | ||
CloneNewRepo.perform(repo_name, "bad_repo/url") | ||
assert_equal false, File.exists?(repo_path(repo_name)) | ||
@@bad_test_repo_names.each do |repo_name| | ||
FileUtils.rm_rf(repo_path(repo_name)) | ||
CloneNewRepo.perform(repo_name, "bad_repo/url") | ||
assert_equal false, File.exists?(repo_path(repo_name)) | ||
end | ||
end | ||
|
||
def repo_path(repo_name) File.join(REPOS_ROOT, @@test_repo_name) end | ||
def repo_path(repo_name) File.join(REPOS_ROOT, repo_name) end | ||
def delete_repo(repo_name) | ||
FileUtils.rm_rf(repo_path(repo_name)) if File.exists?(repo_path(repo_name)) | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These magic vars are hard to read. Use Regexp.last_match instead.