Is it possible to specify a timeout for `git clone` operation?

Viewed 4309

I use git clone in scripts, and I want to timeout the operation, if it takes longer than, say, N minutes to complet.

The reason is that some repositories are more than 5GB in size (even with --depth 1), which can take more than 30 minutes to download, depending on the load. I want to ignore these repositories.

Since git provides no way to check the size of a repository before cloning, the only solution I can think of is to specify a timeout for git clone. Is that possible?

1 Answers

I suggest a method:

  1. git clone with --depth 1 or clone single branch: git clone [remote url] --branch [branch_name] --single-branch [folder] (if needed)

  2. Get output of clone command, ex:

    Cloning into 'www-gitlab-com'... .....

    Receiving objects: 1% (123/624541), 74.61 MiB | 8.14 MiB/s, done.

  3. You can watch command output for a seconds, and if you see "1% ... 1.2 GiB" you know you're in trouble with large repo, and you can cancel it

Related