Skip to content
Merged
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
6 changes: 3 additions & 3 deletions dfetch/commands/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
from dfetch.commands.common import check_child_manifests
from dfetch.log import get_logger
from dfetch.manifest.manifest import Manifest
from dfetch.project.superproject import SuperProject
from dfetch.project import create_super_project
from dfetch.reporting.check.code_climate_reporter import CodeClimateReporter
from dfetch.reporting.check.jenkins_reporter import JenkinsReporter
from dfetch.reporting.check.reporter import CheckReporter
Expand Down Expand Up @@ -90,14 +90,14 @@ def create_menu(subparsers: dfetch.commands.command.SubparserActionType) -> None

def __call__(self, args: argparse.Namespace) -> None:
"""Perform the check."""
superproject = SuperProject()
superproject = create_super_project()
reporters = self._get_reporters(args, superproject.manifest)

with in_directory(superproject.root_directory):
exceptions: list[str] = []
for project in superproject.manifest.selected_projects(args.projects):
with catch_runtime_exceptions(exceptions) as exceptions:
dfetch.project.make(project).check_for_update(
dfetch.project.create_sub_project(project).check_for_update(
reporters,
files_to_ignore=superproject.ignored_files(project.destination),
)
Expand Down
27 changes: 19 additions & 8 deletions dfetch/commands/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@

import dfetch.commands.command
from dfetch.log import get_logger
from dfetch.project import create_super_project
from dfetch.project.metadata import Metadata
from dfetch.project.superproject import SuperProject
from dfetch.project.superproject import NoVcsSuperProject, RevisionRange
from dfetch.util.util import catch_runtime_exceptions, in_directory

logger = get_logger(__name__)
Expand Down Expand Up @@ -96,9 +97,14 @@ def create_menu(subparsers: dfetch.commands.command.SubparserActionType) -> None

def __call__(self, args: argparse.Namespace) -> None:
"""Perform the diff."""
superproject = SuperProject()
superproject = create_super_project()
old_rev, new_rev = self._parse_revs(args.revs)

if isinstance(superproject, NoVcsSuperProject):
raise RuntimeError(
"Can only create patch if your project is an SVN or Git repo",
)

with in_directory(superproject.root_directory):
exceptions: list[str] = []
projects = superproject.manifest.selected_projects(args.projects)
Expand All @@ -114,18 +120,23 @@ def __call__(self, args: argparse.Namespace) -> None:
)
subproject = superproject.get_sub_project(project)

if subproject is None:
raise RuntimeError(
"Can only create patch if your project is an SVN or Git repo",
)
old_rev = old_rev or subproject.metadata_revision()
if not subproject:
raise RuntimeError("No subproject!")

old_rev = old_rev or superproject.get_file_revision(
subproject.metadata_path
)
if not old_rev:
raise RuntimeError(
"When not providing any revisions, dfetch starts from"
f" the last revision to {Metadata.FILENAME} in {subproject.local_path}."
" Please either commit this, or specify a revision to start from with --revs"
)
patch = subproject.diff(old_rev, new_rev)
patch = superproject.diff(
project.destination,
revisions=RevisionRange(old_rev, new_rev),
ignore=(Metadata.FILENAME,),
)

msg = self._rev_msg(old_rev, new_rev)
if patch:
Expand Down
4 changes: 2 additions & 2 deletions dfetch/commands/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import dfetch.commands.command
from dfetch.log import get_logger
from dfetch.project import SUPPORTED_PROJECT_TYPES
from dfetch.project import SUPPORTED_SUBPROJECT_TYPES

logger = get_logger(__name__)

Expand All @@ -26,5 +26,5 @@ def __call__(self, _: argparse.Namespace) -> None:
logger.print_report_line(
"platform", f"{platform.system()} {platform.release()}"
)
for project_type in SUPPORTED_PROJECT_TYPES:
for project_type in SUPPORTED_SUBPROJECT_TYPES:
project_type.list_tool_info()
6 changes: 3 additions & 3 deletions dfetch/commands/format_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import dfetch.manifest.project
import dfetch.project
from dfetch.log import get_logger
from dfetch.project.superproject import SuperProject
from dfetch.project import create_super_project
from dfetch.util.util import catch_runtime_exceptions, in_directory
from dfetch.vcs.patch import PatchAuthor, PatchInfo, add_prefix_to_patch

Expand Down Expand Up @@ -69,7 +69,7 @@ def create_menu(subparsers: dfetch.commands.command.SubparserActionType) -> None

def __call__(self, args: argparse.Namespace) -> None:
"""Perform the format patch."""
superproject = SuperProject()
superproject = create_super_project()

exceptions: list[str] = []

Expand All @@ -86,7 +86,7 @@ def __call__(self, args: argparse.Namespace) -> None:
with in_directory(superproject.root_directory):
for project in superproject.manifest.selected_projects(args.projects):
with catch_runtime_exceptions(exceptions) as exceptions:
subproject = dfetch.project.make(project)
subproject = dfetch.project.create_sub_project(project)

# Check if the project has a patch, maybe suggest creating one?
if not subproject.patch:
Expand Down
8 changes: 5 additions & 3 deletions dfetch/commands/freeze.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
from dfetch.log import get_logger
from dfetch.manifest.manifest import Manifest
from dfetch.manifest.project import ProjectEntry
from dfetch.project.superproject import SuperProject
from dfetch.project import create_super_project
from dfetch.util.util import catch_runtime_exceptions, in_directory

logger = get_logger(__name__)
Expand All @@ -70,15 +70,17 @@ def __call__(self, args: argparse.Namespace) -> None:
"""Perform the freeze."""
del args # unused

superproject = SuperProject()
superproject = create_super_project()

exceptions: list[str] = []
projects: list[ProjectEntry] = []

with in_directory(superproject.root_directory):
for project in superproject.manifest.projects:
with catch_runtime_exceptions(exceptions) as exceptions:
on_disk_version = dfetch.project.make(project).on_disk_version()
on_disk_version = dfetch.project.create_sub_project(
project
).on_disk_version()

if project.version == on_disk_version:
logger.print_info_line(
Expand Down
80 changes: 2 additions & 78 deletions dfetch/commands/import_.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@
from dfetch.manifest.manifest import Manifest
from dfetch.manifest.project import ProjectEntry
from dfetch.manifest.remote import Remote
from dfetch.vcs.git import GitLocalRepo
from dfetch.vcs.svn import SvnRepo
from dfetch.project import determine_superproject_vcs

logger = get_logger(__name__)

Expand All @@ -112,7 +111,7 @@ def create_menu(subparsers: dfetch.commands.command.SubparserActionType) -> None

def __call__(self, _: argparse.Namespace) -> None:
"""Perform the import."""
projects = _import_projects()
projects = determine_superproject_vcs(".").import_projects()

if not projects:
raise RuntimeError(f"No submodules found in {os.getcwd()}!")
Expand All @@ -135,81 +134,6 @@ def __call__(self, _: argparse.Namespace) -> None:
logger.info(f"Created manifest ({DEFAULT_MANIFEST_NAME}) in {os.getcwd()}")


def _import_projects() -> Sequence[ProjectEntry]:
"""Find out what type of VCS is used and import projects."""
if GitLocalRepo().is_git():
projects = _import_from_git()
elif SvnRepo().is_svn():
projects = _import_from_svn()
else:
raise RuntimeError(
"Only git or SVN projects can be imported.",
"Run this command within either a git or SVN repository",
)
return projects


def _import_from_svn() -> Sequence[ProjectEntry]:
projects: list[ProjectEntry] = []

for external in SvnRepo(os.getcwd()).externals():
projects.append(
ProjectEntry(
{
"name": external.name,
"revision": external.revision,
"url": external.url,
"dst": external.path,
"branch": external.branch,
"tag": external.tag,
"src": external.src,
}
)
)
logger.info(f"Found {external.name}")

return projects


def _import_from_git() -> Sequence[ProjectEntry]:
projects: list[ProjectEntry] = []
toplevel: str = ""
for submodule in GitLocalRepo.submodules():
projects.append(
ProjectEntry(
{
"name": submodule.name,
"revision": submodule.sha,
"url": submodule.url,
"dst": submodule.path,
"branch": submodule.branch,
"tag": submodule.tag,
}
)
)
logger.info(f"Found {submodule.name}")

if not toplevel:
toplevel = submodule.toplevel
elif toplevel != submodule.toplevel:
raise RuntimeError(
"Recursive submodules not (yet) supported. Check manifest!"
)

if os.path.realpath(toplevel) != os.getcwd():
logger.warning(
"\n".join(
(
f'The toplevel directory is in "{toplevel}"',
f'"dfetch import" was called from "{os.getcwd()}"',
"All projects paths will be relative to the current directory dfetch is running!",
)
)
)

return projects


def _create_remotes(projects: Sequence[ProjectEntry]) -> Sequence[Remote]:
"""Create a list of Remotes optimized for least amount of entries and smallest manifest.

Expand Down
4 changes: 2 additions & 2 deletions dfetch/commands/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
import dfetch.util.util
from dfetch.log import get_logger
from dfetch.manifest.project import ProjectEntry
from dfetch.project import create_super_project
from dfetch.project.metadata import Metadata
from dfetch.project.subproject import SubProject
from dfetch.project.superproject import SuperProject
from dfetch.reporting import REPORTERS, ReportTypes
from dfetch.util.license import License, guess_license_in_file

Expand Down Expand Up @@ -63,7 +63,7 @@ def create_menu(subparsers: dfetch.commands.command.SubparserActionType) -> None

def __call__(self, args: argparse.Namespace) -> None:
"""Generate the report."""
superproject = SuperProject()
superproject = create_super_project()

with dfetch.util.util.in_directory(superproject.root_directory):
reporter = REPORTERS[args.type](superproject.manifest)
Expand Down
6 changes: 3 additions & 3 deletions dfetch/commands/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import dfetch.project
from dfetch.commands.common import check_child_manifests
from dfetch.log import get_logger
from dfetch.project.superproject import SuperProject
from dfetch.project import create_super_project
from dfetch.util.util import catch_runtime_exceptions, in_directory

logger = get_logger(__name__)
Expand Down Expand Up @@ -74,7 +74,7 @@ def create_menu(subparsers: dfetch.commands.command.SubparserActionType) -> None

def __call__(self, args: argparse.Namespace) -> None:
"""Perform the update."""
superproject = SuperProject()
superproject = create_super_project()

exceptions: list[str] = []
destinations: list[str] = [
Expand All @@ -85,7 +85,7 @@ def __call__(self, args: argparse.Namespace) -> None:
for project in superproject.manifest.selected_projects(args.projects):
with catch_runtime_exceptions(exceptions) as exceptions:
self._check_destination(project, destinations)
dfetch.project.make(project).update(
dfetch.project.create_sub_project(project).update(
force=args.force,
files_to_ignore=superproject.ignored_files(project.destination),
)
Expand Down
21 changes: 12 additions & 9 deletions dfetch/commands/update_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@
import dfetch.manifest.project
import dfetch.project
from dfetch.log import get_logger
from dfetch.project.superproject import SuperProject
from dfetch.project import create_super_project
from dfetch.project.gitsuperproject import GitSuperProject
from dfetch.project.metadata import Metadata
from dfetch.project.superproject import NoVcsSuperProject, RevisionRange
from dfetch.util.util import catch_runtime_exceptions, in_directory

logger = get_logger(__name__)
Expand Down Expand Up @@ -70,22 +73,22 @@ def create_menu(subparsers: dfetch.commands.command.SubparserActionType) -> None

def __call__(self, args: argparse.Namespace) -> None:
"""Perform the update patch."""
superproject = SuperProject()
superproject = create_super_project()

exceptions: list[str] = []

if not superproject.in_vcs():
if isinstance(superproject, NoVcsSuperProject):
raise RuntimeError(
"The project containing the manifest is not under version control,"
" updating patches is not supported"
)
if not superproject.is_git():
if not isinstance(superproject, GitSuperProject):
logger.warning("Update patch is only fully supported in git superprojects!")

with in_directory(superproject.root_directory):
for project in superproject.manifest.selected_projects(args.projects):
with catch_runtime_exceptions(exceptions) as exceptions:
subproject = dfetch.project.make(project)
subproject = dfetch.project.create_sub_project(project)

files_to_ignore = superproject.ignored_files(project.destination)

Expand Down Expand Up @@ -123,10 +126,10 @@ def __call__(self, args: argparse.Namespace) -> None:
)

# generate reverse patch
patch_text = subproject.diff(
old_revision="",
new_revision="",
# ignore=files_to_ignore,
patch_text = superproject.diff(
subproject.local_path,
revisions=RevisionRange("", ""),
ignore=(Metadata.FILENAME,),
reverse=True,
)

Expand Down
Loading
Loading