We have to programmatically detect whether a Git repository is (still) being cloned or cloning has already been completed and the repository is usable. In the ideal case, this detection should be possible just from looking at the current file system state of the repository without having any additional information (e.g. whether a clone has actually been started for the repository before). With other words, I'm looking for some file/flag in Git's admin area which is set exactly while the repository is cloning.
-
1Can you try running `fuser` on the top level directory (it returns the list of pids holding it open). If `git clone` is one of them then you know it's still in progress. If it worked I can make it an answer :-) – bobah Oct 04 '18 at 08:44
-
Are you asking about client side (new repository) or server side (origin repository)? On the server side there is no such flag — cloning process doesn't write to the server file system. – phd Oct 04 '18 at 12:12
-
@bobah Sorry, but that's not what I'm looking/hoping for: " just from looking at the current file system state". – mstrap Oct 04 '18 at 17:49
-
@phd I'm interested in the client side. Maybe .git/objects contains some specific temp files during the clone process ... maybe some other directory ... so you get an idea of what I'm looking for. The detection should be reliable, though. – mstrap Oct 04 '18 at 17:50
1 Answers
On the client side it's a bit simpler. First, during cloning there are no files in the worktree — there is only .git/
subdirectory; git populates the worktree at the very end of cloning process. .git/
directory has many empty subdirectories. In the directory .git/objects/pack/
there is a file tmp_pack_XXX
where XXX
is a random suffix.
But I think you don't need any of that. You can just track git clone
starting and stopping. Either you run some before-install; git clone; after-install
scripts or replace git-clone
binary (symlink, to be precise) with your own script that will run before-clone
and after-clone
scripts and you can do whatever you want in these scripts.
Another possibility: with git clone --template
you can setup a post-checkout
hook that will be run after cloning.

- 82,685
- 13
- 120
- 165