├── .npmrc ├── .gitattributes ├── .gitignore ├── .github ├── funding.yml ├── security.md └── workflows │ └── main.yml ├── test.js ├── index.test-d.ts ├── .editorconfig ├── index.js ├── index.d.ts ├── package.json ├── license └── readme.md /.npmrc: -------------------------------------------------------------------------------- 1 | package-lock=false 2 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto eol=lf 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | yarn.lock 3 | -------------------------------------------------------------------------------- /.github/funding.yml: -------------------------------------------------------------------------------- 1 | github: sindresorhus 2 | tidelift: npm/git-remote-origin-url 3 | -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | import test from 'ava'; 2 | import gitRemoteOriginUrl from './index.js'; 3 | 4 | test('main', async t => { 5 | t.truthy(await gitRemoteOriginUrl()); 6 | }); 7 | -------------------------------------------------------------------------------- /.github/security.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure. 4 | -------------------------------------------------------------------------------- /index.test-d.ts: -------------------------------------------------------------------------------- 1 | import {expectType} from 'tsd'; 2 | import gitRemoteOriginUrl from './index.js'; 3 | 4 | expectType>(gitRemoteOriginUrl()); 5 | expectType>(gitRemoteOriginUrl({cwd: 'my-custom-path'})); 6 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = tab 5 | end_of_line = lf 6 | charset = utf-8 7 | trim_trailing_whitespace = true 8 | insert_final_newline = true 9 | 10 | [*.yml] 11 | indent_style = space 12 | indent_size = 2 13 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | on: 3 | - push 4 | - pull_request 5 | jobs: 6 | test: 7 | name: Node.js ${{ matrix.node-version }} 8 | runs-on: ubuntu-latest 9 | strategy: 10 | fail-fast: false 11 | matrix: 12 | node-version: 13 | - 16 14 | steps: 15 | - uses: actions/checkout@v2 16 | - uses: actions/setup-node@v2 17 | with: 18 | node-version: ${{ matrix.node-version }} 19 | - run: npm install 20 | - run: npm test 21 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | import {promisify} from 'node:util'; 2 | import process from 'node:process'; 3 | import gitconfig from 'gitconfiglocal'; 4 | 5 | const pGitconfig = promisify(gitconfig); 6 | 7 | export default async function gitRemoteOriginUrl({cwd = process.cwd(), remoteName = 'origin'} = {}) { 8 | const config = await pGitconfig(cwd); 9 | const url = config.remote && config.remote[remoteName] && config.remote[remoteName].url; 10 | 11 | if (!url) { 12 | throw new Error(`Couldn't find ${remoteName} url`); 13 | } 14 | 15 | return url; 16 | } 17 | -------------------------------------------------------------------------------- /index.d.ts: -------------------------------------------------------------------------------- 1 | export type Options = { 2 | /** 3 | The current working directory. 4 | 5 | @default process.cwd() 6 | */ 7 | readonly cwd?: string; 8 | 9 | /** 10 | The Git remote name. 11 | 12 | @default 'origin' 13 | */ 14 | readonly remoteName?: string; 15 | }; 16 | 17 | /** 18 | Get the remote origin URL of a Git repository. 19 | 20 | @example 21 | ``` 22 | import gitRemoteOriginUrl from 'git-remote-origin-url'; 23 | 24 | console.log(await gitRemoteOriginUrl()); 25 | //=> 'git@github.com:sindresorhus/git-remote-origin-url.git' 26 | ``` 27 | */ 28 | export default function gitRemoteOriginUrl(options?: Options): Promise; 29 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "git-remote-origin-url", 3 | "version": "4.0.0", 4 | "description": "Get the remote origin URL of a Git repository", 5 | "license": "MIT", 6 | "repository": "sindresorhus/git-remote-origin-url", 7 | "funding": "https://github.com/sponsors/sindresorhus", 8 | "author": { 9 | "name": "Sindre Sorhus", 10 | "email": "sindresorhus@gmail.com", 11 | "url": "https://sindresorhus.com" 12 | }, 13 | "type": "module", 14 | "exports": "./index.js", 15 | "engines": { 16 | "node": "^12.20.0 || ^14.13.1 || >=16.0.0" 17 | }, 18 | "scripts": { 19 | "test": "xo && ava && tsd" 20 | }, 21 | "files": [ 22 | "index.js", 23 | "index.d.ts" 24 | ], 25 | "keywords": [ 26 | "git", 27 | "config", 28 | "url", 29 | "repo", 30 | "remote", 31 | "origin" 32 | ], 33 | "dependencies": { 34 | "gitconfiglocal": "^2.1.0" 35 | }, 36 | "devDependencies": { 37 | "ava": "^3.15.0", 38 | "tsd": "^0.17.0", 39 | "xo": "^0.44.0" 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /license: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) Sindre Sorhus (https://sindresorhus.com) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # git-remote-origin-url 2 | 3 | > Get the remote origin URL of a Git repository 4 | 5 | ## Install 6 | 7 | ``` 8 | $ npm install git-remote-origin-url 9 | ``` 10 | 11 | ## Usage 12 | 13 | ```js 14 | import gitRemoteOriginUrl from 'git-remote-origin-url'; 15 | 16 | console.log(await gitRemoteOriginUrl()); 17 | //=> 'git@github.com:sindresorhus/git-remote-origin-url.git' 18 | ``` 19 | 20 | ## gitRemoteOriginUrl(options?) 21 | 22 | ### options 23 | 24 | Type: `object` 25 | 26 | #### cwd 27 | 28 | Type: `string`\ 29 | Default: `process.cwd()` 30 | 31 | The current working directory. 32 | 33 | #### remoteName 34 | 35 | Type: `string`\ 36 | Default: `'origin'` 37 | 38 | The Git remote name. 39 | 40 | --- 41 | 42 |
43 | 44 | Get professional support for this package with a Tidelift subscription 45 | 46 |
47 | 48 | Tidelift helps make open source sustainable for maintainers while giving companies
assurances about security, maintenance, and licensing for their dependencies. 49 |
50 |
51 | --------------------------------------------------------------------------------