mislav / hub

A command-line tool that makes git easier to use with GitHub.
https://hub.github.com/
MIT License
22.84k stars 2.2k forks source link

Provide the name of the remote for the user's fork, the name of the user #2055

Open lacostej opened 5 years ago

lacostej commented 5 years ago

TL;DR: There doesn't seem to be a way to know the name of the remote of my current fork. I would need it to automate pushing commits.

Background: people have different conventions when naming upstream/fork their remote repositories. Common examples: upstream/origin, origin/$USER etc.

I am writing scripts to be used by a team, and those scripts use git and hub to automate the creation of some branches and pull-requests.

The workflow is similar to the one found in the default documentation:

git checkout -b $mybranch
git commit -am "My automated commit"
git push $userremote
hub pull-request -m $msg

My issue is that given that people name their userremote differently I either have to parametrize it, or fetch it, which can be achieved using the following ruby code:

def hub_fork_remote_name
  require 'YAML'
  hub_config = File.open(File.expand_path("~/.config/hub"), 'r:bom|utf-8') { |f| Psych.safe_load(f.read) }
  user = hub_config['github.com'][0]['user']
  `git remote -v`.split("\n").map{|l| l.split}.select{|a| a[2] == '(push)' && a[1] =~ /github.com.#{user}/ }.first[0]
end
hub_fork_remote_name

It would be much easier if hub was able to display some information, such as the username and the fork remote name.

I am willing to contribute it, but would gladly first get some feedback on whether this is a good idea and where it would make most sense to add the feature.

mislav commented 5 years ago

Excellent suggestion; thank you for writing in!

The next feature release of hub will aim to name the remote for your fork origin by default (and rename existing origin to upstream if it exists). After that change, it will be easier for scripts to guess the name of the fork since hub fork will result in origin by default, instead of the person's username.

However, even after that, we will still need a tool that looks up the git remote of one's fork, because we don't know whether the git remote was created with an old version of hub.

I'm imagining a new command that dumps information about the current repository in a machine-readable format for scripts. That command would help with looking up things like:

  1. current git remote setup (for remotes that point to GitHub repos)
  2. the upstream configuration of the current branch
  3. the default branch of the repository (usually for PR base)
  4. the currently logged-in user

Anything else? Also, how do we imagine this command being called and what should its output look like?

ghost commented 4 years ago

I currently don't have a suggestion for how the output will look, but having the command be named

hub repo info

looks intuitive enough.