提交 c9378ca8 编写于 作者: M Mislav Marohnić

Merge pull request #600 from github/cukes-master

Port latest batch of cukes from master to gh
......@@ -61,6 +61,7 @@ func apply(command *Command, args *Args) {
func transformApplyArgs(args *Args) {
urlRegexp := regexp.MustCompile("^https?://(gist\\.)github\\.com/")
pullRegexp := regexp.MustCompile("^(pull|commit)/([0-9a-f]+)")
for _, arg := range args.Params {
var (
url string
......@@ -68,8 +69,7 @@ func transformApplyArgs(args *Args) {
)
projectURL, err := github.ParseURL(arg)
if err == nil {
pullRegexp := regexp.MustCompile("/(pull|commit)/([0-9a-f]+)")
match := pullRegexp.FindStringSubmatch(projectURL.Path)
match := pullRegexp.FindStringSubmatch(projectURL.ProjectPath())
if match != nil {
url = projectURL.Project.WebURL("", "", match[1]+"/"+match[2])
}
......
......@@ -12,7 +12,7 @@ import (
var cmdBrowse = &Command{
Run: browse,
GitExtension: true,
Usage: "browse [-u] [[<USER>/]<REPOSITORY>] [SUBPAGE]",
Usage: "browse [-u] [[<USER>/]<REPOSITORY>|--] [SUBPAGE]",
Short: "Open a GitHub page in the default browser",
Long: `Open repository's GitHub page in the system's default web browser using
"open(1)" or the "BROWSER" env variable. If the repository isn't
......
......@@ -48,8 +48,9 @@ func transformCherryPickArgs(args *Args) {
if project != nil {
args.ReplaceParam(args.IndexOfParam(ref), sha)
if hasGitRemote(project.Owner) {
args.Before("git", "fetch", project.Owner)
remote := gitRemoteForProject(project)
if remote != nil {
args.Before("git", "fetch", remote.Name)
} else {
args.Before("git", "remote", "add", "-f", project.Owner, project.GitURL("", "", false))
}
......@@ -69,14 +70,14 @@ func parseCherryPickProjectAndSha(ref string) (project *github.Project, sha stri
}
}
ownerWithShaRegexp := regexp.MustCompile("^(%s)@([a-f0-9]{7,40})$")
ownerWithShaRegexp := regexp.MustCompile("^([a-zA-Z0-9][a-zA-Z0-9-]*)@([a-f0-9]{7,40})$")
if ownerWithShaRegexp.MatchString(ref) {
matches := ownerWithShaRegexp.FindStringSubmatch(ref)
sha = matches[2]
localRepo, err := github.LocalRepo()
utils.Check(err)
project, err := localRepo.CurrentProject()
project, err = localRepo.CurrentProject()
utils.Check(err)
project.Owner = matches[1]
}
......
......@@ -51,16 +51,18 @@ func parseUserBranchFromPR(pullRequest *octokit.PullRequest) (user string, branc
return
}
func hasGitRemote(name string) bool {
func gitRemoteForProject(project *github.Project) (foundRemote *github.Remote) {
remotes, err := github.Remotes()
utils.Check(err)
for _, remote := range remotes {
if remote.Name == name {
return true
remoteProject, pErr := remote.Project()
if pErr == nil && remoteProject.SameAs(project) {
foundRemote = &remote
return
}
}
return false
return nil
}
func isEmptyDir(path string) bool {
......
Feature: hub am
Background:
Given I am in "git://github.com/mislav/dotfiles.git" git repo
And I am "mislav" on github.com with OAuth token "OTOKEN"
Scenario: Apply a local patch
When I run `hub am some.patch`
Then the git command should be unchanged
Scenario: Apply commits from pull request
Given the GitHub API server:
"""
get('/repos/mislav/dotfiles/pulls/387') {
halt 400 unless request.env['HTTP_ACCEPT'] == 'application/vnd.github.v3.patch'
generate_patch "Create a README"
}
"""
When I successfully run `hub am -q -3 https://github.com/mislav/dotfiles/pull/387`
Then there should be no output
Then the latest commit message should be "Create a README"
Scenario: Apply commits when TMPDIR is empty
Given $TMPDIR is ""
Given the GitHub API server:
"""
get('/repos/mislav/dotfiles/pulls/387') {
halt 400 unless request.env['HTTP_ACCEPT'] == 'application/vnd.github.v3.patch'
generate_patch "Create a README"
}
"""
When I successfully run `hub am -q https://github.com/mislav/dotfiles/pull/387`
Then the latest commit message should be "Create a README"
Scenario: Enterprise repo
Given I am in "git://git.my.org/mislav/dotfiles.git" git repo
And I am "mislav" on git.my.org with OAuth token "FITOKEN"
......@@ -7,23 +39,37 @@ Feature: hub am
"""
get('/api/v3/repos/mislav/dotfiles/pulls/387') {
halt 400 unless request.env['HTTP_ACCEPT'] == 'application/vnd.github.v3.patch'
<<PATCH
From 7eb75a26ee8e402aad79fcf36a4c1461e3ec2592 Mon Sep 17 00:00:00 2001
From: Mislav <mislav.marohnic@gmail.com>
Date: Tue, 24 Jun 2014 11:07:05 -0700
Subject: [PATCH] Create a README
---
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..ce01362
--- /dev/null
+++ b/README.md
+hello
--
1.9.3
PATCH
generate_patch "Create a README"
}
"""
When I successfully run `hub am -q -3 https://git.my.org/mislav/dotfiles/pull/387`
And I successfully run `git log -1 --format=%s`
Then the output should contain exactly "Create a README\n"
Then the latest commit message should be "Create a README"
Scenario: Apply patch from commit
Given the GitHub API server:
"""
get('/repos/davidbalbert/dotfiles/commits/fdb9921') {
halt 400 unless request.env['HTTP_ACCEPT'] == 'application/vnd.github.v3.patch'
generate_patch "Create a README"
}
"""
When I successfully run `hub am -q https://github.com/davidbalbert/dotfiles/commit/fdb9921`
Then the latest commit message should be "Create a README"
Scenario: Apply patch from gist
Given the GitHub API server:
"""
get('/gists/8da7fb575debd88c54cf', :host_name => 'api.github.com') {
json :files => {
'file.diff' => {
:raw_url => "https://gist.github.com/raw/8da7fb575debd88c54cf/SHA/file.diff"
}
}
}
get('/raw/8da7fb575debd88c54cf/SHA/file.diff', :host_name => 'gist.github.com') {
halt 400 unless request.env['HTTP_ACCEPT'] == 'text/plain'
generate_patch "Create a README"
}
"""
When I successfully run `hub am -q https://gist.github.com/8da7fb575debd88c54cf`
Then the latest commit message should be "Create a README"
Feature: hub apply
Background:
Given I am in "git://github.com/mislav/dotfiles.git" git repo
And I am "mislav" on github.com with OAuth token "OTOKEN"
And I make a commit
Scenario: Apply a local patch
When I run `hub apply some.patch`
Then the git command should be unchanged
And the file "README.md" should not exist
Scenario: Apply commits from pull request
Given the GitHub API server:
"""
get('/repos/mislav/dotfiles/pulls/387') {
halt 400 unless request.env['HTTP_ACCEPT'] == 'application/vnd.github.v3.patch'
generate_patch "Create a README"
}
"""
When I successfully run `hub apply -3 https://github.com/mislav/dotfiles/pull/387`
Then there should be no output
Then a file named "README.md" should exist
Scenario: Apply commits when TMPDIR is empty
Given $TMPDIR is ""
Given the GitHub API server:
"""
get('/repos/mislav/dotfiles/pulls/387') {
halt 400 unless request.env['HTTP_ACCEPT'] == 'application/vnd.github.v3.patch'
generate_patch "Create a README"
}
"""
When I successfully run `hub apply https://github.com/mislav/dotfiles/pull/387`
Then a file named "README.md" should exist
Scenario: Enterprise repo
Given I am in "git://git.my.org/mislav/dotfiles.git" git repo
And I am "mislav" on git.my.org with OAuth token "FITOKEN"
And "git.my.org" is a whitelisted Enterprise host
Given the GitHub API server:
"""
get('/api/v3/repos/mislav/dotfiles/pulls/387') {
halt 400 unless request.env['HTTP_ACCEPT'] == 'application/vnd.github.v3.patch'
generate_patch "Create a README"
}
"""
When I successfully run `hub apply https://git.my.org/mislav/dotfiles/pull/387`
Then a file named "README.md" should exist
Scenario: Apply patch from commit
Given the GitHub API server:
"""
get('/repos/davidbalbert/dotfiles/commits/fdb9921') {
halt 400 unless request.env['HTTP_ACCEPT'] == 'application/vnd.github.v3.patch'
generate_patch "Create a README"
}
"""
When I successfully run `hub apply https://github.com/davidbalbert/dotfiles/commit/fdb9921`
Then a file named "README.md" should exist
Scenario: Apply patch from gist
Given the GitHub API server:
"""
get('/gists/8da7fb575debd88c54cf', :host_name => 'api.github.com') {
json :files => {
'file.diff' => {
:raw_url => "https://gist.github.com/raw/8da7fb575debd88c54cf/SHA/file.diff"
}
}
}
get('/raw/8da7fb575debd88c54cf/SHA/file.diff', :host_name => 'gist.github.com') {
halt 400 unless request.env['HTTP_ACCEPT'] == 'text/plain'
generate_patch "Create a README"
}
"""
When I successfully run `hub apply https://gist.github.com/8da7fb575debd88c54cf`
Then a file named "README.md" should exist
......@@ -2,6 +2,11 @@ Feature: hub browse
Background:
Given I am "mislav" on github.com with OAuth token "OTOKEN"
Scenario: No repo
When I run `hub browse`
Then the exit status should be 1
Then the output should contain exactly "git browse [-u] [[<USER>/]<REPOSITORY>|--] [SUBPAGE]\n"
Scenario: Project with owner
When I successfully run `hub browse mislav/dotfiles`
Then there should be no output
......@@ -105,7 +110,7 @@ Feature: hub browse
And I am on the "feature" branch pushed to "mislav/feature"
When I successfully run `hub browse -- issues`
Then there should be no output
# Then "open https://github.com/jashkenas/coffee-script/issues" should be run
Then "open https://github.com/jashkenas/coffee-script/issues" should be run
Scenario: Forward Slash Delimited branch
Given I am in "git://github.com/mislav/dotfiles.git" git repo
......@@ -167,3 +172,24 @@ Feature: hub browse
And "git.my.org" is a whitelisted Enterprise host
When I successfully run `hub browse`
Then "open http://git.my.org/mislav/dotfiles" should be run
Scenario: SSH alias
Given the SSH config:
"""
Host gh
User git
HostName github.com
"""
Given I am in "gh:singingwolfboy/sekrit.git" git repo
When I successfully run `hub browse`
Then "open https://github.com/singingwolfboy/sekrit" should be run
Scenario: SSH GitHub alias
Given the SSH config:
"""
Host github.com
HostName ssh.github.com
"""
Given I am in "git@github.com:suan/git-sanity.git" git repo
When I successfully run `hub browse`
Then "open https://github.com/suan/git-sanity" should be run
Feature: hub cherry-pick
Background:
Given I am in "git://github.com/rtomayko/ronn.git" git repo
And I am "mislav" on github.com with OAuth token "OTOKEN"
Scenario: Unchanged
When I run `hub cherry-pick a319d88`
Then the git command should be unchanged
Scenario: From GitHub commit URL
When I run `hub cherry-pick https://github.com/rtomayko/ronn/commit/a319d88#comments`
Then "git fetch origin" should be run
And "git cherry-pick a319d88" should be run
Scenario: From fork that has existing remote
Given the "mislav" remote has url "git@github.com:mislav/ronn.git"
When I run `hub cherry-pick https://github.com/mislav/ronn/commit/a319d88`
Then "git fetch mislav" should be run
And "git cherry-pick a319d88" should be run
Scenario: Using GitHub owner@SHA notation
Given the "mislav" remote has url "git@github.com:mislav/ronn.git"
When I run `hub cherry-pick mislav@a319d88`
Then "git fetch mislav" should be run
And "git cherry-pick a319d88" should be run
Scenario: Using GitHub owner@SHA notation that is too short
When I run `hub cherry-pick mislav@a319`
Then the git command should be unchanged
Scenario: Unsupported GitHub owner/repo@SHA notation
When I run `hub cherry-pick mislav/ronn@a319d88`
Then the git command should be unchanged
Scenario: Skips processing if `-m/--mainline` is specified
When I run `hub cherry-pick -m 42 mislav@a319d88`
Then the git command should be unchanged
When I run `hub cherry-pick --mainline 42 mislav@a319d88`
Then the git command should be unchanged
Scenario: Using GitHub owner@SHA notation with remote add
When I run `hub cherry-pick mislav@a319d88`
Then "git remote add -f mislav git://github.com/mislav/ronn.git" should be run
And "git cherry-pick a319d88" should be run
Scenario: From fork that doesn't have a remote
When I run `hub cherry-pick https://github.com/jingweno/ronn/commit/a319d88`
Then "git remote add -f jingweno git://github.com/jingweno/ronn.git" should be run
And "git cherry-pick a319d88" should be run
Feature: hub init
Background:
Given I am "mislav" on github.com with OAuth token "OTOKEN"
Given a directory named "dotfiles"
When I cd to "dotfiles"
Scenario: Initializes a git repo with remote
When I successfully run `hub init -g`
Then the url for "origin" should be "git@github.com:mislav/dotfiles.git"
Scenario: Enterprise host
Given $GITHUB_HOST is "git.my.org"
And I am "mislav" on git.my.org with OAuth token "FITOKEN"
And "git.my.org" is a whitelisted Enterprise host
When I successfully run `hub init -g`
Then the url for "origin" should be "git@git.my.org:mislav/dotfiles.git"
......@@ -429,7 +429,25 @@ Feature: hub pull-request
And "git.my.org" is a whitelisted Enterprise host
Given the GitHub API server:
"""
post('/api/v3/repos/mislav/coral/pulls') {
post('/api/v3/repos/mislav/coral/pulls', :host_name => 'git.my.org') {
assert :base => 'master',
:head => 'mislav:master'
json :html_url => "the://url"
}
"""
When I successfully run `hub pull-request -m enterprisey`
Then the output should contain exactly "the://url\n"
Scenario: Enterprise remote witch matching branch but no tracking
Given the "origin" remote has url "git@git.my.org:mislav/coral.git"
And I am "mislav" on git.my.org with OAuth token "FITOKEN"
And "git.my.org" is a whitelisted Enterprise host
And I am on the "feature" branch pushed to "origin/feature"
Given the GitHub API server:
"""
post('/api/v3/repos/mislav/coral/pulls', :host_name => 'git.my.org') {
assert :base => 'master',
:head => 'mislav:feature'
json :html_url => "the://url"
}
"""
......@@ -492,3 +510,17 @@ Feature: hub pull-request
"""
When I successfully run `hub pull-request -o -m hereyougo`
Then "open the://url" should be run
Scenario: Current branch is tracking local branch
Given git "push.default" is set to "upstream"
And I am on the "feature" branch with upstream "refs/heads/master"
Given the GitHub API server:
"""
post('/repos/mislav/coral/pulls') {
assert :base => 'master',
:head => 'mislav:feature'
json :html_url => "the://url"
}
"""
When I successfully run `hub pull-request -m hereyougo`
Then the output should contain exactly "the://url\n"
Feature: hub push
Background:
Given I am in "git://github.com/mislav/coral.git" git repo
Scenario: Normal push
When I successfully run `hub push`
Then the git command should be unchanged
Scenario: Push current branch to multiple remotes
Given I am on the "cool-feature" branch
When I successfully run `hub push origin,staging`
Then "git push origin cool-feature" should be run
Then "git push staging cool-feature" should be run
Scenario: Push explicit branch to multiple remotes
When I successfully run `hub push origin,staging,qa cool-feature`
Then "git push origin cool-feature" should be run
Then "git push staging cool-feature" should be run
Then "git push qa cool-feature" should be run
Scenario: Push multiple refs to multiple remotes
When I successfully run `hub push origin,staging master new-feature`
Then "git push origin master new-feature" should be run
Then "git push staging master new-feature" should be run
......@@ -42,7 +42,7 @@ Given(/^\$(\w+) is "([^"]*)"$/) do |name, value|
end
Given(/^I am in "([^"]*)" git repo$/) do |dir_name|
if dir_name.include? '://'
if dir_name.include?(':')
origin_url = dir_name
dir_name = File.basename origin_url, '.git'
end
......@@ -70,6 +70,11 @@ When(/^I make (a|\d+) commits?(?: with message "([^"]+)")?$/) do |num, msg|
num.times { empty_commit(msg) }
end
Then(/^the latest commit message should be "([^"]+)"$/) do |subject|
step %(I successfully run `git log -1 --format=%s`)
step %(the output should contain exactly "#{subject}\\n")
end
Given(/^the "([^"]+)" branch is pushed to "([^"]+)"$/) do |name, upstream|
full_upstream = ".git/refs/remotes/#{upstream}"
in_current_dir do
......@@ -81,11 +86,15 @@ end
Given(/^I am on the "([^"]+)" branch(?: (pushed to|with upstream) "([^"]+)")?$/) do |name, type, upstream|
empty_commit
if upstream
full_upstream = ".git/refs/remotes/#{upstream}"
if upstream =~ /^refs\//
full_upstream = ".git/#{upstream}"
else
full_upstream = ".git/refs/remotes/#{upstream}"
end
in_current_dir do
FileUtils.mkdir_p File.dirname(full_upstream)
FileUtils.cp '.git/refs/heads/master', full_upstream
end
end unless upstream == 'refs/heads/master'
end
track = type == 'pushed to' ? '--no-track' : '--track'
run_silent %(git checkout --quiet -B #{name} #{track} #{upstream})
......@@ -239,3 +248,9 @@ end
Given(/^the git commit editor is "([^"]+)"$/) do |cmd|
set_env('GIT_EDITOR', cmd)
end
Given(/^the SSH config:$/) do |config_lines|
ssh_config = "#{ENV['HOME']}/.ssh/config"
FileUtils.mkdir_p(File.dirname(ssh_config))
File.open(ssh_config, 'w') {|f| f << config_lines }
end
......@@ -4,7 +4,7 @@ set -e
url="$3"
file="$5"
if [ "${url%.patch}" = "$url" ]; then
if [ "${url%.patch}" = "$url" ] && [ "${url%.txt}" = "$url" ]; then
echo "invalid pull request URL: $url" >&2
exit 1
fi
......
......@@ -92,6 +92,24 @@ module Hub
)
end
end
def generate_patch(subject)
<<PATCH
From 7eb75a26ee8e402aad79fcf36a4c1461e3ec2592 Mon Sep 17 00:00:00 2001
From: Mislav <mislav.marohnic@gmail.com>
Date: Tue, 24 Jun 2014 11:07:05 -0700
Subject: [PATCH] #{subject}
---
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..ce01362
--- /dev/null
+++ b/README.md
+hello
--
1.9.3
PATCH
end
end
new(klass.new).start
......
package git
import (
"fmt"
"bufio"
"net/url"
"os"
"path/filepath"
"regexp"
"strings"
)
var (
ProtocolRe = regexp.MustCompile("^[a-zA-Z_-]+://")
SshConfigFiles = []string{
filepath.Join(os.Getenv("HOME"), ".ssh/config"),
"/etc/ssh_config",
"/etc/ssh/ssh_config",
}
SshConfig map[string]string
)
func ParseURL(rawurl string) (u *url.URL, err error) {
sshGitRegexp := regexp.MustCompile(`(.+)@(.+):(.+)(\.git)?`)
if sshGitRegexp.MatchString(rawurl) {
match := sshGitRegexp.FindStringSubmatch(rawurl)
user := match[1]
host := match[2]
path := match[3]
ext := match[4]
rawurl = fmt.Sprintf("ssh://%s@%s/%s%s", user, host, path, ext)
if !ProtocolRe.MatchString(rawurl) && strings.Contains(rawurl, ":") {
rawurl = "ssh://" + strings.Replace(rawurl, ":", "/", 1)
}
u, err = url.Parse(rawurl)
if err == nil {
if SshConfig == nil {
SshConfig = readSshConfig()
}
if SshConfig[u.Host] != "" {
u.Host = SshConfig[u.Host]
}
}
return
}
func readSshConfig() map[string]string {
config := make(map[string]string)
hostRe := regexp.MustCompile("^[ \t]*(Host|HostName)[ \t]+(.+)$")
for _, filename := range SshConfigFiles {
file, err := os.Open(filename)
if err != nil {
continue
}
hosts := []string{"*"}
scanner := bufio.NewScanner(file)
for scanner.Scan() {
line := scanner.Text()
match := hostRe.FindStringSubmatch(line)
if match == nil {
continue
}
names := strings.Fields(match[2])
if match[1] == "Host" {
hosts = names
} else {
for _, host := range hosts {
for _, name := range names {
config[host] = name
}
}
}
}
file.Close()
}
return url.Parse(rawurl)
return config
}
package github
import (
"fmt"
"os"
"strings"
......@@ -27,7 +26,7 @@ func (h GitHubHosts) Include(host string) bool {
func knownGitHubHosts() (hosts GitHubHosts) {
defaultHost := DefaultGitHubHost()
hosts = append(hosts, defaultHost)
hosts = append(hosts, fmt.Sprintf("ssh.%s", defaultHost))
hosts = append(hosts, "ssh." + GitHubHost)
ghHosts, _ := git.Config("hub.host")
for _, ghHost := range strings.Split(ghHosts, "\n") {
......
......@@ -23,6 +23,10 @@ func (p Project) String() string {
return fmt.Sprintf("%s/%s", p.Owner, p.Name)
}
func (p *Project) SameAs(other *Project) bool {
return p.Owner == other.Owner && p.Name == other.Name && p.Host == other.Host
}
func (p *Project) WebURL(name, owner, path string) string {
if owner == "" {
owner = p.Owner
......@@ -139,6 +143,9 @@ func newProject(owner, name, host, protocol string) *Project {
if host == "" {
host = DefaultGitHubHost()
}
if host == "ssh.github.com" {
host = "github.com"
}
if protocol != "http" && protocol != "https" {
protocol = ""
......
......@@ -690,7 +690,7 @@ module Hub
elsif subpage && !%w[commits tree blob settings].include?(subpage)
branch = master_branch
project = local_repo.main_project
else
elsif local_repo(false)
# $ hub browse
prefer_upstream = current_branch && current_branch.master?
branch, project = remote_branch_and_project(method(:github_user), prefer_upstream)
......
......@@ -116,239 +116,6 @@ class HubTest < Minitest::Test
WebMock.reset!
end
def test_cherry_pick
assert_forwarded "cherry-pick a319d88"
end
def test_cherry_pick_url
url = 'http://github.com/mislav/hub/commit/a319d88'
assert_commands "git fetch mislav", "git cherry-pick a319d88", "cherry-pick #{url}"
end
def test_cherry_pick_url_with_fragment
url = 'http://github.com/mislav/hub/commit/abcdef0123456789#comments'
assert_commands "git fetch mislav", "git cherry-pick abcdef0123456789", "cherry-pick #{url}"
end
def test_cherry_pick_url_with_remote_add
url = 'https://github.com/xoebus/hub/commit/a319d88'
assert_commands "git remote add -f xoebus git://github.com/xoebus/hub.git",
"git cherry-pick a319d88",
"cherry-pick #{url}"
end
def test_cherry_pick_origin_url
url = 'https://github.com/defunkt/hub/commit/a319d88'
assert_commands "git fetch origin", "git cherry-pick a319d88", "cherry-pick #{url}"
end
def test_cherry_pick_github_user_notation
assert_commands "git fetch mislav", "git cherry-pick 368af20", "cherry-pick mislav@368af20"
end
def test_cherry_pick_github_user_repo_notation
# not supported
assert_forwarded "cherry-pick mislav/hubbub@a319d88"
end
def test_cherry_pick_github_notation_too_short
assert_forwarded "cherry-pick mislav@a319"
end
def test_cherry_pick_github_notation_with_remote_add
assert_commands "git remote add -f xoebus git://github.com/xoebus/hub.git",
"git cherry-pick a319d88",
"cherry-pick xoebus@a319d88"
end
def test_am_untouched
assert_forwarded "am some.patch"
end
def test_am_pull_request
stub_request(:get, "https://api.github.com/repos/defunkt/hub/pulls/55").
with(:headers => {'Accept'=>'application/vnd.github.v3.patch', 'Authorization'=>'token OTOKEN'}).
to_return(:status => 200)
with_tmpdir('/tmp/') do
assert_commands %r{git am --signoff /tmp/55\.patch[\w-]+ -p2},
"am --signoff https://github.com/defunkt/hub/pull/55#comment_123 -p2"
cmd = Hub("am https://github.com/defunkt/hub/pull/55/files").command
assert_includes '/tmp/55.patch', cmd
end
end
def test_am_no_tmpdir
stub_request(:get, "https://api.github.com/repos/defunkt/hub/pulls/55").
to_return(:status => 200)
with_tmpdir(nil) do
cmd = Hub("am https://github.com/defunkt/hub/pull/55").command
assert_includes '/tmp/55.patch', cmd
end
end
def test_am_commit_url
stub_request(:get, "https://api.github.com/repos/davidbalbert/hub/commits/fdb9921").
with(:headers => {'Accept'=>'application/vnd.github.v3.patch', 'Authorization'=>'token OTOKEN'}).
to_return(:status => 200)
with_tmpdir('/tmp/') do
url = 'https://github.com/davidbalbert/hub/commit/fdb9921'
assert_commands %r{git am --signoff /tmp/fdb9921\.patch[\w-]+ -p2},
"am --signoff #{url} -p2"
end
end
def test_am_gist
stub_request(:get, "https://api.github.com/gists/8da7fb575debd88c54cf").
with(:headers => {'Authorization'=>'token OTOKEN'}).
to_return(:body => Hub::JSON.generate(:files => {
'file.diff' => {
:raw_url => "https://gist.github.com/raw/8da7fb575debd88c54cf/SHA/file.diff"
}
}))
stub_request(:get, "https://gist.github.com/raw/8da7fb575debd88c54cf/SHA/file.diff").
with(:headers => {'Accept'=>'text/plain'}).
to_return(:status => 200)
with_tmpdir('/tmp/') do
url = 'https://gist.github.com/8da7fb575debd88c54cf'
assert_commands %r{git am --signoff /tmp/gist-8da7fb575debd88c54cf\.txt[\w-]+ -p2},
"am --signoff #{url} -p2"
end
end
def test_apply_untouched
assert_forwarded "apply some.patch"
end
def test_apply_pull_request
stub_request(:get, "https://api.github.com/repos/defunkt/hub/pulls/55").
to_return(:status => 200)
with_tmpdir('/tmp/') do
assert_commands %r{git apply /tmp/55\.patch[\w-]+ -p2},
"apply https://github.com/defunkt/hub/pull/55 -p2"
cmd = Hub("apply https://github.com/defunkt/hub/pull/55/files").command
assert_includes '/tmp/55.patch', cmd
end
end
def test_apply_commit_url
stub_request(:get, "https://api.github.com/repos/davidbalbert/hub/commits/fdb9921").
to_return(:status => 200)
with_tmpdir('/tmp/') do
url = 'https://github.com/davidbalbert/hub/commit/fdb9921'
assert_commands %r{git apply /tmp/fdb9921\.patch[\w-]+ -p2},
"apply #{url} -p2"
end
end
def test_apply_gist
stub_request(:get, "https://api.github.com/gists/8da7fb575debd88c54cf").
with(:headers => {'Authorization'=>'token OTOKEN'}).
to_return(:body => Hub::JSON.generate(:files => {
'file.diff' => {
:raw_url => "https://gist.github.com/raw/8da7fb575debd88c54cf/SHA/file.diff"
}
}))
stub_request(:get, "https://gist.github.com/raw/8da7fb575debd88c54cf/SHA/file.diff").
to_return(:status => 200)
with_tmpdir('/tmp/') do
url = 'https://gist.github.com/mislav/8da7fb575debd88c54cf'
assert_commands %r{git apply /tmp/gist-8da7fb575debd88c54cf\.txt[\w-]+ -p2},
"apply #{url} -p2"
end
end
def test_init
stub_no_remotes
stub_no_git_repo
assert_commands "git init", "git remote add origin git@github.com:tpw/hub.git", "init -g"
end
def test_init_enterprise
stub_no_remotes
stub_no_git_repo
edit_hub_config do |data|
data['git.my.org'] = [{'user'=>'myfiname'}]
end
with_host_env('git.my.org') do
assert_commands "git init", "git remote add origin git@git.my.org:myfiname/hub.git", "init -g"
end
end
def test_push_untouched
assert_forwarded "push"
end
def test_push_two
assert_commands "git push origin cool-feature", "git push staging cool-feature",
"push origin,staging cool-feature"
end
def test_push_current_branch
stub_branch('refs/heads/cool-feature')
assert_commands "git push origin cool-feature", "git push staging cool-feature",
"push origin,staging"
end
def test_push_more
assert_commands "git push origin cool-feature",
"git push staging cool-feature",
"git push qa cool-feature",
"push origin,staging,qa cool-feature"
end
def test_push_multiple_refs
assert_commands "git push origin master new-feature",
"git push staging master new-feature",
"push origin,staging master new-feature"
end
def test_pullrequest_from_branch_tracking_local
stub_config_value 'push.default', 'upstream'
stub_branch('refs/heads/feature')
stub_tracking('feature', 'refs/heads/master')
stub_request(:post, "https://api.github.com/repos/defunkt/hub/pulls").
with(:body => {'base' => "master", 'head' => "defunkt:feature", 'title' => "hereyougo" }).
to_return(:body => mock_pullreq_response(1))
expected = "https://github.com/defunkt/hub/pull/1\n"
assert_output expected, "pull-request -m hereyougo -f"
end
def test_pullrequest_enterprise_no_tracking
stub_hub_host('git.my.org')
stub_repo_url('git@git.my.org:defunkt/hub.git')
stub_branch('refs/heads/feature')
stub_remote_branch('origin/feature')
stub_tracking_nothing('feature')
stub_command_output "rev-list --cherry-pick --right-only --no-merges origin/feature...", nil
edit_hub_config do |data|
data['git.my.org'] = [{'user'=>'myfiname', 'oauth_token' => 'FITOKEN'}]
end
stub_request(:post, "https://git.my.org/api/v3/repos/defunkt/hub/pulls").
with(:body => {'base' => "master", 'head' => "defunkt:feature", 'title' => "hereyougo" }).
to_return(:body => mock_pullreq_response(1, 'api/v3/defunkt/hub', 'git.my.org'))
expected = "https://git.my.org/api/v3/defunkt/hub/pull/1\n"
assert_output expected, "pull-request -m hereyougo -f"
end
def test_pullrequest_alias
out = hub('e-note')
assert_equal hub('pull-request'), out
......@@ -423,25 +190,6 @@ class HubTest < Minitest::Test
assert_includes 'This file is generated code', hub("hub standalone")
end
def test_hub_browse_no_repo
stub_repo_url(nil)
assert_equal "Usage: hub browse [<USER>/]<REPOSITORY>\n", hub("browse")
end
def test_hub_browse_ssh_alias
with_ssh_config "Host gh\n User git\n HostName github.com" do
stub_repo_url "gh:singingwolfboy/sekrit.git"
assert_command "browse", "open https://github.com/singingwolfboy/sekrit"
end
end
def test_hub_browse_ssh_github_alias
with_ssh_config "Host github.com\n HostName ssh.github.com" do
stub_repo_url "git@github.com:suan/git-sanity.git"
assert_command "browse", "open https://github.com/suan/git-sanity"
end
end
def test_custom_browser
with_browser_env("custom") do
assert_browser("custom")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册