From cec211c6e3f90f45a455c81b994c2d38e70312d3 Mon Sep 17 00:00:00 2001 From: Leander Stephen D'Souza Date: Mon, 10 Nov 2025 15:27:57 +0000 Subject: [PATCH 1/2] Enable git fetch for non-shallow clones with commit hashes. Signed-off-by: Leander Stephen D'Souza --- test/import.txt | 2 ++ test/reimport_force.txt | 3 ++- vcs2l/clients/git.py | 27 +++++++++++++++++++++++++-- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/test/import.txt b/test/import.txt index 95523e2..70a47f8 100644 --- a/test/import.txt +++ b/test/import.txt @@ -1,6 +1,8 @@ ...... === ./immutable/hash (git) === Cloning into '.'... +From file:///vcstmp/gitrepo + * branch 5b3504594f7354121cf024dc734bf79e270cffd3 -> FETCH_HEAD Note: switching to '5b3504594f7354121cf024dc734bf79e270cffd3'. You are in 'detached HEAD' state. You can look around, make experimental diff --git a/test/reimport_force.txt b/test/reimport_force.txt index 791a028..2fd7799 100644 --- a/test/reimport_force.txt +++ b/test/reimport_force.txt @@ -1,6 +1,7 @@ ...... === ./immutable/hash (git) === - +From file:///vcstmp/gitrepo + * branch 5b3504594f7354121cf024dc734bf79e270cffd3 -> FETCH_HEAD HEAD is now at 5b35045... update changelog === ./immutable/hash_tar (tar) === Downloaded tarball from 'file:///vcstmp/archive.tar.gz' and unpacked it diff --git a/vcs2l/clients/git.py b/vcs2l/clients/git.py index 4026f4c..83e47b1 100644 --- a/vcs2l/clients/git.py +++ b/vcs2l/clients/git.py @@ -331,13 +331,18 @@ def import_(self, command): cmd_fetch = [GitClient._executable, 'fetch', remote] if command.blobless_clone: cmd_fetch.append('--filter=blob:none') - if command.shallow: + + # Determine version type for both shallow and non-shallow modes + version_type, version_name = None, None + if checkout_version is not None: result_version_type, version_name = self._check_version_type( command.url, checkout_version, command.retry ) if result_version_type['returncode']: return result_version_type version_type = result_version_type['version_type'] + + if command.shallow: if version_type == 'branch': cmd_fetch.append( 'refs/heads/%s:refs/remotes/%s/%s' @@ -353,7 +358,9 @@ def import_(self, command): assert False cmd_fetch += ['--depth', '1'] else: - version_type = None + # For non-shallow mode, only fetch specific commit hashes + if version_type == 'hash': + cmd_fetch.append(checkout_version) result_fetch = self._run_command(cmd_fetch, retry=command.retry) if result_fetch['returncode']: return result_fetch @@ -440,6 +447,22 @@ def import_(self, command): return result_clone cmd = result_clone['cmd'] output = result_clone['output'] + + # For non-shallow clones with commit hashes, fetch the specific commit + if not command.shallow and version_type == 'hash': + cmd_fetch_hash = [ + GitClient._executable, + 'fetch', + 'origin', + command.version, + ] + result_fetch_hash = self._run_command( + cmd_fetch_hash, retry=command.retry + ) + if result_fetch_hash['returncode']: + return result_fetch_hash + cmd += ' && ' + ' '.join(cmd_fetch_hash) + output = '\n'.join([output, result_fetch_hash['output']]) else: # getting a hash or tag with a depth of 1 can't use 'clone' cmd_init = [GitClient._executable, 'init'] From 1fef30fffc0551346b8f03696df20856e1f6484f Mon Sep 17 00:00:00 2001 From: Leander Stephen D'Souza Date: Fri, 6 Mar 2026 20:28:40 +0000 Subject: [PATCH 2/2] Add support for blobless clone. Signed-off-by: Leander Stephen D'Souza --- test/import_blobless.txt | 2 ++ vcs2l/clients/git.py | 2 ++ 2 files changed, 4 insertions(+) diff --git a/test/import_blobless.txt b/test/import_blobless.txt index b461059..d97981e 100644 --- a/test/import_blobless.txt +++ b/test/import_blobless.txt @@ -2,6 +2,8 @@ === ./immutable/hash (git) === Cloning into '.'... warning: filtering not recognized by server, ignoring +From file:///vcstmp/gitrepo + * branch 5b3504594f7354121cf024dc734bf79e270cffd3 -> FETCH_HEAD Note: switching to '5b3504594f7354121cf024dc734bf79e270cffd3'. You are in 'detached HEAD' state. You can look around, make experimental diff --git a/vcs2l/clients/git.py b/vcs2l/clients/git.py index 83e47b1..c2cabb3 100644 --- a/vcs2l/clients/git.py +++ b/vcs2l/clients/git.py @@ -456,6 +456,8 @@ def import_(self, command): 'origin', command.version, ] + if command.blobless_clone: + cmd_fetch_hash.append('--filter=blob:none') result_fetch_hash = self._run_command( cmd_fetch_hash, retry=command.retry )