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/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/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..c2cabb3 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,24 @@ 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, + ] + if command.blobless_clone: + cmd_fetch_hash.append('--filter=blob:none') + 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']