Skip to content

Commit 70091b0

Browse files
committed
Fix hub am for Enterprise URLs
Still won't work for Enterprise gists, but this makes it work for pull request & commit URLs. Fixes mislav#584
1 parent bb45222 commit 70091b0

File tree

2 files changed

+39
-6
lines changed

2 files changed

+39
-6
lines changed

features/am.feature

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
Feature: hub am
2+
Scenario: Enterprise repo
3+
Given I am in "git://git.my.org/mislav/dotfiles.git" git repo
4+
And I am "mislav" on git.my.org with OAuth token "FITOKEN"
5+
And "git.my.org" is a whitelisted Enterprise host
6+
Given the GitHub API server:
7+
"""
8+
get('/api/v3/repos/mislav/dotfiles/pulls/387') {
9+
halt 400 unless request.env['HTTP_ACCEPT'] == 'application/vnd.github.v3.patch'
10+
<<PATCH
11+
From 7eb75a26ee8e402aad79fcf36a4c1461e3ec2592 Mon Sep 17 00:00:00 2001
12+
From: Mislav <[email protected]>
13+
Date: Tue, 24 Jun 2014 11:07:05 -0700
14+
Subject: [PATCH] Create a README
15+
---
16+
diff --git a/README.md b/README.md
17+
new file mode 100644
18+
index 0000000..ce01362
19+
--- /dev/null
20+
+++ b/README.md
21+
+hello
22+
--
23+
1.9.3
24+
PATCH
25+
}
26+
"""
27+
When I successfully run `hub am -q -3 https://git.my.org/mislav/dotfiles/pull/387`
28+
And I successfully run `git log -1 --format=%s`
29+
Then the output should contain exactly "Create a README\n"

lib/hub/commands.rb

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -498,15 +498,19 @@ def cherry_pick(args)
498498
# ... downloads patch via API ...
499499
# > git am /tmp/55.patch
500500
def am(args)
501-
if url = args.find { |a| a =~ %r{^https?://(gist\.)?github\.com/} }
502-
idx = args.index(url)
503-
if $1 == 'gist.'
504-
path_parts = $'.sub(/#.*/, '').split('/')
505-
gist_id = path_parts.last
501+
gh_url = nil
502+
idx = args.index { |arg|
503+
gh_url = if arg =~ %r{^https?://gist\.github\.com/} then URI(arg)
504+
else resolve_github_url(arg)
505+
end
506+
}
507+
508+
if gh_url
509+
if "gist.github.com" == gh_url.host
510+
gist_id = gh_url.path.split('/').last
506511
patch_name = "gist-#{gist_id}.txt"
507512
patch = api_client.gist_raw(gist_id)
508513
else
509-
gh_url = resolve_github_url(url)
510514
case gh_url.project_path
511515
when /^pull\/(\d+)/
512516
pull_id = $1.to_i

0 commit comments

Comments
 (0)