Giter Site home page Giter Site logo

hotoo / gitopen Goto Github PK

View Code? Open in Web Editor NEW
43.0 3.0 6.0 1.64 MB

:twisted_rightwards_arrows: Open git/hg/svn remote url via web browser from terminal.

Home Page: https://hotoo.github.io/blog/post/gitopen

JavaScript 98.35% Makefile 1.65%
gitcafe gitlab github git

gitopen's Introduction

gitopen

NPM version Build status Coveralls status

Open git/hg/svn remote url in web browser from terminal.

demo

Support:

  • Mac OS X
  • Windows
  • Linux/Unix

,

  • git
  • hg
  • svn

and

If you are use GitBucket, tell me please.

Install

$ npm install -g gitopen

Usage

$ git remote -v
origin	[email protected]:hotoo/gitopen.git (fetch)
origin	[email protected]:hotoo/gitopen.git (push)
$ git branch
* master
$ cd subdir

$ gitopen                       # Open git repository homepage, like: https://github.com/hotoo/gitopen
$ gitopen :master               # Open git repository on given branch name.
$ gitopen -b master             # Same the `:master`
$ gitopen issues                # https://github.com/hotoo/gitopen/issues
$ gitopen #1                    # https://github.com/hotoo/gitopen/issues/1
$ gitopen pr                    # New a pull-request
$ gitopen !1                    # Open merge/pull request by id.
$ gitopen prs                   # https://github.com/hotoo/gitopen/pulls, alias `pulls`, `mrs`.
$ gitopen wiki                  # Open wiki pages.
$ gitopen release               # Open releases page.
$ gitopen tags                  # Open tags page.
$ gitopen commits               # Open commits page.
$ gitopen brs                   # Open branches page, alias `branchs` and `branches`.
$ gitopen {hash}                # Open commit page by hash code.

$ gitopen README.md             # Open remote blob url. default use current working branch.
$ gitopen README.md -b branch   # Open remote blob url by given branch.
$ gitopen README.md :branch     # Open remote blob url by given branch.
$ gitopen path/to/dir           # Open remote tree url. default use current working branch.

# global command.
$ gitopen @lizzie               # https://github.com/lizzie
$ gitopen @hotoo/gitopen        # https://github.com/hotoo/gitopen

Configuration

Default support github.com, bitbucket.org, gitlab.com, gitea.com, gitcafe.com, coding.net, gitee.com, AntCode and CSDN gitcode.com.

If you are use GitHub Enterprise, GitLab Community Edition (CE), GitLab Enterprise Edition (EE), Atlassian Stash, GitCafe Enterprise You need config in ~/.gitconfig file:

[gitopen "github.company.com"]
	type = github
	protocol = https
[gitopen "gitlab.company.net"]
	type = gitlab
	protocol = http

You can config it by git command-line:

; global
$ git config --global gitopen.github.company.com.type github
$ git config --global gitopen.github.company.com.protocol https

; set local repo default remote name.
$ git remote add gitlabRemote [email protected]:hotoo/gitopen.git
$ git config gitopen.remote gitlabRemote

Also you can config it in ~/.gitopenrc file for global settings:

github.company.com:
  type: github
  protocol: https
gitlab.company.net:
  type: gitlab
  protocol: http
  • github.company.com, gitlab.company.net is your company's git web server domain name.
    • type is the type of your company's git web server, support github, gitlab, gitbucket, gitea, coding, gitee, gitcode, antcode.
    • protocol: protocol of your company's git web server, http or https.

Else if you are using other custom web system build your owner git server, you need config like:

git.example.com:
  type: custom
  protocol: http
  scheme:
    issues: /path/to/issues
    wiki: /path/to/wikis
    more: [reference to github scheme](./lib/scheme/github.js)
    ...

You can git alias in ~/.gitconfig:

[alias]
  open = !gitopen

Then you can use command like:

$ git open

gitopen Commands

$ gitopen

Open git repository homepage.

$ gitopen issues

Open git repository issues list page.

$ gitopen issue [title]

Open new issue with title (optional).

$ gitopen #1

Open git repository issue by id.

$ gitopen pulls

Open git repository pulls list page.

$ gitopen pull [branch-name]

Open pull request or merge request from given branch or current working branch for git repository.

alias:

  • $ gitopen pr
  • $ gitopen mr

for example:

$ gitopen pr        # current working branch to compare default branch.
$ gitopen pr a      # given branch(a) to compare default branch.
$ gitopen pr a b    # branch b to compare branch a.
$ gitopen pr a...b  # branch b to compare branch a.

$ gitopen !1

Open git repository pull request or merge request by id.

alias:

  • $ gitopen pr1
  • $ gitopen mr#1

support @, /, #, :, - or without sparator.

$ gitopen blame path/to/file

Open file blame information page.

$ gitopen commits

Open git repository commits list page.

alias:

  • $ gitopen commit
  • $ gitopen ci

$ gitopen {hash}

Open commit page by hash code.

$ gitopen wiki

Open git repository wiki home page.

alias:

  • $ gitopen wikis

$ gitopen tags

Open git repository tags list page.

alias:

  • $ gitopen tag

$ gitopen milestones

Open git repository milestones list page.

$ gitopen milestones@id

Open git repository milestones by given id.

alias:

  • $ gitopen milestone@id

support @, /, #, :, - sparator.

$ gitopen milestone

Open new milestone for git.

$ gitopen releases

Open git repository releases list page.

alias:

  • $ gitopen release

$ gitopen release new [tag-name]

Open new release by tag name.

$ gitopen release edit

Edit release by tag name.

$ gitopen filename [--branch ]

Open given file on given branch, default use current working branch.

alias:

  • $ gitopen filename :branch
  • $ gitopen filename -b branch

$ gitopen directory [--branch ]

Open given directory on given branch, default use current working branch.

alias:

  • $ gitopen directory :branch
  • $ gitopen directory -b branch

$ gitopen snippet

[LOCAL COMMAND] Open new snippet.

[GLOBAL COMMAND] Open https://gist.github.com/

alias:

  • $ gitopen snip
  • $ gitopen gist

$ gitopen network

Open network page.

$ gitopen @profile

[GLOBAL COMMAND] Open profile page on GitHub.

$ gitopen @profile/repository-name

[GLOBAL COMMAND] Open given repository homepage on GitHub.

hgopen Commands

Support all of gitopen in repository local commands (not support global commands), like:

  • $ hgopen open homepage.
  • $ hgopen issues open issues list page.
  • $ hgopen #id op issues by id.
  • ...

svnopen Commands

$ svnopen

Open svn repository on current working directory.

Options

-p, --path

Specify file/directory path, default is current working directory.

If you want open a file or directory name is reserved words, like issues and pr, you can use --path option instead.

$ gitopen -p issues
$ gitopen --path pr

-b, --branch

Specify git/hg branch name, default is current working branch.

-r, --remote

Specify git remote name, default is origin.

-v, --verbose

Display detail information for debug.

FAQ

xdg-open: not found in Linux

sudo apt-get install xdg-utils --fix-missing

License

MIT

Donate

If this tool is useful for you, please Star this repository.

And maybe you want to donate me via Alipay / WeChat:

Alipay:hotoo.cn@gmail.com, WeChat:hotoome

Thank you.

gitopen's People

Contributors

dependabot[bot] avatar hotoo avatar nlazarov avatar xudafeng avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

gitopen's Issues

gitopen help

open https://github.com/hotoo/gitopen#gitopen

symbolic-ref

  • open PR/MR auto ref to symbolic branch.
  • open symbolic-ref will go to actual branch.

Create MR/PR support multiple remote

right:

https://github.com/hotoo/fanyi/pull/new/feat/nocolor

https://github.com/afc163/fanyi/compare/master...hotoo:feat/nocolor?expand=1

wrong:

https://github.com/hotoo/fanyi/compare/master...feat/nocolor?expand=1

Error: Command failed: git config --list --local | grep "^gitopen\."

Hi, hooto:

Thanks for this convenient tool. I found an update to 3.0.0 today and I upgraded it, but I got an error:

child_process.js:679
    throw err;
    ^

Error: Command failed: git config --list --global | grep "^gitopen\.gitlab\.company\.com\."
    at checkExecSyncError (child_process.js:639:11)
    at Object.execSync (child_process.js:676:15)
    at openrc (/usr/local/lib/node_modules/gitopen/bin/openrc.js:59:17)
    at /usr/local/lib/node_modules/gitopen/bin/gitopen:60:16
    at module.exports (/usr/local/lib/node_modules/gitopen/bin/open-commander.js:335:3)
    at Object.<anonymous> (/usr/local/lib/node_modules/gitopen/bin/gitopen:16:1)
    at Module._compile (internal/modules/cjs/loader.js:816:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:827:10)
    at Module.load (internal/modules/cjs/loader.js:685:32)
    at Function.Module._load (internal/modules/cjs/loader.js:620:12)

I found that I need to add some config into ~/.gitconfig now because I'm using GitLab CE. So I added:

[gitopen "gitlab.company.com"]
    type = gitlab
    protocol = https

Now it reports:

child_process.js:679
    throw err;
    ^

Error: Command failed: git config --list --local | grep "^gitopen\."
    at checkExecSyncError (child_process.js:639:11)
    at Object.execSync (child_process.js:676:15)
    at openrc (/usr/local/lib/node_modules/gitopen/bin/openrc.js:71:17)
    at /usr/local/lib/node_modules/gitopen/bin/gitopen:60:16
    at module.exports (/usr/local/lib/node_modules/gitopen/bin/open-commander.js:335:3)
    at Object.<anonymous> (/usr/local/lib/node_modules/gitopen/bin/gitopen:16:1)
    at Module._compile (internal/modules/cjs/loader.js:816:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:827:10)
    at Module.load (internal/modules/cjs/loader.js:685:32)
    at Function.Module._load (internal/modules/cjs/loader.js:620:12)

I wonder why it looks for the local config after I added the configuration into the global ~/.gitconfig. Could you take a look at it?

My ~/.gitopenrc:

gitlab.company.com:
    type: gitlab
    protocol: https

Support XDG_CONFIG_HOME or way to change config path

I don't see a way to change the config path currently. Would be good to follow the XDG config spec:

https://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
https://wiki.archlinux.org/index.php/XDG_Base_Directory_support

Essentially if XDG_CONFIG_HOME is set it'll use that as the base path and then add /git or /gitopen to it.

Git already uses this and will get your config if you have it set - $XDG_CONFIG_HOME/git/config / $XDG_CONFIG_HOME/git/ignore

feat(filepath): open given file.

$ cd subdir
$ gitopen -p .                      # https://github.com/hotoo/gitopen/master/subdir
$ gitopen -p ../README.md           # https://github.com/hotoo/gitopen/blob/master/README.md
$ gitopen -p ../../other-repo-dir   # https://github.com/hotoo/other-repo-dir
$ gitopen -p ../README.md -b branch-name

`gitopen pr` chooses incorrect base branch

The regular expression appears to be incorrect for determining the base branch for a repo.

A way to reproduce this is as follows:

  • Merge a branch which has a commit name that includes square brackets. e.g., [foo] This is my commit message
  • On another branch, run gitopen pr and notice that the URL sets the base branch as foo, somehow pulling that out as the base branch based on the above merged commit with the bracketed [foo] in the commit message

P.S. Thanks for making gitopen. Really useful tool! Hope we can fix this issue, since this is an important feature in your tool over https://github.com/paulirish/git-open.

error in custom gitlab server

某配置的内部 gitlab 执行报错。

$ gitopen
/usr/local/lib/node_modules/gitopen/lib/index.js:54
  return options.scheme.base.replace('{protocol}', protocol)
                       ^
TypeError: Cannot read property 'base' of undefined
    at resolve (/usr/local/lib/node_modules/gitopen/lib/index.js:54:24)
    at module.exports (/usr/local/lib/node_modules/gitopen/lib/index.js:62:13)
    at Object.<anonymous> (/usr/local/lib/node_modules/gitopen/bin/gitopen:226:11)
    at Module._compile (module.js:426:26)
    at Object.Module._extensions..js (module.js:444:10)
    at Module.load (module.js:351:32)
    at Function.Module._load (module.js:306:12)
    at Function.Module.runMain (module.js:467:10)
    at startup (node.js:117:18)
    at node.js:946:3
$ gitopen -V
1.2.0

feat: blame

$ gitopen blame path/to/file
  • GitHub: {server}/{profile}/{repo}/blame/{branch}/path/to/file
  • GitLab: {server}/{profile}/{repo}/blame/master/path/to/file

better way for open MR/PR

When I open new MR/PR, gitopen is use current working branch and remote default branch for now.
but some times, default branch isn't I want, and I can't change the default branch,

Way I

  1. auto get the base branch which the current working branck.
  2. gitopen mr base-branch:current-working-branch

Way II

  1. Get the remote branchs: git branch -r
  2. If just one remote branch, use it as base branch
  3. Else, show remote branches option menu.

global command error in non-git-repo dir

$ cd ~
$ gitopen @hotoo/gitopen
child_process.js:475
    throw err;
          ^
Error: Command failed: git config remote.origin.url

    at checkExecSyncError (child_process.js:432:13)
    at Object.execSync (child_process.js:472:13)
    at Object.getRemoteUrl (/usr/local/lib/node_modules/gitopen/lib/gitremote.js:10:27)
    at Object.<anonymous> (/usr/local/lib/node_modules/gitopen/bin/gitopen:8:21)
    at Module._compile (module.js:426:26)
    at Object.Module._extensions..js (module.js:444:10)
    at Module.load (module.js:351:32)
    at Function.Module._load (module.js:306:12)
    at Function.Module.runMain (module.js:467:10)
    at startup (node.js:117:18)

git branch description

Sometimes, branch name is unreadable for people, you can add a description for this branch:

$ git branch  --edit-description
$ git config branch.youBranchName.description youDescriptionHere

gitopen need show the description when show remote branch option menu.

$ gitopen mr
? Choose remote brance to compare: (Use arrow keys)
❯ origin/MS146182233844965268_20160428 (show description here)
  origin/MS146182233844123456_20160620 (another description)
  origin/master 

Think about config into gitconfig

$ gitopen config gitlab http
$ gitopen config http gitlab
$ gitopen config gitlab.company.com type gitlab
$ git config gitopen.gitlab.company.com.type gitlab
$ gitopen config gitlab.company.com protocol http
$ git config gitopen.gitlab.company.com.protocol http

$ gitopen config --global gitlab.company.com gitlab http
$ gitopen config --global http://gitlab.company.com gitlab
$ gitopen config --global gitlab.company.com type gitlab
$ git config --global gitopen.gitlab.company.com.type gitlab
$ gitopen config --global gitlab.company.com protocol http
$ git config --global gitopen.gitlab.company.com.protocol http

.gitconfig

[gitopen "gitlab.company.com"]
    type = gitlab
    protocol = http

Bad news

  • The .gitconfig can't publish.
  • Not support svn.
  • Need config both in .gitconfig and .hgrc

gitopen does not work properly

We have our own gitlab server .

There is a remote called upstream in .git/config

The .gitopenrc is

gitlab.x.xx.com:
  type: custom
  protocol: http

the gitopen command opens a url like this http://gitlab.x.xx.com/[:username]/[:repository]undefined

the gitopen mr/pr command pops a list without the upstream/master

feat: search

$ gitopen search keyword
  • GitHub: /profile/repo/search?q={keyword}&type={Code|Commits|Issues|Wikis}&utf8=✓
  • GitLab: /search?utf8=✓&search={keyword}&group_id=&project_id={project_id}&scope={blobs|issues|merge_requests|milestones|notes|wiki_blobs|commits}&repository_ref= - get project id by token and API.

gitopen config

Global config:

gitopen config https://github.company.com github

gitopen config github.company.com github https

gitopen config --host=github.company.com --type=github --protocol=https

Local repo config:

gitopen --local config https://github.company.com github

Feature: auto push target branch

  • --push, -p auto push target branch to remote repo.
  • --forcepush, -P auto force push target branch to remote repo.
git config --global gitopen.autopush true

throw error when in Debian

/bin/sh: 1: xdg-open: not found
child_process.js:866
    throw err;
    ^

Error: Command failed: xdg-open https://code.xxx.org/life_service/*********/merge_requests/new\?merge_request%5Bsource_branch%5D\=master
/bin/sh: 1: xdg-open: not found

    at checkExecSyncError (child_process.js:790:11)
    at Object.execSync (child_process.js:863:15)
    at open (/data00/home/lizhiyuan.prozac/.nvm/nvm-0.38.0/versions/node/v14.21.2/lib/node_modules/gitopen/lib/xopen.js:36:17)
    at /data00/home/lizhiyuan.prozac/.nvm/nvm-0.38.0/versions/node/v14.21.2/lib/node_modules/gitopen/bin/gitopen:75:5
    at module.exports (/data00/home/lizhiyuan.prozac/.nvm/nvm-0.38.0/versions/node/v14.21.2/lib/node_modules/gitopen/bin/open-commander.js:330:3)
    at Object.<anonymous> (/data00/home/lizhiyuan.prozac/.nvm/nvm-0.38.0/versions/node/v14.21.2/lib/node_modules/gitopen/bin/gitopen:16:1)
    at Module._compile (internal/modules/cjs/loader.js:1085:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:12) {
  status: 127,
  signal: null,
  output: [
    null,
    Buffer(0) [Uint8Array] [],
    Buffer(32) [Uint8Array] [
       47,  98, 105, 110,  47, 115, 104,  58,
       32,  49,  58,  32, 120, 100, 103,  45,
      111, 112, 101, 110,  58,  32, 110, 111,
      116,  32, 102, 111, 117, 110, 100,  10
    ]
  ],
  pid: 80520,
  stdout: Buffer(0) [Uint8Array] [],
  stderr: Buffer(32) [Uint8Array] [
     47,  98, 105, 110,  47, 115, 104,  58,
     32,  49,  58,  32, 120, 100, 103,  45,
    111, 112, 101, 110,  58,  32, 110, 111,
    116,  32, 102, 111, 117, 110, 100,  10
  ]
}

feat: history

$ gitopen history path/to/file
  • GitHub: {server}/{profile}/{repo}/commits/{branch}/path/to/file
  • GitLab: {server}/{profile}/{repo}/commits/{branch}/path/to/file

support `!1` for merge request

GitLab and Bitbucket'a issues and merge/pull request id is count respectively.

And GitLab support !1 to reference merge request.

command mr branch branch error

gitopen mr master master

/bin/sh: merge_request%5Btarget_branch%5D=master: command not found
child_process.js:1382
    throw err;
          ^
   Error: Command failed: open gitlab/domain/merge_requests/new?merge_request%5Bsource_branch%5D=master&merge_request%5Btarget_branch%5D=master
/bin/sh: merge_request%5Btarget_branch%5D=master: command not found

at checkExecSyncError (child_process.js:1339:13)
at Object.execSync (child_process.js:1379:13)
at open (/usr/local/lib/node_modules/gitopen/lib/xopen.js:30:17)
at Object.<anonymous> (/usr/local/lib/node_modules/gitopen/bin/gitopen:59:3)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:501:10)
at startup (node.js:129:16)

Open exists PR/MR by branch name.

When a branch is already created PR/MR, the new commit will automatically push into the PR/MR.

So I want open the exists PR/MR again.

But GitHub hasn't a API for find PR/MR id by branch name, and the worse is GitLab API is using project id and repo id, not project name and repo name...

Breaks with node v6

gitopen stopped working after I upgraded to node v6. I saw the same thing happen to a colleague.

Is this a known problem?

Log

$ node -v
v6.9.1
$ npm -v
3.10.8
$ gitopen
path.js:7
    throw new TypeError('Path must be a string. Received ' + inspect(path));
    ^

TypeError: Path must be a string. Received undefined
    at assertPath (path.js:7:11)
    at Object.dirname (path.js:1324:5)
    at module.exports (/Users/nick/npm-global/lib/node_modules/gitopen/bin/open-commander.js:86:15)
    at Object.<anonymous> (/Users/nick/npm-global/lib/node_modules/gitopen/bin/gitopen:15:1)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.runMain (module.js:604:10)
$ gitopen pr
path.js:7
    throw new TypeError('Path must be a string. Received ' + inspect(path));
    ^

TypeError: Path must be a string. Received undefined
    at assertPath (path.js:7:11)
    at Object.dirname (path.js:1324:5)
    at module.exports (/Users/nick/npm-global/lib/node_modules/gitopen/bin/open-commander.js:86:15)
    at Object.<anonymous> (/Users/nick/npm-global/lib/node_modules/gitopen/bin/gitopen:15:1)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.runMain (module.js:604:10)

Problem
The problem appears because we're calling path.dirname with undefined (commander.path).
This seems to fix the issue:

- cwd: path.dirname(commander.path) || option.cwd || process.cwd(),
+ cwd: commander.path ? path.dirname(commander.path) : (option.cwd || process.cwd()),

in https://github.com/hotoo/gitopen/blob/d42851b/bin/open-commander.js#L86

gitopen gh-pages

If has CNAME (for example content is "hotoo.me") in gh-pages branch, open http://hotoo.me , else open http://{profile}.github.io/{reponame} .

Just support GitHub.

gitopen config command

$ gitopen config --global --hostname gitlab.com --type gitlab --protocol http
$ gitopen config --hostname gitlab.com --type gitlab --protocol http

$ git config --global gitopen://gitlab.com http://gitlab.com#gitlab
$ git config gitopen://gitlab.com http://gitlab.com#gitlab

Use git config .gitconfig to replace .gitopenrc file.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.