- Notifications
You must be signed in to change notification settings - Fork530
Make Git::URL.clone_to handle cloning to bare and mirror repos#577
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
+223 −148
Merged
Changes fromall commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
13 changes: 9 additions & 4 deletionslib/git/url.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
144 changes: 0 additions & 144 deletionstests/units/test_url.rb
This file was deleted.
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
114 changes: 114 additions & 0 deletionstests/units/test_url_clone_to.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| # frozen_string_literal: true | ||
| require 'test/unit' | ||
| require File.join(File.dirname(__dir__), 'test_helper') | ||
| # Tests Git::URL.clone_to | ||
| # | ||
| class TestURLCloneTo < Test::Unit::TestCase | ||
| def test_clone_to_full_repo | ||
| GIT_URLS.each do |url_data| | ||
| url = url_data[:url] | ||
| expected_path = url_data[:expected_path] | ||
| actual_path = Git::URL.clone_to(url) | ||
| assert_equal( | ||
| expected_path, actual_path, | ||
| "Failed to determine the clone path for URL '#{url}' correctly" | ||
| ) | ||
| end | ||
| end | ||
| def test_clone_to_bare_repo | ||
| GIT_URLS.each do |url_data| | ||
| url = url_data[:url] | ||
| expected_path = url_data[:expected_bare_path] | ||
| actual_path = Git::URL.clone_to(url, bare: true) | ||
| assert_equal( | ||
| expected_path, actual_path, | ||
| "Failed to determine the clone path for URL '#{url}' correctly" | ||
| ) | ||
| end | ||
| end | ||
| def test_clone_to_mirror_repo | ||
| GIT_URLS.each do |url_data| | ||
| url = url_data[:url] | ||
| # The expected_path is the same for bare and mirror repos | ||
| expected_path = url_data[:expected_bare_path] | ||
| actual_path = Git::URL.clone_to(url, mirror: true) | ||
| assert_equal( | ||
| expected_path, actual_path, | ||
| "Failed to determine the clone path for URL '#{url}' correctly" | ||
| ) | ||
| end | ||
| end | ||
| GIT_URLS = [ | ||
| { | ||
| url: 'https://github.com/org/repo', | ||
| expected_path: 'repo', | ||
| expected_bare_path: 'repo.git' | ||
| }, | ||
| { | ||
| url: 'https://github.com/org/repo.git', | ||
| expected_path: 'repo', | ||
| expected_bare_path: 'repo.git' | ||
| }, | ||
| { | ||
| url: 'https://git.mydomain.com/org/repo/.git', | ||
| expected_path: 'repo', | ||
| expected_bare_path: 'repo.git' | ||
| } | ||
| ].freeze | ||
| # Git::URL.clone_to makes some assumptions about how the `git` command names | ||
| # the directory to clone to. This test ensures that the assumptions are | ||
| # correct. | ||
| # | ||
| def test_git_clone_naming_assumptions | ||
| in_temp_dir do |_path| | ||
| setup_test_repositories | ||
| GIT_CLONE_COMMANDS.each do |command_data| | ||
| command = command_data[:command] | ||
| expected_path = command_data[:expected_path] | ||
| output = `#{command} 2>&1` | ||
| assert_match(/Cloning into (?:bare repository )?'#{expected_path}'/, output) | ||
| FileUtils.rm_rf(expected_path) | ||
| end | ||
| end | ||
| end | ||
| GIT_CLONE_COMMANDS = [ | ||
| # Clone to full repository | ||
| { command: 'git clone server/my_project', expected_path: 'my_project' }, | ||
| { command: 'git clone server/my_project/.git', expected_path: 'my_project' }, | ||
| { command: 'git clone server/my_project.git', expected_path: 'my_project' }, | ||
| # Clone to bare repository | ||
| { command: 'git clone --bare server/my_project', expected_path: 'my_project.git' }, | ||
| { command: 'git clone --bare server/my_project/.git', expected_path: 'my_project.git' }, | ||
| { command: 'git clone --bare server/my_project.git', expected_path: 'my_project.git' }, | ||
| # Clone to mirror repository | ||
| { command: 'git clone --mirror server/my_project', expected_path: 'my_project.git' }, | ||
| { command: 'git clone --mirror server/my_project/.git', expected_path: 'my_project.git' }, | ||
| { command: 'git clone --mirror server/my_project.git', expected_path: 'my_project.git' } | ||
| ].freeze | ||
| def setup_test_repositories | ||
| # Create a repository to clone from | ||
| Dir.mkdir 'server' | ||
| remote = Git.init('server/my_project') | ||
| Dir.chdir('server/my_project') do | ||
| new_file('README.md', '# My New Project') | ||
| remote.add | ||
| remote.commit('Initial version') | ||
| end | ||
| # Create a bare repository to clone from | ||
| Git.clone('server/my_project', 'server/my_project.git', bare: true) | ||
| end | ||
| end |
100 changes: 100 additions & 0 deletionstests/units/test_url_parse.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| # frozen_string_literal: true | ||
| require'test/unit' | ||
| # Tests Git::URL.parse | ||
| # | ||
| classTestURLParse <Test::Unit::TestCase | ||
| deftest_parse_with_invalid_url | ||
| url='user@host.xz:/path/to/repo.git/' | ||
| assert_raise(Addressable::URI::InvalidURIError)do | ||
| Git::URL.parse(url) | ||
| end | ||
| end | ||
| deftest_parse | ||
| GIT_URLS.eachdo |url_data| | ||
| url=url_data[:url] | ||
| expected_uri=url_data[:expected_uri] | ||
| actual_uri=Git::URL.parse(url).to_hash.delete_if{ |_key,value|value.nil?} | ||
| assert_equal(expected_uri,actual_uri,"Failed to parse URL '#{url}' correctly") | ||
| end | ||
| end | ||
| # For any URL, #to_s should return the url passed to Git::URL.parse(url) | ||
| deftest_to_s | ||
| GIT_URLS.eachdo |url_data| | ||
| url=url_data[:url] | ||
| to_s=Git::URL.parse(url).to_s | ||
| assert_equal(url,to_s,"Parsed URI#to_s does not return the original URL '#{url}' correctly") | ||
| end | ||
| end | ||
| GIT_URLS=[ | ||
| { | ||
| url:'ssh://host.xz/path/to/repo.git/', | ||
| expected_uri:{scheme:'ssh',host:'host.xz',path:'/path/to/repo.git/'} | ||
| }, | ||
| { | ||
| url:'ssh://host.xz:4443/path/to/repo.git/', | ||
| expected_uri:{scheme:'ssh',host:'host.xz',port:4443,path:'/path/to/repo.git/'} | ||
| }, | ||
| { | ||
| url:'ssh:///path/to/repo.git/', | ||
| expected_uri:{scheme:'ssh',host:'',path:'/path/to/repo.git/'} | ||
| }, | ||
| { | ||
| url:'user@host.xz:path/to/repo.git/', | ||
| expected_uri:{scheme:'git-alt',user:'user',host:'host.xz',path:'/path/to/repo.git/'} | ||
| }, | ||
| { | ||
| url:'host.xz:path/to/repo.git/', | ||
| expected_uri:{scheme:'git-alt',host:'host.xz',path:'/path/to/repo.git/'} | ||
| }, | ||
| { | ||
| url:'git://host.xz:4443/path/to/repo.git/', | ||
| expected_uri:{scheme:'git',host:'host.xz',port:4443,path:'/path/to/repo.git/'} | ||
| }, | ||
| { | ||
| url:'git://user@host.xz:4443/path/to/repo.git/', | ||
| expected_uri:{scheme:'git',user:'user',host:'host.xz',port:4443,path:'/path/to/repo.git/'} | ||
| }, | ||
| { | ||
| url:'https://host.xz/path/to/repo.git/', | ||
| expected_uri:{scheme:'https',host:'host.xz',path:'/path/to/repo.git/'} | ||
| }, | ||
| { | ||
| url:'https://host.xz:4443/path/to/repo.git/', | ||
| expected_uri:{scheme:'https',host:'host.xz',port:4443,path:'/path/to/repo.git/'} | ||
| }, | ||
| { | ||
| url:'ftps://host.xz:4443/path/to/repo.git/', | ||
| expected_uri:{scheme:'ftps',host:'host.xz',port:4443,path:'/path/to/repo.git/'} | ||
| }, | ||
| { | ||
| url:'ftps://host.xz:4443/path/to/repo.git/', | ||
| expected_uri:{scheme:'ftps',host:'host.xz',port:4443,path:'/path/to/repo.git/'} | ||
| }, | ||
| { | ||
| url:'file:./relative-path/to/repo.git/', | ||
| expected_uri:{scheme:'file',path:'./relative-path/to/repo.git/'} | ||
| }, | ||
| { | ||
| url:'file:///path/to/repo.git/', | ||
| expected_uri:{scheme:'file',host:'',path:'/path/to/repo.git/'} | ||
| }, | ||
| { | ||
| url:'file:///path/to/repo.git', | ||
| expected_uri:{scheme:'file',host:'',path:'/path/to/repo.git'} | ||
| }, | ||
| { | ||
| url:'file://host.xz/path/to/repo.git', | ||
| expected_uri:{scheme:'file',host:'host.xz',path:'/path/to/repo.git'} | ||
| }, | ||
| {url:'/path/to/repo.git/',expected_uri:{path:'/path/to/repo.git/'}}, | ||
| {url:'/path/to/bare-repo/.git',expected_uri:{path:'/path/to/bare-repo/.git'}}, | ||
| {url:'relative-path/to/repo.git/',expected_uri:{path:'relative-path/to/repo.git/'}}, | ||
| {url:'./relative-path/to/repo.git/',expected_uri:{path:'./relative-path/to/repo.git/'}}, | ||
| {url:'../ruby-git/.git',expected_uri:{path:'../ruby-git/.git'}} | ||
| ].freeze | ||
| end |
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.