forked from git-lfs/git-lfs
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
161 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package commands | ||
|
||
import ( | ||
"os" | ||
"path" | ||
"path/filepath" | ||
"strings" | ||
|
||
"github.com/github/git-lfs/git" | ||
"github.com/github/git-lfs/lfs" | ||
"github.com/github/git-lfs/vendor/_nuts/github.com/spf13/cobra" | ||
) | ||
|
||
var ( | ||
cloneCmd = &cobra.Command{ | ||
Use: "clone", | ||
Run: cloneCommand, | ||
} | ||
) | ||
|
||
func cloneCommand(cmd *cobra.Command, args []string) { | ||
|
||
// We pass all args to git clone | ||
err := git.CloneWithoutFilters(args) | ||
if err != nil { | ||
Panic(err, "Error(s) during clone") | ||
} | ||
|
||
// now execute pull (need to be inside dir) | ||
cwd, err := os.Getwd() | ||
if err != nil { | ||
Panic(err, "Unable to derive current working dir") | ||
} | ||
|
||
// Either the last argument was a relative or local dir, or we have to | ||
// derive it from the clone URL | ||
clonedir, err := filepath.Abs(args[len(args)-1]) | ||
if err != nil || !lfs.DirExists(clonedir) { | ||
// Derive from clone URL instead | ||
base := path.Base(args[len(args)-1]) | ||
if strings.HasSuffix(base, ".git") { | ||
base = base[:len(base)-4] | ||
} | ||
clonedir, _ = filepath.Abs(base) | ||
if !lfs.DirExists(clonedir) { | ||
Exit("Unable to find clone dir at %q", clonedir) | ||
} | ||
} | ||
|
||
err = os.Chdir(clonedir) | ||
if err != nil { | ||
Panic(err, "Unable to change directory to clone dir %q", clonedir) | ||
} | ||
|
||
// Make sure we pop back to dir we started in at the end | ||
defer os.Chdir(cwd) | ||
|
||
// Also need to derive dirs now | ||
lfs.ResolveDirs() | ||
requireInRepo() | ||
|
||
// Now just call pull with default args | ||
lfs.Config.CurrentRemote = "origin" // always origin after clone | ||
pull(nil, nil) | ||
|
||
} | ||
|
||
func init() { | ||
RootCmd.AddCommand(cloneCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
git-lfs-clone(1) -- Efficiently clone a LFS-enabled repository | ||
======================================================================== | ||
|
||
## SYNOPSIS | ||
|
||
`git lfs clone` [git clone options] <repository> [<directory>] | ||
|
||
## DESCRIPTION | ||
|
||
Clone an LFS enabled Git repository more efficiently by disabling LFS during the | ||
git clone, then performing a 'git lfs pull' directly afterwards. | ||
|
||
This is faster than a regular 'git clone' because that will download LFS content | ||
using the smudge filter, which is executed individually per file in the working | ||
copy. This is relatively inefficient compared to the batch mode and parallel | ||
downloads performed by 'git lfs pull'. | ||
|
||
## OPTIONS | ||
|
||
All options supported by 'git clone' | ||
|
||
## SEE ALSO | ||
|
||
git-clone(1), git-lfs-pull(1). | ||
|
||
Part of the git-lfs(1) suite. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters