mirror of
https://github.com/x-motemen/ghq.git
synced 2026-09-10 07:26:27 -04:00
Merge branch 'master' into feature/get-print-flag
This commit is contained in:
commit
723bf49fd6
2
.github/workflows/integration.yaml
vendored
2
.github/workflows/integration.yaml
vendored
|
|
@ -15,7 +15,7 @@ jobs:
|
|||
with:
|
||||
persist-credentials: false
|
||||
- name: setup go
|
||||
uses: actions/setup-go@7a3fe6cf4cb3a834922a1244abfce67bcef6a0c5 # v6.2.0
|
||||
uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
|
||||
with:
|
||||
go-version-file: go.mod
|
||||
- name: install
|
||||
|
|
|
|||
4
.github/workflows/reviewdog.yaml
vendored
4
.github/workflows/reviewdog.yaml
vendored
|
|
@ -16,7 +16,7 @@ jobs:
|
|||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
with:
|
||||
persist-credentials: false
|
||||
- uses: crate-ci/typos@78bc6fb2c0d734235d57a2d6b9de923cc325ebdd # v1.43.4
|
||||
- uses: crate-ci/typos@02ea592e44b3a53c302f697cddca7641cd051c3d # v1.45.0
|
||||
|
||||
staticcheck:
|
||||
permissions:
|
||||
|
|
@ -65,6 +65,6 @@ jobs:
|
|||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
with:
|
||||
persist-credentials: false
|
||||
- uses: reviewdog/action-actionlint@e58ee9d111489c31395fbe4857b0be6e7635dbda # v1.70.0
|
||||
- uses: reviewdog/action-actionlint@6fb7acc99f4a1008869fa8a0f09cfca740837d9d # v1.72.0
|
||||
with:
|
||||
reporter: github-pr-review
|
||||
|
|
|
|||
4
.github/workflows/tagpr.yaml
vendored
4
.github/workflows/tagpr.yaml
vendored
|
|
@ -18,12 +18,12 @@ jobs:
|
|||
with:
|
||||
persist-credentials: false
|
||||
- name: setup go
|
||||
uses: actions/setup-go@7a3fe6cf4cb3a834922a1244abfce67bcef6a0c5 # v6.2.0
|
||||
uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
|
||||
with:
|
||||
go-version-file: go.mod
|
||||
- name: tagpr
|
||||
id: tagpr
|
||||
uses: Songmu/tagpr@da82ed6743aec90049892070edd5561335904a9e # v1.17.0
|
||||
uses: Songmu/tagpr@9d0f650553240dab1fa907eca27e3fd5b586e538 # v1.18.1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
- uses: ./.github/actions/release
|
||||
|
|
|
|||
9
.github/workflows/test.yaml
vendored
9
.github/workflows/test.yaml
vendored
|
|
@ -1,8 +1,11 @@
|
|||
name: test
|
||||
on:
|
||||
push:
|
||||
pull_request:
|
||||
branches:
|
||||
- "**"
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
permissions:
|
||||
contents: read
|
||||
pull-requests: read
|
||||
|
|
@ -28,10 +31,10 @@ jobs:
|
|||
with:
|
||||
persist-credentials: false
|
||||
- name: setup go
|
||||
uses: actions/setup-go@7a3fe6cf4cb3a834922a1244abfce67bcef6a0c5 # v6.2.0
|
||||
uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
|
||||
with:
|
||||
go-version-file: go.mod
|
||||
- name: test
|
||||
run: go test -coverprofile coverage.out -covermode atomic ./...
|
||||
- name: Send coverage
|
||||
uses: codecov/codecov-action@671740ac38dd9b0130fbe1cec585b89eea48d3de # v5.5.2
|
||||
uses: codecov/codecov-action@57e3a136b779b570ffcdbf80b3bdc90e7fab3de2 # v6.0.0
|
||||
|
|
|
|||
135
CREDITS
135
CREDITS
|
|
@ -117,33 +117,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
================================================================
|
||||
|
||||
github.com/cpuguy83/go-md2man/v2
|
||||
https://github.com/cpuguy83/go-md2man/v2
|
||||
----------------------------------------------------------------
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Brian Goff
|
||||
|
||||
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:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
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.
|
||||
|
||||
================================================================
|
||||
|
||||
github.com/davecgh/go-spew
|
||||
https://github.com/davecgh/go-spew
|
||||
----------------------------------------------------------------
|
||||
|
|
@ -379,6 +352,46 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|||
SOFTWARE.
|
||||
================================================================
|
||||
|
||||
github.com/otiai10/copy
|
||||
https://github.com/otiai10/copy
|
||||
----------------------------------------------------------------
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2018 otiai10
|
||||
|
||||
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:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
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.
|
||||
|
||||
================================================================
|
||||
|
||||
github.com/otiai10/mint
|
||||
https://github.com/otiai10/mint
|
||||
----------------------------------------------------------------
|
||||
Copyright 2017 otiai10 (Hiromu OCHIAI)
|
||||
|
||||
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:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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.
|
||||
|
||||
================================================================
|
||||
|
||||
github.com/pmezard/go-difflib
|
||||
https://github.com/pmezard/go-difflib
|
||||
----------------------------------------------------------------
|
||||
|
|
@ -412,41 +425,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
================================================================
|
||||
|
||||
github.com/russross/blackfriday/v2
|
||||
https://github.com/russross/blackfriday/v2
|
||||
----------------------------------------------------------------
|
||||
Blackfriday is distributed under the Simplified BSD License:
|
||||
|
||||
> Copyright © 2011 Russ Ross
|
||||
> All rights reserved.
|
||||
>
|
||||
> Redistribution and use in source and binary forms, with or without
|
||||
> modification, are permitted provided that the following conditions
|
||||
> are met:
|
||||
>
|
||||
> 1. Redistributions of source code must retain the above copyright
|
||||
> notice, this list of conditions and the following disclaimer.
|
||||
>
|
||||
> 2. Redistributions in binary form must reproduce the above
|
||||
> copyright notice, this list of conditions and the following
|
||||
> disclaimer in the documentation and/or other materials provided with
|
||||
> the distribution.
|
||||
>
|
||||
> THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
> "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
> LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
> FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
> COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
> INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
> BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
> LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
> CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
> LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
> ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
> POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
================================================================
|
||||
|
||||
github.com/saracen/walker
|
||||
https://github.com/saracen/walker
|
||||
----------------------------------------------------------------
|
||||
|
|
@ -500,12 +478,12 @@ SOFTWARE.
|
|||
|
||||
================================================================
|
||||
|
||||
github.com/urfave/cli/v2
|
||||
https://github.com/urfave/cli/v2
|
||||
github.com/urfave/cli/v3
|
||||
https://github.com/urfave/cli/v3
|
||||
----------------------------------------------------------------
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2022 urfave/cli maintainers
|
||||
Copyright (c) 2023 urfave/cli maintainers
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
|
@ -527,33 +505,6 @@ SOFTWARE.
|
|||
|
||||
================================================================
|
||||
|
||||
github.com/xrash/smetrics
|
||||
https://github.com/xrash/smetrics
|
||||
----------------------------------------------------------------
|
||||
Copyright (C) 2016 Felipe da Cunha Gonçalves
|
||||
All Rights Reserved.
|
||||
|
||||
MIT LICENSE
|
||||
|
||||
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:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
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.
|
||||
|
||||
================================================================
|
||||
|
||||
golang.org/x/net
|
||||
https://golang.org/x/net
|
||||
----------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -98,6 +98,11 @@ ghq.completeUser::
|
|||
`vim` as `github.com/vim/vim`, and `peco` as `github.com/peco/peco`.
|
||||
If you prefer this behavior, set this option to `false` to switch the owner completion method.
|
||||
|
||||
ghq.defaultHost::
|
||||
The default host used when the repository specification omits the host.
|
||||
For example, `ghq get owner/project` normally resolves to `github.com/owner/project`.
|
||||
If this option is set, the specified host will be used instead.
|
||||
|
||||
ghq.<url>.vcs::
|
||||
ghq tries to detect the remote repository's VCS backend for non-"github.com"
|
||||
repositories. With this option you can explicitly specify the VCS for the
|
||||
|
|
|
|||
|
|
@ -1,19 +1,20 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
func doCreate(c *cli.Context) error {
|
||||
func doCreate(ctx context.Context, cmd *cli.Command) error {
|
||||
var (
|
||||
name = c.Args().First()
|
||||
vcs = c.String("vcs")
|
||||
w = c.App.Writer
|
||||
bare = c.Bool("bare")
|
||||
name = cmd.Args().First()
|
||||
vcs = cmd.String("vcs")
|
||||
w = cmd.Root().Writer
|
||||
bare = cmd.Bool("bare")
|
||||
)
|
||||
|
||||
if name == "" {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"os"
|
||||
"os/exec"
|
||||
|
|
@ -128,7 +129,7 @@ func TestDoCreate(t *testing.T) {
|
|||
|
||||
var err error
|
||||
out, _, _ := capture(func() {
|
||||
err = newApp().Run(append([]string{""}, tc.input...))
|
||||
err = newApp().Run(context.Background(), append([]string{""}, tc.input...))
|
||||
})
|
||||
out = strings.TrimSpace(out)
|
||||
|
||||
|
|
|
|||
31
cmd_get.go
31
cmd_get.go
|
|
@ -2,6 +2,7 @@ package main
|
|||
|
||||
import (
|
||||
"bufio"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
|
|
@ -13,30 +14,30 @@ import (
|
|||
"sync"
|
||||
|
||||
"github.com/mattn/go-isatty"
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
"github.com/x-motemen/ghq/cmdutil"
|
||||
"github.com/x-motemen/ghq/logger"
|
||||
"golang.org/x/sync/errgroup"
|
||||
)
|
||||
|
||||
func doGet(c *cli.Context) error {
|
||||
func doGet(ctx context.Context, cmd *cli.Command) error {
|
||||
var (
|
||||
args = c.Args().Slice()
|
||||
andLook = c.Bool("look")
|
||||
parallel = c.Bool("parallel")
|
||||
silent = c.Bool("silent")
|
||||
printPath = c.Bool("print")
|
||||
args = cmd.Args().Slice()
|
||||
andLook = cmd.Bool("look")
|
||||
parallel = cmd.Bool("parallel")
|
||||
silent = cmd.Bool("silent")
|
||||
printPath = cmd.Bool("print")
|
||||
)
|
||||
g := &getter{
|
||||
update: c.Bool("update"),
|
||||
shallow: c.Bool("shallow"),
|
||||
ssh: c.Bool("p"),
|
||||
vcs: c.String("vcs"),
|
||||
update: cmd.Bool("update"),
|
||||
shallow: cmd.Bool("shallow"),
|
||||
ssh: cmd.Bool("p"),
|
||||
vcs: cmd.String("vcs"),
|
||||
silent: silent,
|
||||
branch: c.String("branch"),
|
||||
recursive: !c.Bool("no-recursive"),
|
||||
bare: c.Bool("bare"),
|
||||
partial: c.String("partial"),
|
||||
branch: cmd.String("branch"),
|
||||
recursive: !cmd.Bool("no-recursive"),
|
||||
bare: cmd.Bool("bare"),
|
||||
partial: cmd.String("partial"),
|
||||
}
|
||||
if parallel {
|
||||
// force silent in parallel import
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package main
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
|
|
@ -26,7 +27,7 @@ func TestCommandGet(t *testing.T) {
|
|||
scenario: func(t *testing.T, tmpRoot string, cloneArgs *_cloneArgs, updateArgs *_updateArgs) {
|
||||
localDir := filepath.Join(tmpRoot, "github.com", "motemen", "ghq-test-repo")
|
||||
|
||||
app.Run([]string{"", "get", "motemen/ghq-test-repo"})
|
||||
app.Run(context.Background(), []string{"", "get", "motemen/ghq-test-repo"})
|
||||
|
||||
expect := "https://github.com/motemen/ghq-test-repo"
|
||||
if cloneArgs.remote.String() != expect {
|
||||
|
|
@ -53,7 +54,7 @@ func TestCommandGet(t *testing.T) {
|
|||
scenario: func(t *testing.T, tmpRoot string, cloneArgs *_cloneArgs, updateArgs *_updateArgs) {
|
||||
localDir := filepath.Join(tmpRoot, "github.com", "motemen", "ghq-test-repo")
|
||||
|
||||
app.Run([]string{"", "get", "-p", "motemen/ghq-test-repo"})
|
||||
app.Run(context.Background(), []string{"", "get", "-p", "motemen/ghq-test-repo"})
|
||||
|
||||
expect := "ssh://git@github.com/motemen/ghq-test-repo"
|
||||
if cloneArgs.remote.String() != expect {
|
||||
|
|
@ -73,7 +74,7 @@ func TestCommandGet(t *testing.T) {
|
|||
// mark as "already cloned", the condition may change later
|
||||
os.MkdirAll(filepath.Join(localDir, ".git"), 0755)
|
||||
|
||||
app.Run([]string{"", "get", "-update", "motemen/ghq-test-repo"})
|
||||
app.Run(context.Background(), []string{"", "get", "-update", "motemen/ghq-test-repo"})
|
||||
|
||||
if updateArgs.local != localDir {
|
||||
t.Errorf("got: %s, expect: %s", updateArgs.local, localDir)
|
||||
|
|
@ -84,7 +85,7 @@ func TestCommandGet(t *testing.T) {
|
|||
scenario: func(t *testing.T, tmpRoot string, cloneArgs *_cloneArgs, updateArgs *_updateArgs) {
|
||||
localDir := filepath.Join(tmpRoot, "github.com", "motemen", "ghq-test-repo")
|
||||
|
||||
app.Run([]string{"", "get", "-shallow", "motemen/ghq-test-repo"})
|
||||
app.Run(context.Background(), []string{"", "get", "-shallow", "motemen/ghq-test-repo"})
|
||||
|
||||
expect := "https://github.com/motemen/ghq-test-repo"
|
||||
if cloneArgs.remote.String() != expect {
|
||||
|
|
@ -106,7 +107,7 @@ func TestCommandGet(t *testing.T) {
|
|||
os.Chdir(localDir)
|
||||
defer os.Chdir(wd)
|
||||
|
||||
app.Run([]string{"", "get", "-update", "." + string(filepath.Separator) + "ghq-test-repo"})
|
||||
app.Run(context.Background(), []string{"", "get", "-update", "." + string(filepath.Separator) + "ghq-test-repo"})
|
||||
|
||||
expect := "https://github.com/motemen/ghq-test-repo"
|
||||
if cloneArgs.remote.String() != expect {
|
||||
|
|
@ -126,7 +127,7 @@ func TestCommandGet(t *testing.T) {
|
|||
os.Chdir(localDir)
|
||||
defer os.Chdir(wd)
|
||||
|
||||
app.Run([]string{"", "get", "-update", ".." + string(filepath.Separator) + "ghq-another-test-repo"})
|
||||
app.Run(context.Background(), []string{"", "get", "-update", ".." + string(filepath.Separator) + "ghq-another-test-repo"})
|
||||
|
||||
expect := "https://github.com/motemen/ghq-another-test-repo"
|
||||
if cloneArgs.remote.String() != expect {
|
||||
|
|
@ -143,7 +144,7 @@ func TestCommandGet(t *testing.T) {
|
|||
localDir := filepath.Join(tmpRoot, "github.com", "motemen", "ghq-test-repo")
|
||||
|
||||
expectBranch := "hello"
|
||||
app.Run([]string{"", "get", "-shallow", "-branch", expectBranch, "motemen/ghq-test-repo"})
|
||||
app.Run(context.Background(), []string{"", "get", "-shallow", "-branch", expectBranch, "motemen/ghq-test-repo"})
|
||||
|
||||
expect := "https://github.com/motemen/ghq-test-repo"
|
||||
if cloneArgs.remote.String() != expect {
|
||||
|
|
@ -162,7 +163,7 @@ func TestCommandGet(t *testing.T) {
|
|||
localDir := filepath.Join(tmpRoot, "github.com", "motemen", "ghq-test-repo")
|
||||
|
||||
expectBranch := "hello"
|
||||
app.Run([]string{"", "get", "-shallow", "motemen/ghq-test-repo@" + expectBranch})
|
||||
app.Run(context.Background(), []string{"", "get", "-shallow", "motemen/ghq-test-repo@" + expectBranch})
|
||||
|
||||
expect := "https://github.com/motemen/ghq-test-repo"
|
||||
if cloneArgs.remote.String() != expect {
|
||||
|
|
@ -178,7 +179,7 @@ func TestCommandGet(t *testing.T) {
|
|||
}, {
|
||||
name: "with --no-recursive option",
|
||||
scenario: func(t *testing.T, tmpRoot string, cloneArgs *_cloneArgs, updateArgs *_updateArgs) {
|
||||
app.Run([]string{"", "get", "--no-recursive", "motemen/ghq-test-repo"})
|
||||
app.Run(context.Background(), []string{"", "get", "--no-recursive", "motemen/ghq-test-repo"})
|
||||
|
||||
localDir := filepath.Join(tmpRoot, "github.com", "motemen", "ghq-test-repo")
|
||||
if filepath.ToSlash(cloneArgs.local) != filepath.ToSlash(localDir) {
|
||||
|
|
@ -196,7 +197,7 @@ func TestCommandGet(t *testing.T) {
|
|||
[ghq "https://github.com/motemen"]
|
||||
root = "%s"
|
||||
`, filepath.ToSlash(tmpd))))
|
||||
app.Run([]string{"", "get", "motemen/ghq-test-repo"})
|
||||
app.Run(context.Background(), []string{"", "get", "motemen/ghq-test-repo"})
|
||||
|
||||
localDir := filepath.Join(tmpd, "github.com", "motemen", "ghq-test-repo")
|
||||
if filepath.ToSlash(cloneArgs.local) != filepath.ToSlash(localDir) {
|
||||
|
|
@ -208,7 +209,7 @@ func TestCommandGet(t *testing.T) {
|
|||
scenario: func(t *testing.T, tmpRoot string, cloneArgs *_cloneArgs, updateArgs *_updateArgs) {
|
||||
localDir := filepath.Join(tmpRoot, "github.com", "motemen", "ghq-test-repo.git")
|
||||
|
||||
app.Run([]string{"", "get", "--bare", "motemen/ghq-test-repo"})
|
||||
app.Run(context.Background(), []string{"", "get", "--bare", "motemen/ghq-test-repo"})
|
||||
|
||||
expect := "https://github.com/motemen/ghq-test-repo"
|
||||
if cloneArgs.remote.String() != expect {
|
||||
|
|
@ -227,7 +228,7 @@ func TestCommandGet(t *testing.T) {
|
|||
localDir := filepath.Join(tmpRoot, "github.com", "motemen", "ghq-test-repo")
|
||||
|
||||
out, _, err := captureWithInput([]string{}, func() {
|
||||
app.Run([]string{"", "get", "--silent", "motemen/ghq-test-repo"})
|
||||
app.Run(context.Background(), []string{"", "get", "--silent", "motemen/ghq-test-repo"})
|
||||
})
|
||||
if err != nil {
|
||||
t.Errorf("error should be nil, but: %s", err)
|
||||
|
|
@ -253,7 +254,7 @@ func TestCommandGet(t *testing.T) {
|
|||
scenario: func(t *testing.T, tmpRoot string, cloneArgs *_cloneArgs, updateArgs *_updateArgs) {
|
||||
localDir := filepath.Join(tmpRoot, "github.com", "motemen", "ghq-test-repo")
|
||||
|
||||
app.Run([]string{"", "get", "--partial", "blobless", "motemen/ghq-test-repo"})
|
||||
app.Run(context.Background(), []string{"", "get", "--partial", "blobless", "motemen/ghq-test-repo"})
|
||||
|
||||
expect := "https://github.com/motemen/ghq-test-repo"
|
||||
if cloneArgs.remote.String() != expect {
|
||||
|
|
@ -271,7 +272,7 @@ func TestCommandGet(t *testing.T) {
|
|||
scenario: func(t *testing.T, tmpRoot string, cloneArgs *_cloneArgs, updateArgs *_updateArgs) {
|
||||
localDir := filepath.Join(tmpRoot, "github.com", "motemen", "ghq-test-repo")
|
||||
|
||||
app.Run([]string{"", "get", "--partial", "treeless", "motemen/ghq-test-repo"})
|
||||
app.Run(context.Background(), []string{"", "get", "--partial", "treeless", "motemen/ghq-test-repo"})
|
||||
|
||||
expect := "https://github.com/motemen/ghq-test-repo"
|
||||
if cloneArgs.remote.String() != expect {
|
||||
|
|
@ -287,7 +288,7 @@ func TestCommandGet(t *testing.T) {
|
|||
}, {
|
||||
name: "[partial] unacceptable value",
|
||||
scenario: func(t *testing.T, tmpRoot string, cloneArgs *_cloneArgs, updateArgs *_updateArgs) {
|
||||
err := app.Run([]string{"", "get", "--partial", "unacceptable", "motemen/ghq-test-repo"})
|
||||
err := app.Run(context.Background(), []string{"", "get", "--partial", "unacceptable", "motemen/ghq-test-repo"})
|
||||
|
||||
expect := "flag partial value \"unacceptable\" is not allowed"
|
||||
if err.Error() != expect {
|
||||
|
|
@ -385,7 +386,7 @@ func TestLook(t *testing.T) {
|
|||
}
|
||||
sh := detectShell()
|
||||
|
||||
err := newApp().Run([]string{"", "get", "--look", "https://github.com/motemen/ghq"})
|
||||
err := newApp().Run(context.Background(), []string{"", "get", "--look", "https://github.com/motemen/ghq"})
|
||||
if err != nil {
|
||||
t.Errorf("error should be nil, but: %s", err)
|
||||
}
|
||||
|
|
@ -431,7 +432,7 @@ func TestBareLook(t *testing.T) {
|
|||
}
|
||||
sh := detectShell()
|
||||
|
||||
err := newApp().Run([]string{"", "get", "--bare", "--look", "https://github.com/motemen/ghq.git"})
|
||||
err := newApp().Run(context.Background(), []string{"", "get", "--bare", "--look", "https://github.com/motemen/ghq.git"})
|
||||
if err != nil {
|
||||
t.Errorf("error should be nil, but: %s", err)
|
||||
}
|
||||
|
|
@ -493,7 +494,7 @@ func TestDoGet_bulk(t *testing.T) {
|
|||
buf.Reset()
|
||||
out, _, err := captureWithInput(in, func() {
|
||||
args := append([]string{"", "get"}, tc.args...)
|
||||
if err := newApp().Run(args); err != nil {
|
||||
if err := newApp().Run(context.Background(), args); err != nil {
|
||||
t.Errorf("error should be nil but: %s", err)
|
||||
}
|
||||
})
|
||||
|
|
|
|||
19
cmd_list.go
19
cmd_list.go
|
|
@ -1,24 +1,25 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
func doList(c *cli.Context) error {
|
||||
func doList(ctx context.Context, cmd *cli.Command) error {
|
||||
var (
|
||||
w = c.App.Writer
|
||||
query = c.Args().First()
|
||||
exact = c.Bool("exact")
|
||||
vcsBackend = c.String("vcs")
|
||||
printFullPaths = c.Bool("full-path")
|
||||
printUniquePaths = c.Bool("unique")
|
||||
bare = c.Bool("bare")
|
||||
w = cmd.Root().Writer
|
||||
query = cmd.Args().First()
|
||||
exact = cmd.Bool("exact")
|
||||
vcsBackend = cmd.String("vcs")
|
||||
printFullPaths = cmd.Bool("full-path")
|
||||
printUniquePaths = cmd.Bool("unique")
|
||||
bare = cmd.Bool("bare")
|
||||
)
|
||||
|
||||
filterByQuery := func(_ *LocalRepository) bool {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"context"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
|
|
@ -9,26 +9,11 @@ import (
|
|||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
func flagSet(name string, flags []cli.Flag) *flag.FlagSet {
|
||||
set := flag.NewFlagSet(name, flag.ContinueOnError)
|
||||
|
||||
for _, f := range flags {
|
||||
f.Apply(set)
|
||||
}
|
||||
return set
|
||||
}
|
||||
|
||||
func TestCommandList(t *testing.T) {
|
||||
_, _, err := capture(func() {
|
||||
app := cli.NewApp()
|
||||
flagSet := flagSet("list", commandList.Flags)
|
||||
c := cli.NewContext(app, flagSet, nil)
|
||||
|
||||
doList(c)
|
||||
newApp().Run(context.Background(), []string{"ghq", "list"})
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
|
|
@ -38,12 +23,7 @@ func TestCommandList(t *testing.T) {
|
|||
|
||||
func TestCommandListUnique(t *testing.T) {
|
||||
_, _, err := capture(func() {
|
||||
app := cli.NewApp()
|
||||
flagSet := flagSet("list", commandList.Flags)
|
||||
flagSet.Parse([]string{"--unique"})
|
||||
c := cli.NewContext(app, flagSet, nil)
|
||||
|
||||
doList(c)
|
||||
newApp().Run(context.Background(), []string{"ghq", "list", "--unique"})
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
|
|
@ -53,12 +33,7 @@ func TestCommandListUnique(t *testing.T) {
|
|||
|
||||
func TestCommandListUnknown(t *testing.T) {
|
||||
_, _, err := capture(func() {
|
||||
app := cli.NewApp()
|
||||
flagSet := flagSet("list", commandList.Flags)
|
||||
flagSet.Parse([]string{"--unknown-flag"})
|
||||
c := cli.NewContext(app, flagSet, nil)
|
||||
|
||||
doList(c)
|
||||
newApp().Run(context.Background(), []string{"ghq", "list", "--unknown-flag"})
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
|
|
@ -158,7 +133,7 @@ func TestDoList_query(t *testing.T) {
|
|||
t.Run(tc.name, func(t *testing.T) {
|
||||
args := append([]string{"ghq", "list"}, tc.args...)
|
||||
out, _, _ := capture(func() {
|
||||
newApp().Run(args)
|
||||
newApp().Run(context.Background(), args)
|
||||
})
|
||||
if !equalPathLines(out, tc.expect) {
|
||||
t.Errorf("got:\n%s\nexpect:\n%s", out, tc.expect)
|
||||
|
|
@ -177,7 +152,7 @@ func TestDoList_query(t *testing.T) {
|
|||
fullExpect += "\n"
|
||||
}
|
||||
out, _, _ = capture(func() {
|
||||
newApp().Run(argsFull)
|
||||
newApp().Run(context.Background(), argsFull)
|
||||
})
|
||||
if !equalPathLines(out, fullExpect) {
|
||||
t.Errorf("got:\n%s\nexpect:\n%s", out, fullExpect)
|
||||
|
|
@ -201,7 +176,7 @@ func TestDoList_unique(t *testing.T) {
|
|||
os.MkdirAll(filepath.Join(rootPath, "github.com/motemen/ghq/.git"), 0755)
|
||||
}
|
||||
out, _, _ := capture(func() {
|
||||
newApp().Run([]string{"ghq", "list", "--unique"})
|
||||
newApp().Run(context.Background(), []string{"ghq", "list", "--unique"})
|
||||
})
|
||||
if out != "ghq\n" {
|
||||
t.Errorf("got: %s, expect: ghq\n", out)
|
||||
|
|
@ -214,7 +189,7 @@ func TestDoList_unknownRoot(t *testing.T) {
|
|||
_localRepositoryRoots = nil
|
||||
localRepoOnce = &sync.Once{}
|
||||
|
||||
err := newApp().Run([]string{"ghq", "list"})
|
||||
err := newApp().Run(context.Background(), []string{"ghq", "list"})
|
||||
if err != nil {
|
||||
t.Errorf("error should be nil, but: %v", err)
|
||||
}
|
||||
|
|
@ -233,7 +208,7 @@ func TestDoList_notPermittedRoot(t *testing.T) {
|
|||
localRepoOnce = &sync.Once{}
|
||||
os.Chmod(tmpdir, 0000)
|
||||
|
||||
err := newApp().Run([]string{"ghq", "list"})
|
||||
err := newApp().Run(context.Background(), []string{"ghq", "list"})
|
||||
if err != nil {
|
||||
t.Errorf("error should be nil, but: %+v", err)
|
||||
}
|
||||
|
|
@ -253,7 +228,7 @@ func TestDoList_withSystemHiddenDir(t *testing.T) {
|
|||
_localRepositoryRoots = nil
|
||||
localRepoOnce = &sync.Once{}
|
||||
|
||||
err := newApp().Run([]string{"ghq", "list"})
|
||||
err := newApp().Run(context.Background(), []string{"ghq", "list"})
|
||||
if err != nil {
|
||||
t.Errorf("error should be nil, but: %v", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
|
|
@ -10,16 +11,16 @@ import (
|
|||
"syscall"
|
||||
|
||||
"github.com/otiai10/copy"
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
"github.com/x-motemen/ghq/logger"
|
||||
)
|
||||
|
||||
func doMigrate(c *cli.Context) error {
|
||||
func doMigrate(ctx context.Context, cmd *cli.Command) error {
|
||||
var (
|
||||
repoDir = c.Args().First()
|
||||
dry = c.Bool("dry-run")
|
||||
skipConfirm = c.Bool("y")
|
||||
w = c.App.Writer
|
||||
repoDir = cmd.Args().First()
|
||||
dry = cmd.Bool("dry-run")
|
||||
skipConfirm = cmd.Bool("y")
|
||||
w = cmd.Root().Writer
|
||||
)
|
||||
|
||||
if repoDir == "" {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
|
|
@ -65,7 +66,7 @@ func TestDoMigrate(t *testing.T) {
|
|||
c2.Run()
|
||||
|
||||
a := newApp()
|
||||
e := a.Run([]string{"ghq", "migrate", "-y", srcdir})
|
||||
e := a.Run(context.Background(), []string{"ghq", "migrate", "-y", srcdir})
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
|
|
@ -79,7 +80,7 @@ func TestDoMigrate(t *testing.T) {
|
|||
// Test case: nonexistent directory
|
||||
t.Run("migrate_nonexist", func(t *testing.T) {
|
||||
a := newApp()
|
||||
e := a.Run([]string{"ghq", "migrate", "-y", "/does/not/exist"})
|
||||
e := a.Run(context.Background(), []string{"ghq", "migrate", "-y", "/does/not/exist"})
|
||||
if e == nil {
|
||||
t.Error("expected error")
|
||||
}
|
||||
|
|
@ -99,7 +100,7 @@ func TestDoMigrate(t *testing.T) {
|
|||
c2.Run()
|
||||
|
||||
a := newApp()
|
||||
e := a.Run([]string{"ghq", "migrate", "--dry-run", srcdir})
|
||||
e := a.Run(context.Background(), []string{"ghq", "migrate", "--dry-run", srcdir})
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
|
|
@ -117,7 +118,7 @@ func TestDoMigrate(t *testing.T) {
|
|||
addWorktree(t, srcdir, wtDir, "wt-branch")
|
||||
|
||||
a := newApp()
|
||||
e := a.Run([]string{"ghq", "migrate", "-y", srcdir})
|
||||
e := a.Run(context.Background(), []string{"ghq", "migrate", "-y", srcdir})
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
|
|
@ -154,7 +155,7 @@ func TestDoMigrate(t *testing.T) {
|
|||
|
||||
out, _, err := capture(func() {
|
||||
a := newApp()
|
||||
a.Run([]string{"ghq", "migrate", "--dry-run", srcdir})
|
||||
a.Run(context.Background(), []string{"ghq", "migrate", "--dry-run", srcdir})
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
|
@ -180,7 +181,7 @@ func TestDoMigrate(t *testing.T) {
|
|||
addWorktree(t, srcdir, wtDir, "wt-int-branch")
|
||||
|
||||
a := newApp()
|
||||
e := a.Run([]string{"ghq", "migrate", "-y", srcdir})
|
||||
e := a.Run(context.Background(), []string{"ghq", "migrate", "-y", srcdir})
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
|
|
@ -226,7 +227,7 @@ func TestMigrateEdgeCases(t *testing.T) {
|
|||
os.MkdirAll(srcdir, 0755)
|
||||
|
||||
a := newApp()
|
||||
e := a.Run([]string{"ghq", "migrate", "-y", srcdir})
|
||||
e := a.Run(context.Background(), []string{"ghq", "migrate", "-y", srcdir})
|
||||
if e == nil {
|
||||
t.Error("should fail when no VCS found")
|
||||
}
|
||||
|
|
@ -241,7 +242,7 @@ func TestMigrateEdgeCases(t *testing.T) {
|
|||
c.Run()
|
||||
|
||||
a := newApp()
|
||||
e := a.Run([]string{"ghq", "migrate", "-y", srcdir})
|
||||
e := a.Run(context.Background(), []string{"ghq", "migrate", "-y", srcdir})
|
||||
if e == nil {
|
||||
t.Error("should fail when no remote")
|
||||
}
|
||||
|
|
@ -263,7 +264,7 @@ func TestMigrateEdgeCases(t *testing.T) {
|
|||
os.MkdirAll(dest, 0755)
|
||||
|
||||
a := newApp()
|
||||
e := a.Run([]string{"ghq", "migrate", "-y", srcdir})
|
||||
e := a.Run(context.Background(), []string{"ghq", "migrate", "-y", srcdir})
|
||||
if e == nil {
|
||||
t.Error("should fail when dest exists")
|
||||
}
|
||||
|
|
@ -276,7 +277,7 @@ func TestMigrateEdgeCases(t *testing.T) {
|
|||
addWorktree(t, srcdir, wtDir, "wt-ref-branch")
|
||||
|
||||
a := newApp()
|
||||
e := a.Run([]string{"ghq", "migrate", "-y", wtDir})
|
||||
e := a.Run(context.Background(), []string{"ghq", "migrate", "-y", wtDir})
|
||||
if e == nil {
|
||||
t.Fatal("expected error migrating a worktree")
|
||||
}
|
||||
|
|
@ -299,7 +300,7 @@ func TestMigrateEdgeCases(t *testing.T) {
|
|||
os.WriteFile(repoFile, []byte("test-repo\n"), 0644)
|
||||
|
||||
a := newApp()
|
||||
e := a.Run([]string{"ghq", "migrate", "-y", srcdir})
|
||||
e := a.Run(context.Background(), []string{"ghq", "migrate", "-y", srcdir})
|
||||
if e == nil {
|
||||
t.Error("should fail for unsupported VCS (CVS)")
|
||||
}
|
||||
|
|
|
|||
13
cmd_rm.go
13
cmd_rm.go
|
|
@ -1,18 +1,19 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
func doRm(c *cli.Context) error {
|
||||
func doRm(ctx context.Context, cmd *cli.Command) error {
|
||||
var (
|
||||
name = c.Args().First()
|
||||
dry = c.Bool("dry-run")
|
||||
w = c.App.Writer
|
||||
bare = c.Bool("bare")
|
||||
name = cmd.Args().First()
|
||||
dry = cmd.Bool("dry-run")
|
||||
w = cmd.Root().Writer
|
||||
bare = cmd.Bool("bare")
|
||||
)
|
||||
|
||||
if name == "" {
|
||||
|
|
|
|||
|
|
@ -1,22 +1,23 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
func doRoot(c *cli.Context) error {
|
||||
func doRoot(ctx context.Context, cmd *cli.Command) error {
|
||||
roots, err := localRepositoryRoots(true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !c.Bool("all") {
|
||||
if !cmd.Bool("all") {
|
||||
roots = roots[:1] // only the first root is needed
|
||||
}
|
||||
|
||||
for _, root := range roots {
|
||||
_, err := fmt.Fprintln(c.App.Writer, root)
|
||||
_, err := fmt.Fprintln(cmd.Root().Writer, root)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
|
|
@ -90,13 +91,13 @@ func TestDoRoot(t *testing.T) {
|
|||
homeOnce = &sync.Once{}
|
||||
tc.setup(t)
|
||||
out, _, _ := capture(func() {
|
||||
newApp().Run([]string{"", "root"})
|
||||
newApp().Run(context.Background(), []string{"", "root"})
|
||||
})
|
||||
if !samePaths(out, tc.expect) {
|
||||
t.Errorf("got: %s, expect: %s", out, tc.expect)
|
||||
}
|
||||
out, _, _ = capture(func() {
|
||||
newApp().Run([]string{"", "root", "--all"})
|
||||
newApp().Run(context.Background(), []string{"", "root", "--all"})
|
||||
})
|
||||
if !samePaths(out, tc.allExpect) {
|
||||
t.Errorf("got: %s, expect: %s", out, tc.allExpect)
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
var commands = []*cli.Command{
|
||||
|
|
@ -44,7 +45,7 @@ var commandGet = &cli.Command{
|
|||
&cli.StringFlag{
|
||||
Name: "partial",
|
||||
Usage: "Do a partial clone. Can specify either \"blobless\" or \"treeless\"",
|
||||
Action: func(ctx *cli.Context, v string) error {
|
||||
Action: func(ctx context.Context, cmd *cli.Command, v string) error {
|
||||
expected := []string{"blobless", "treeless"}
|
||||
if !slices.Contains(expected, v) {
|
||||
return fmt.Errorf("flag partial value \"%v\" is not allowed", v)
|
||||
|
|
|
|||
13
go.mod
13
go.mod
|
|
@ -8,9 +8,9 @@ require (
|
|||
github.com/motemen/go-colorine v0.0.0-20180816141035-45d19169413a
|
||||
github.com/otiai10/copy v1.14.1
|
||||
github.com/saracen/walker v0.1.4
|
||||
github.com/urfave/cli/v2 v2.27.7
|
||||
golang.org/x/net v0.50.0
|
||||
golang.org/x/sync v0.19.0
|
||||
github.com/urfave/cli/v3 v3.7.0
|
||||
golang.org/x/net v0.52.0
|
||||
golang.org/x/sync v0.20.0
|
||||
)
|
||||
|
||||
require (
|
||||
|
|
@ -21,12 +21,9 @@ require (
|
|||
|
||||
require (
|
||||
github.com/cli/safeexec v1.0.1 // indirect
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.7 // indirect
|
||||
github.com/daviddengcn/go-colortext v1.0.0 // indirect
|
||||
github.com/goccy/go-yaml v1.19.2 // indirect
|
||||
github.com/russross/blackfriday/v2 v2.1.0 // indirect
|
||||
github.com/xrash/smetrics v0.0.0-20250705151800-55b8f293f342 // indirect
|
||||
golang.org/x/sys v0.41.0 // indirect
|
||||
golang.org/x/text v0.34.0
|
||||
golang.org/x/sys v0.42.0 // indirect
|
||||
golang.org/x/text v0.35.0
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
)
|
||||
|
|
|
|||
30
go.sum
30
go.sum
|
|
@ -4,8 +4,6 @@ github.com/cli/go-gh/v2 v2.13.0 h1:jEHZu/VPVoIJkciK3pzZd3rbT8J90swsK5Ui4ewH1ys=
|
|||
github.com/cli/go-gh/v2 v2.13.0/go.mod h1:Us/NbQ8VNM0fdaILgoXSz6PKkV5PWaEzkJdc9vR2geM=
|
||||
github.com/cli/safeexec v1.0.1 h1:e/C79PbXF4yYTN/wauC4tviMxEV13BwljGj0N9j+N00=
|
||||
github.com/cli/safeexec v1.0.1/go.mod h1:Z/D4tTN8Vs5gXYHDCbaM1S/anmEDnJb1iW0+EJ5zx3Q=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.7 h1:zbFlGlXEAKlwXpmvle3d8Oe3YnkKIK4xSRTd3sHPnBo=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.7/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
|
||||
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
|
|
@ -32,25 +30,21 @@ github.com/otiai10/mint v1.6.3 h1:87qsV/aw1F5as1eH1zS/yqHY85ANKVMgkDrf9rcxbQs=
|
|||
github.com/otiai10/mint v1.6.3/go.mod h1:MJm72SBthJjz8qhefc4z1PYEieWmy8Bku7CjcAqyUSM=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
|
||||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||
github.com/saracen/walker v0.1.4 h1:/WCOt98GRkQ0KgL6hXJFBpoH21XY6iCD2N6LQWBFiaU=
|
||||
github.com/saracen/walker v0.1.4/go.mod h1:2F+hfOidTHfXP2AmlKOqpO+yewf8fIvNUDBNJogpJbk=
|
||||
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/urfave/cli/v2 v2.27.7 h1:bH59vdhbjLv3LAvIu6gd0usJHgoTTPhCFib8qqOwXYU=
|
||||
github.com/urfave/cli/v2 v2.27.7/go.mod h1:CyNAG/xg+iAOg0N4MPGZqVmv2rCoP267496AOXUZjA4=
|
||||
github.com/xrash/smetrics v0.0.0-20250705151800-55b8f293f342 h1:FnBeRrxr7OU4VvAzt5X7s6266i6cSVkkFPS0TuXWbIg=
|
||||
github.com/xrash/smetrics v0.0.0-20250705151800-55b8f293f342/go.mod h1:Ohn+xnUBiLI6FVj/9LpzZWtj1/D6lUovWYBkxHVV3aM=
|
||||
golang.org/x/net v0.50.0 h1:ucWh9eiCGyDR3vtzso0WMQinm2Dnt8cFMuQa9K33J60=
|
||||
golang.org/x/net v0.50.0/go.mod h1:UgoSli3F/pBgdJBHCTc+tp3gmrU4XswgGRgtnwWTfyM=
|
||||
golang.org/x/sync v0.19.0 h1:vV+1eWNmZ5geRlYjzm2adRgW2/mcpevXNg50YZtPCE4=
|
||||
golang.org/x/sync v0.19.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
|
||||
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
|
||||
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
|
||||
github.com/urfave/cli/v3 v3.7.0 h1:AGSnbUyjtLiM+WJUb4dzXKldl/gL+F8OwmRDtVr6g2U=
|
||||
github.com/urfave/cli/v3 v3.7.0/go.mod h1:ysVLtOEmg2tOy6PknnYVhDoouyC/6N42TMeoMzskhso=
|
||||
golang.org/x/net v0.52.0 h1:He/TN1l0e4mmR3QqHMT2Xab3Aj3L9qjbhRm78/6jrW0=
|
||||
golang.org/x/net v0.52.0/go.mod h1:R1MAz7uMZxVMualyPXb+VaqGSa3LIaUqk0eEt3w36Sw=
|
||||
golang.org/x/sync v0.20.0 h1:e0PTpb7pjO8GAtTs2dQ6jYa5BWYlMuX047Dco/pItO4=
|
||||
golang.org/x/sync v0.20.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.41.0 h1:Ivj+2Cp/ylzLiEU89QhWblYnOE9zerudt9Ftecq2C6k=
|
||||
golang.org/x/sys v0.41.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
|
||||
golang.org/x/text v0.34.0 h1:oL/Qq0Kdaqxa1KbNeMKwQq0reLCCaFtqu2eNuSeNHbk=
|
||||
golang.org/x/text v0.34.0/go.mod h1:homfLqTYRFyVYemLBFl5GgL/DWEiH5wcsQ5gSh1yziA=
|
||||
golang.org/x/sys v0.42.0 h1:omrd2nAlyT5ESRdCLYdm3+fMfNFE/+Rf4bDIQImRJeo=
|
||||
golang.org/x/sys v0.42.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
|
||||
golang.org/x/text v0.35.0 h1:JOVx6vVDFokkpaq1AEptVzLTpDe9KGpj5tR4/X+ybL8=
|
||||
golang.org/x/text v0.35.0/go.mod h1:khi/HExzZJ2pGnjenulevKNX1W67CUy0AsXcNubPGCA=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
|
|
|
|||
28
main.go
28
main.go
|
|
@ -1,10 +1,11 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
"github.com/x-motemen/ghq/logger"
|
||||
)
|
||||
|
||||
|
|
@ -13,7 +14,7 @@ const version = "1.9.4"
|
|||
var revision = "HEAD"
|
||||
|
||||
func main() {
|
||||
if err := newApp().Run(os.Args); err != nil {
|
||||
if err := newApp().Run(context.Background(), os.Args); err != nil {
|
||||
exitCode := 1
|
||||
if excoder, ok := err.(cli.ExitCoder); ok {
|
||||
exitCode = excoder.ExitCode()
|
||||
|
|
@ -23,18 +24,13 @@ func main() {
|
|||
}
|
||||
}
|
||||
|
||||
func newApp() *cli.App {
|
||||
app := cli.NewApp()
|
||||
app.Name = "ghq"
|
||||
app.Usage = "Manage remote repository clones"
|
||||
app.Version = fmt.Sprintf("%s (rev:%s)", version, revision)
|
||||
app.Authors = []*cli.Author{{
|
||||
Name: "motemen",
|
||||
Email: "motemen@gmail.com",
|
||||
}, {
|
||||
Name: "Songmu",
|
||||
Email: "y.songmu@gmail.com",
|
||||
}}
|
||||
app.Commands = commands
|
||||
return app
|
||||
func newApp() *cli.Command {
|
||||
return &cli.Command{
|
||||
Name: "ghq",
|
||||
Usage: "Manage remote repository clones",
|
||||
Version: fmt.Sprintf("%s (rev:%s)", version, revision),
|
||||
Authors: []any{"motemen <motemen@gmail.com>", "Songmu <y.songmu@gmail.com>"},
|
||||
Suggest: true,
|
||||
Commands: commands,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,6 +48,7 @@ complete -c ghq -n '__fish_seen_subcommand_from list' -s p -l full-path -d 'Prin
|
|||
complete -c ghq -n '__fish_seen_subcommand_from list' -l unique -d 'Print unique subpaths'
|
||||
|
||||
complete -c ghq -n '__fish_seen_subcommand_from rm' -l dry-run -d 'Do not remove actually'
|
||||
complete -c ghq -n '__fish_seen_subcommand_from rm' -xa '(ghq list)'
|
||||
|
||||
complete -c ghq -n '__fish_seen_subcommand_from root' -l all -d 'Show all roots'
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#compdef ghq
|
||||
#compdef ghq ghq-dev
|
||||
|
||||
function _ghq () {
|
||||
local context curcontext=$curcontext state line
|
||||
|
|
@ -37,6 +37,7 @@ function _ghq () {
|
|||
'--vcs[Specify vcs backend for matching]' \
|
||||
'(-p --full-path)'{-p,--full-path}'[Print full paths]' \
|
||||
'--unique[Print unique subpaths]' \
|
||||
'--bare[Query bare repositories]' \
|
||||
'(-)*:: :->null_state' \
|
||||
&& ret=0
|
||||
;;
|
||||
|
|
@ -49,13 +50,22 @@ function _ghq () {
|
|||
(create)
|
||||
_arguments -C \
|
||||
'--vcs[Specify vcs backend explicitly]' \
|
||||
'--bare[Create a bare repository]' \
|
||||
'(-)*:: :->null_state' \
|
||||
&& ret=0
|
||||
;;
|
||||
(rm)
|
||||
_arguments -C \
|
||||
'--dry-run[Do not remove actually]' \
|
||||
'(-)*:: :->null_state' \
|
||||
'--bare[Remove a bare repository]' \
|
||||
'(-)*: :__ghq_all_repositories' \
|
||||
&& ret=0
|
||||
;;
|
||||
(migrate)
|
||||
_arguments -C \
|
||||
'-y[Skip confirmation prompt]' \
|
||||
'--dry-run[Show what would happen without moving]' \
|
||||
':repository directory:_directories' \
|
||||
&& ret=0
|
||||
;;
|
||||
(help|h)
|
||||
|
|
@ -74,12 +84,20 @@ __ghq_repositories () {
|
|||
_describe -t repositories Repositories _repos
|
||||
}
|
||||
|
||||
__ghq_all_repositories () {
|
||||
local -a _repos
|
||||
_repos=( ${(@f)"$(_call_program repositories ghq list)"} )
|
||||
_describe -t repositories Repositories _repos
|
||||
}
|
||||
|
||||
__ghq_commands () {
|
||||
local -a _c
|
||||
_c=(
|
||||
'get:Clone/sync with a remote repository'
|
||||
'list:List local repositories'
|
||||
'rm:Remove local repository'
|
||||
'create:Create a new repository'
|
||||
'migrate:Migrate existing repository to ghq-managed directory'
|
||||
"root:Show repositories' root"
|
||||
'help:Show a list of commands or help for one command'
|
||||
)
|
||||
|
|
|
|||
5
url.go
5
url.go
|
|
@ -139,7 +139,12 @@ func newURL(ref string, ssh, forceMe bool) (*url.URL, error) {
|
|||
}
|
||||
}
|
||||
u.Scheme = "https"
|
||||
host, err := gitconfig.Get("ghq.defaultHost")
|
||||
if (err != nil && !gitconfig.IsNotFound(err)) || host != "" {
|
||||
u.Host = host
|
||||
} else {
|
||||
u.Host = "github.com"
|
||||
}
|
||||
if u.Path[0] != '/' {
|
||||
u.Path = "/" + u.Path
|
||||
}
|
||||
|
|
|
|||
|
|
@ -66,6 +66,15 @@ completeUser = false`))
|
|||
url: "peco",
|
||||
expect: "https://github.com/peco/peco",
|
||||
host: "github.com",
|
||||
}, {
|
||||
name: "configured default host",
|
||||
setup: func(t *testing.T) {
|
||||
t.Cleanup(gitconfig.WithConfig(t, `[ghq]
|
||||
defaultHost = gitlab.com`))
|
||||
},
|
||||
url: "gnuwget/wget2",
|
||||
expect: "https://gitlab.com/gnuwget/wget2",
|
||||
host: "gitlab.com",
|
||||
}}
|
||||
|
||||
for _, tc := range testCases {
|
||||
|
|
|
|||
Loading…
Reference in a new issue