Skip to content

repo: add depth option when clone #64

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,19 @@ jobs:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Checkout code
uses: actions/checkout@v2
- name: Run golangci-lint
uses: actions-contrib/golangci-lint@v1
uses: golangci/golangci-lint-action@v2
with:
version: latest
args: --timeout=30m

test:
name: Test
strategy:
matrix:
go-version: [1.14.x, 1.15.x]
go-version: [1.14.x, 1.15.x, 1.16.x]
platform: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.platform }}
steps:
Expand Down
5 changes: 5 additions & 0 deletions repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ type CloneOptions struct {
Quiet bool
// The branch to checkout for the working tree when Bare=false.
Branch string
// The number of revisions to clone.
Depth uint64
// The timeout duration before giving up for each shell command execution.
// The default timeout duration will be used when not supplied.
Timeout time.Duration
Expand Down Expand Up @@ -139,6 +141,9 @@ func Clone(url, dst string, opts ...CloneOptions) error {
if !opt.Bare && opt.Branch != "" {
cmd.AddArgs("-b", opt.Branch)
}
if opt.Depth > 0 {
cmd.AddArgs("--depth", strconv.FormatUint(opt.Depth, 10))
}

_, err = cmd.AddArgs(url, dst).RunWithTimeout(opt.Timeout)
return err
Expand Down
4 changes: 3 additions & 1 deletion repo_remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ func RepoRemoveRemote(repoPath, name string, opts ...RemoveRemoteOptions) error

_, err := NewCommand("remote", "remove", name).RunInDirWithTimeout(opt.Timeout, repoPath)
if err != nil {
if strings.Contains(err.Error(), "fatal: No such remote") {
// the error status may differ from git clients
if strings.Contains(err.Error(), "error: No such remote") ||
strings.Contains(err.Error(), "fatal: No such remote") {
return ErrRemoteNotExist
}
return err
Expand Down
11 changes: 11 additions & 0 deletions repo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,17 @@ func TestClone(t *testing.T) {
Branch: "develop",
},
},
{
opt: CloneOptions{
Depth: 1,
},
},
{
opt: CloneOptions{
Branch: "develop",
Depth: 1,
},
},
}
for _, test := range tests {
t.Run("", func(t *testing.T) {
Expand Down