Skip to content

Shallow clone? #269

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

Closed
ghost opened this issue Mar 7, 2015 · 9 comments
Closed

Shallow clone? #269

ghost opened this issue Mar 7, 2015 · 9 comments

Comments

@ghost
Copy link

ghost commented Mar 7, 2015

hi!

I am using GitPython for a personal project and I want to clone repositories on behalf of user but this takes very long time if repos are huge. I am unable to shallow clone because the -- chars are removed when I run the clone method.

GitCommandError: 'git clone --depth 1 https://github.com/scrollback/argent.git' returned with exit code 129
stderr: 'error: unknown option `depth 1 https://github.com/scrollback/argent.git'

What is a workaround for this?
Thanks!

@Byron
Copy link
Member

Byron commented Mar 7, 2015

Could it be that your installed git version is too old and doesn't support the 'depth' flag ? What happens if you execute git clone --depth 1 https://github.com/scrollback/argent.git yourself, in a shell ?

@ghost
Copy link
Author

ghost commented Mar 7, 2015

I am able to shallow clone in terminal. What would you say is the correct syntax to shallow clone using GitPython's clone method? (just so we are clear) Thanks!

@Byron
Copy link
Member

Byron commented Mar 8, 2015

The syntax I used is the correct one, which is the same that git-python uses.

NAME
       git-clone - Clone a repository into a new directory

SYNOPSIS
       git clone [--template=<template_directory>]
                 [-l] [-s] [--no-hardlinks] [-q] [-n] [--bare] [--mirror]
                 [-o <name>] [-b <name>] [-u <upload-pack>] [--reference <repository>]
                 [--separate-git-dir <git dir>]
                 [--depth <depth>] [--[no-]single-branch]
                 [--recursive | --recurse-submodules] [--] <repository>
                 [<directory>]

When interpreting the error stderr: 'error: unknown option 'depth 1 https://github.com/scrollback/argent.git' correctly, it seems that for some reason, the shell is handing multiple arguments as one.

What does your git-python code look like ?

@ghost
Copy link
Author

ghost commented Mar 8, 2015

Thanks for looking into this. I will try to explain whats happening on my side.
I have this code:

import git
git.Git().clone(clone_url, potential_repo)

Where clone_url is a string "https://github.com/scrollback/argent.git"
I know git.Git().clone() is equivalent to git clone ...
and so adding a string "--depth 1 https://github.com/scrollback/argent.git" should execute as "git clone --depth 1 https://github.com/scrollback/argent.git" but something about clone or GitPython Git class is removing the hyphens and thus the command gets interpretted as "git clone depth https://github.com/scrollback/argent.git".

How can I fix this?

@Byron
Copy link
Member

Byron commented Mar 8, 2015

If you want to use git directly, you have to pass each argument individually. The call you want would be

git.Git().clone(clone_url, to_directory, depth=1)

Besides, I'd recommend not to use the git command directly unless you have to. A more pythonic way to achieve the same would be this:

repo = git.Repo.clone_from(clone_url, to_directory, depth=1)

repo is the hub from which you can do pretty much everything - have a look at the docs for much more information.

Also I't be grateful if you would prefer to ask questions on Stackoverflow instead, just use the GitPython tag and you will be helped.

Thanks

@Byron Byron closed this as completed Mar 8, 2015
@ghost
Copy link
Author

ghost commented Mar 8, 2015

Oh! I wasn't aware that additional arguments are to be passed with clone method itself. Thanks for clearing this up! Noted about using Repo class and stackoverflow. Thanks so much! 👍

@zhimsel
Copy link

zhimsel commented Aug 2, 2018

@Byron sorry to drag up an old thread, but where is the depth argument in the docs? https://gitpython.readthedocs.io/en/stable/search.html?q=depth&check_keywords=yes&area=default

@Byron
Copy link
Member

Byron commented Aug 5, 2018

@zhimsel Could it be one of the kwargs which are automatically passed down as arguments to the git command-line?

@zhimsel
Copy link

zhimsel commented Aug 6, 2018

@Byron ah, you know what, you're probably right. I must have not notice that part where all kwargs are passed to the git command. That makes a lot more sense. I sometimes forget that GitPython is more a wrapper around commandline git than a more direct library (and that's fine).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants