Skip to content

Commit 8c661f1

Browse files
Enable git fetch for non-shallow clones with commit hashes.
Signed-off-by: Leander Stephen D'Souza <leanderdsouza1234@gmail.com>
1 parent 3d0f2f9 commit 8c661f1

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

test/import.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
......
22
=== ./immutable/hash (git) ===
33
Cloning into '.'...
4+
From file:///vcstmp/gitrepo
5+
* branch 5b3504594f7354121cf024dc734bf79e270cffd3 -> FETCH_HEAD
46
Note: switching to '5b3504594f7354121cf024dc734bf79e270cffd3'.
57

68
You are in 'detached HEAD' state. You can look around, make experimental

test/reimport_force.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
......
22
=== ./immutable/hash (git) ===
3-
3+
From file:///vcstmp/gitrepo
4+
* branch 5b3504594f7354121cf024dc734bf79e270cffd3 -> FETCH_HEAD
45
HEAD is now at 5b35045... update changelog
56
=== ./immutable/hash_tar (tar) ===
67
Downloaded tarball from 'file:///vcstmp/archive.tar.gz' and unpacked it

vcs2l/clients/git.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,13 +323,18 @@ def import_(self, command):
323323

324324
# fetch updates for existing repo
325325
cmd_fetch = [GitClient._executable, 'fetch', remote]
326-
if command.shallow:
326+
327+
# Determine version type for both shallow and non-shallow modes
328+
version_type, version_name = None, None
329+
if checkout_version is not None:
327330
result_version_type, version_name = self._check_version_type(
328331
command.url, checkout_version, command.retry
329332
)
330333
if result_version_type['returncode']:
331334
return result_version_type
332335
version_type = result_version_type['version_type']
336+
337+
if command.shallow:
333338
if version_type == 'branch':
334339
cmd_fetch.append(
335340
'refs/heads/%s:refs/remotes/%s/%s'
@@ -345,7 +350,9 @@ def import_(self, command):
345350
assert False
346351
cmd_fetch += ['--depth', '1']
347352
else:
348-
version_type = None
353+
# For non-shallow mode, only fetch specific commit hashes
354+
if version_type == 'hash':
355+
cmd_fetch.append(checkout_version)
349356
result_fetch = self._run_command(cmd_fetch, retry=command.retry)
350357
if result_fetch['returncode']:
351358
return result_fetch
@@ -422,6 +429,22 @@ def import_(self, command):
422429
return result_clone
423430
cmd = result_clone['cmd']
424431
output = result_clone['output']
432+
433+
# For non-shallow clones with commit hashes, fetch the specific commit
434+
if not command.shallow and version_type == 'hash':
435+
cmd_fetch_hash = [
436+
GitClient._executable,
437+
'fetch',
438+
'origin',
439+
command.version,
440+
]
441+
result_fetch_hash = self._run_command(
442+
cmd_fetch_hash, retry=command.retry
443+
)
444+
if result_fetch_hash['returncode']:
445+
return result_fetch_hash
446+
cmd += ' && ' + ' '.join(cmd_fetch_hash)
447+
output = '\n'.join([output, result_fetch_hash['output']])
425448
else:
426449
# getting a hash or tag with a depth of 1 can't use 'clone'
427450
cmd_init = [GitClient._executable, 'init']

0 commit comments

Comments
 (0)