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
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
6 changes: 6 additions & 0 deletions test/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import sys
import unittest
from io import StringIO
from shutil import which

import vcs2l.executor as executor
from vcs2l.clients.git import GitClient
Expand All @@ -19,6 +20,10 @@
os.path.dirname(os.path.dirname(__file__)), 'test_workspace'
)

svn = which('svn')
svnadmin = which('svnadmin')
hg = which('hg')


class TestCommands(StagedReposFile):
@classmethod
Expand Down Expand Up @@ -354,6 +359,7 @@ def test_status(self):
self.assertEqual(output, expected)


@unittest.skipIf(not svn or not svnadmin or not hg, 'svn or hg was not found')
class TestCommands2(StagedReposFile2):
@classmethod
def setUpClass(cls):
Expand Down
27 changes: 25 additions & 2 deletions vcs2l/clients/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,13 +323,18 @@ def import_(self, command):

# fetch updates for existing repo
cmd_fetch = [GitClient._executable, 'fetch', remote]
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 @@ -345,7 +350,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 @@ -422,6 +429,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']
Expand Down
Loading