Improve detecting of origin remote and remote branch
In hub lingo, "origin remote" is the remote pointing to the canonical
GitHub project, i.e. where pull requests should be sent. "Remote branch"
is where hub guesses the user has pushed their changes from the current
local branch.
The origin remote can now be called "upstream", "github", or "origin",
in that order of precedence.
The `browse`, `compare`, and especially `pull-request` commands need to
know the remote branch. Previously we relied on git upstream
configuration, but that wasn't enough. This behavior is now only kept if
git "push.default" is set to "upstream" or "tracking".
For "push.default" values "current", "simple" (git 2.0 default), or
"matching" (git 1.x default), we can safely assume that the user
probably pushes to the same-named branches on some remote, and we ignore
upstream configuration.
To find the remote where the user pushed their changes, we search for
the same-named branch on:
1. the remote which points to a GitHub project owned by the current user;
2. "origin", "github", and "upstream" remotes.
When a match is found, it is assumed that the user pushed there and it
is taken as the implicit pull-request head.
Fixes #158, fixes #360, fixes #381
2013-12-21 20:24:33 +04:00
|
|
|
Feature: hub compare
|
2013-01-21 16:45:10 +04:00
|
|
|
Background:
|
|
|
|
Given I am in "git://github.com/mislav/dotfiles.git" git repo
|
Improve detecting of origin remote and remote branch
In hub lingo, "origin remote" is the remote pointing to the canonical
GitHub project, i.e. where pull requests should be sent. "Remote branch"
is where hub guesses the user has pushed their changes from the current
local branch.
The origin remote can now be called "upstream", "github", or "origin",
in that order of precedence.
The `browse`, `compare`, and especially `pull-request` commands need to
know the remote branch. Previously we relied on git upstream
configuration, but that wasn't enough. This behavior is now only kept if
git "push.default" is set to "upstream" or "tracking".
For "push.default" values "current", "simple" (git 2.0 default), or
"matching" (git 1.x default), we can safely assume that the user
probably pushes to the same-named branches on some remote, and we ignore
upstream configuration.
To find the remote where the user pushed their changes, we search for
the same-named branch on:
1. the remote which points to a GitHub project owned by the current user;
2. "origin", "github", and "upstream" remotes.
When a match is found, it is assumed that the user pushed there and it
is taken as the implicit pull-request head.
Fixes #158, fixes #360, fixes #381
2013-12-21 20:24:33 +04:00
|
|
|
And I am "mislav" on github.com with OAuth token "OTOKEN"
|
2013-01-21 16:45:10 +04:00
|
|
|
|
|
|
|
Scenario: Compare branch
|
|
|
|
When I successfully run `hub compare refactor`
|
|
|
|
Then there should be no output
|
|
|
|
And "open https://github.com/mislav/dotfiles/compare/refactor" should be run
|
|
|
|
|
2014-01-19 06:58:29 +04:00
|
|
|
Scenario: Compare complex branch
|
|
|
|
When I successfully run `hub compare feature/foo`
|
|
|
|
Then there should be no output
|
2014-07-11 19:17:35 +04:00
|
|
|
And "open https://github.com/mislav/dotfiles/compare/feature/foo" should be run
|
2014-01-19 06:58:29 +04:00
|
|
|
|
2014-12-25 07:20:28 +03:00
|
|
|
Scenario: Compare branch with funky characters
|
|
|
|
When I successfully run `hub compare 'my#branch!with.special+chars'`
|
|
|
|
Then there should be no output
|
|
|
|
And "open https://github.com/mislav/dotfiles/compare/my%23branch!with.special%2Bchars" should be run
|
|
|
|
|
2013-01-21 16:45:10 +04:00
|
|
|
Scenario: No args, no upstream
|
|
|
|
When I run `hub compare`
|
|
|
|
Then the exit status should be 1
|
|
|
|
And the stderr should contain:
|
|
|
|
"""
|
2015-09-26 20:39:32 +03:00
|
|
|
Usage: hub compare [-u] [-b <BASE>] [<USER>] [[<START>...]<END>]
|
2013-01-21 16:45:10 +04:00
|
|
|
"""
|
|
|
|
|
2013-07-18 01:36:25 +04:00
|
|
|
Scenario: Can't compare default branch to self
|
|
|
|
Given the default branch for "origin" is "develop"
|
|
|
|
And I am on the "develop" branch with upstream "origin/develop"
|
|
|
|
When I run `hub compare`
|
|
|
|
Then the exit status should be 1
|
|
|
|
And the stderr should contain:
|
|
|
|
"""
|
2015-09-26 20:39:32 +03:00
|
|
|
Usage: hub compare [-u] [-b <BASE>] [<USER>] [[<START>...]<END>]
|
2013-07-18 01:36:25 +04:00
|
|
|
"""
|
|
|
|
|
2013-01-21 16:45:10 +04:00
|
|
|
Scenario: No args, has upstream branch
|
|
|
|
Given I am on the "feature" branch with upstream "origin/experimental"
|
Improve detecting of origin remote and remote branch
In hub lingo, "origin remote" is the remote pointing to the canonical
GitHub project, i.e. where pull requests should be sent. "Remote branch"
is where hub guesses the user has pushed their changes from the current
local branch.
The origin remote can now be called "upstream", "github", or "origin",
in that order of precedence.
The `browse`, `compare`, and especially `pull-request` commands need to
know the remote branch. Previously we relied on git upstream
configuration, but that wasn't enough. This behavior is now only kept if
git "push.default" is set to "upstream" or "tracking".
For "push.default" values "current", "simple" (git 2.0 default), or
"matching" (git 1.x default), we can safely assume that the user
probably pushes to the same-named branches on some remote, and we ignore
upstream configuration.
To find the remote where the user pushed their changes, we search for
the same-named branch on:
1. the remote which points to a GitHub project owned by the current user;
2. "origin", "github", and "upstream" remotes.
When a match is found, it is assumed that the user pushed there and it
is taken as the implicit pull-request head.
Fixes #158, fixes #360, fixes #381
2013-12-21 20:24:33 +04:00
|
|
|
And git "push.default" is set to "upstream"
|
2013-01-21 16:45:10 +04:00
|
|
|
When I successfully run `hub compare`
|
|
|
|
Then there should be no output
|
|
|
|
And "open https://github.com/mislav/dotfiles/compare/experimental" should be run
|
|
|
|
|
2014-12-25 07:20:28 +03:00
|
|
|
Scenario: Current branch has funky characters
|
|
|
|
Given I am on the "feature" branch with upstream "origin/my#branch!with.special+chars"
|
|
|
|
And git "push.default" is set to "upstream"
|
|
|
|
When I successfully run `hub compare`
|
|
|
|
Then there should be no output
|
|
|
|
And "open https://github.com/mislav/dotfiles/compare/my%23branch!with.special%2Bchars" should be run
|
|
|
|
|
2013-01-21 16:45:10 +04:00
|
|
|
Scenario: Compare range
|
|
|
|
When I successfully run `hub compare 1.0...fix`
|
|
|
|
Then there should be no output
|
|
|
|
And "open https://github.com/mislav/dotfiles/compare/1.0...fix" should be run
|
|
|
|
|
|
|
|
Scenario: Output URL without opening the browser
|
|
|
|
When I successfully run `hub compare -u 1.0...fix`
|
|
|
|
Then "open https://github.com/mislav/dotfiles/compare/1.0...fix" should not be run
|
|
|
|
And the stdout should contain exactly:
|
|
|
|
"""
|
|
|
|
https://github.com/mislav/dotfiles/compare/1.0...fix\n
|
|
|
|
"""
|
|
|
|
|
2015-06-28 06:58:35 +03:00
|
|
|
Scenario: Compare base in branch that is not master
|
|
|
|
Given I am on the "feature" branch with upstream "origin/experimental"
|
|
|
|
And git "push.default" is set to "upstream"
|
|
|
|
When I successfully run `hub compare -b master`
|
|
|
|
Then there should be no output
|
|
|
|
And "open https://github.com/mislav/dotfiles/compare/master...experimental" should be run
|
|
|
|
|
|
|
|
Scenario: Compare base in master branch
|
|
|
|
Given I am on the "master" branch with upstream "origin/master"
|
|
|
|
And git "push.default" is set to "upstream"
|
|
|
|
When I successfully run `hub compare -b experimental`
|
|
|
|
Then there should be no output
|
|
|
|
And "open https://github.com/mislav/dotfiles/compare/experimental...master" should be run
|
|
|
|
|
|
|
|
Scenario: Compare base with same branch as the current branch
|
|
|
|
Given I am on the "feature" branch with upstream "origin/experimental"
|
|
|
|
And git "push.default" is set to "upstream"
|
|
|
|
When I run `hub compare -b experimental`
|
|
|
|
Then "open https://github.com/mislav/dotfiles/compare/experimental...experimental" should not be run
|
|
|
|
And the exit status should be 1
|
|
|
|
And the stderr should contain:
|
|
|
|
"""
|
2015-09-26 20:39:32 +03:00
|
|
|
Usage: hub compare [-u] [-b <BASE>] [<USER>] [[<START>...]<END>]
|
2015-06-28 06:58:35 +03:00
|
|
|
"""
|
|
|
|
|
|
|
|
Scenario: Compare base with parameters
|
|
|
|
Given I am on the "master" branch with upstream "origin/master"
|
|
|
|
When I run `hub compare -b master experimental..master`
|
|
|
|
Then "open https://github.com/mislav/dotfiles/compare/experimental...master" should not be run
|
|
|
|
And the exit status should be 1
|
|
|
|
And the stderr should contain:
|
|
|
|
"""
|
2015-09-26 20:39:32 +03:00
|
|
|
Usage: hub compare [-u] [-b <BASE>] [<USER>] [[<START>...]<END>]
|
2015-06-28 06:58:35 +03:00
|
|
|
"""
|
|
|
|
|
2013-01-21 16:45:10 +04:00
|
|
|
Scenario: Compare 2-dots range for tags
|
|
|
|
When I successfully run `hub compare 1.0..fix`
|
|
|
|
Then there should be no output
|
|
|
|
And "open https://github.com/mislav/dotfiles/compare/1.0...fix" should be run
|
|
|
|
|
|
|
|
Scenario: Compare 2-dots range for SHAs
|
|
|
|
When I successfully run `hub compare 1234abc..3456cde`
|
|
|
|
Then there should be no output
|
|
|
|
And "open https://github.com/mislav/dotfiles/compare/1234abc...3456cde" should be run
|
|
|
|
|
2013-01-21 16:53:43 +04:00
|
|
|
Scenario: Compare 2-dots range with "user:repo" notation
|
|
|
|
When I successfully run `hub compare henrahmagix:master..2b10927`
|
|
|
|
Then there should be no output
|
|
|
|
And "open https://github.com/mislav/dotfiles/compare/henrahmagix:master...2b10927" should be run
|
|
|
|
|
2013-01-21 16:45:10 +04:00
|
|
|
Scenario: Complex range is unchanged
|
|
|
|
When I successfully run `hub compare @{a..b}..@{c..d}`
|
|
|
|
Then there should be no output
|
|
|
|
And "open https://github.com/mislav/dotfiles/compare/@{a..b}..@{c..d}" should be run
|
|
|
|
|
|
|
|
Scenario: Compare wiki
|
|
|
|
Given the "origin" remote has url "git://github.com/mislav/dotfiles.wiki.git"
|
|
|
|
When I successfully run `hub compare 1.0..fix`
|
|
|
|
Then there should be no output
|
|
|
|
And "open https://github.com/mislav/dotfiles/wiki/_compare/1.0...fix" should be run
|
|
|
|
|
|
|
|
Scenario: Compare fork
|
|
|
|
When I successfully run `hub compare anotheruser feature`
|
|
|
|
Then there should be no output
|
|
|
|
And "open https://github.com/anotheruser/dotfiles/compare/feature" should be run
|
2014-02-16 06:56:56 +04:00
|
|
|
|
|
|
|
Scenario: Enterprise repo over HTTP
|
|
|
|
Given the "origin" remote has url "git://git.my.org/mislav/dotfiles.git"
|
|
|
|
And I am "mislav" on http://git.my.org with OAuth token "FITOKEN"
|
|
|
|
And "git.my.org" is a whitelisted Enterprise host
|
|
|
|
When I successfully run `hub compare refactor`
|
|
|
|
Then there should be no output
|
|
|
|
And "open http://git.my.org/mislav/dotfiles/compare/refactor" should be run
|
2015-09-28 17:22:34 +03:00
|
|
|
|
2018-06-14 16:06:08 +03:00
|
|
|
Scenario: Enterprise repo with explicit upstream project
|
|
|
|
Given the "origin" remote has url "git://git.my.org/mislav/dotfiles.git"
|
|
|
|
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 compare fehmicansaglam a..b`
|
|
|
|
Then there should be no output
|
|
|
|
And "open https://git.my.org/fehmicansaglam/dotfiles/compare/a...b" should be run
|
|
|
|
|
2015-09-28 17:22:34 +03:00
|
|
|
Scenario: Compare in non-GitHub repo
|
|
|
|
Given the "origin" remote has url "git@bitbucket.org:mislav/dotfiles.git"
|
|
|
|
And I am on the "feature" branch
|
|
|
|
When I run `hub compare`
|
|
|
|
Then the stdout should contain exactly ""
|
|
|
|
And the stderr should contain exactly:
|
|
|
|
"""
|
|
|
|
Aborted: the origin remote doesn't point to a GitHub repository.\n
|
|
|
|
"""
|
|
|
|
And the exit status should be 1
|
2018-10-14 20:14:30 +03:00
|
|
|
|
|
|
|
Scenario: Comparing two branches while not on a local branch
|
|
|
|
Given I am in detached HEAD
|
|
|
|
And I run `hub compare refactor...master`
|
|
|
|
Then the exit status should be 0
|
|
|
|
And there should be no output
|
|
|
|
And "open https://github.com/mislav/dotfiles/compare/refactor...master" should be run
|