public
Rubygem
Description: The official `github` command line helper for simplifying your GitHub experience.
Homepage: http://github.com
Clone URL: git://github.com/defunkt/github-gem.git
Search Repo:
Merge branch 'kballard/master'
defunkt (author)
Sun May 11 19:32:43 -0700 2008
commit  af8cfb367df0a76aec274c16af26936bcb9de1da
tree    c03f6c824e3961f8bf81f30a1da45cfe85a965b1
parent  a4452cb0f150a63e6c417dbabbc56fff8f59094c parent  bf1aaf6cca044b58bf74c2d7eaddb04764cb90dd
...
1
2
3
4
 
 
 
5
6
7
...
18
19
20
21
 
 
 
 
 
 
 
 
 
 
22
23
24
...
1
2
 
 
3
4
5
6
7
8
...
19
20
21
 
22
23
24
25
26
27
28
29
30
31
32
33
34
0
@@ -1,7 +1,8 @@
0
 GitHub.helper :user_and_repo_from do |url|
0
   case url
0
- when %r|^git://github\.com/(.*)$|: $1.split('/')
0
- when %r|^git@github\.com:(.*)$|: $1.split('/')
0
+ when %r|^git://github\.com/([^/]+/[^/]+)$|: $1.split('/')
0
+ when %r|^(?:ssh://)?(?:git@)?github\.com:([^/]+/[^/]+)$|: $1.split('/')
0
+ else ['', '']
0
   end
0
 end
0
 
0
@@ -18,7 +19,16 @@
0
 end
0
 
0
 GitHub.helper :project do
0
- repo_for(:origin).chomp('.git')
0
+ repo = repo_for(:origin)
0
+ if repo == ""
0
+ if url_for(:origin) == ""
0
+ STDERR.puts "Error: missing remote 'origin'"
0
+ else
0
+ STDERR.puts "Error: remote 'origin' is not a github URL"
0
+ end
0
+ exit 1
0
+ end
0
+ repo.chomp('.git')
0
 end
0
 
0
 GitHub.helper :url_for do |remote|
...
9
10
11
 
 
 
 
 
 
 
 
 
 
 
 
12
...
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
0
@@ -9,5 +9,17 @@
0
     @helper.should_receive(:url_for).with(:origin).and_return("git://github.com/user/project-awesome.git")
0
     @helper.project.should == "project-awesome"
0
   end
0
+
0
+ it "should exit due to missing origin" do
0
+ @helper.should_receive(:url_for).twice.with(:origin).and_return("")
0
+ STDERR.should_receive(:puts).with("Error: missing remote 'origin'")
0
+ lambda { @helper.project }.should raise_error(SystemExit)
0
+ end
0
+
0
+ it "should exit due to non-github origin" do
0
+ @helper.should_receive(:url_for).twice.with(:origin).and_return("home:path/to/repo.git")
0
+ STDERR.should_receive(:puts).with("Error: remote 'origin' is not a github URL")
0
+ lambda { @helper.project }.should raise_error(SystemExit)
0
+ end
0
 end
...
12
13
14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
...
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
0
@@ -12,5 +12,27 @@
0
   it "should parse a ssh-based url" do
0
     @helper.user_and_repo_from("git@github.com:mojombo/god.git").should == ["mojombo", "god.git"]
0
   end
0
+
0
+ it "should parse a non-standard ssh-based url" do
0
+ @helper.user_and_repo_from("ssh://git@github.com:mojombo/god.git").should == ["mojombo", "god.git"]
0
+ @helper.user_and_repo_from("github.com:mojombo/god.git").should == ["mojombo", "god.git"]
0
+ @helper.user_and_repo_from("ssh://github.com:mojombo/god.git").should == ["mojombo", "god.git"]
0
+ end
0
+
0
+ it "should return nothing for other urls" do
0
+ @helper.user_and_repo_from("home:path/to/repo.git").should == ['', '']
0
+ end
0
+
0
+ it "should return nothing for invalid git:// urls" do
0
+ @helper.user_and_repo_from("git://github.com/foo").should == ['', '']
0
+ end
0
+
0
+ it "should return nothing for invalid ssh-based urls" do
0
+ @helper.user_and_repo_from("git@github.com:kballard").should == ['', '']
0
+ @helper.user_and_repo_from("git@github.com:kballard/test/repo.git").should == ['', '']
0
+ @helper.user_and_repo_from("ssh://git@github.com:kballard").should == ['', '']
0
+ @helper.user_and_repo_from("github.com:kballard").should == ['', '']
0
+ @helper.user_and_repo_from("ssh://github.com:kballard").should == ['', '']
0
+ end
0
 end

Comments

    No one has commented yet.