Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions test/import.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 2 additions & 0 deletions test/import_blobless.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion test/reimport_force.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
29 changes: 27 additions & 2 deletions vcs2l/clients/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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
Expand Down Expand Up @@ -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']
Expand Down