Esempio n. 1
0
def step_impl(context, name):
    repo_path = create_svn_server_and_repo(context, name)

    files = context.table or [{"path": "README.md"}]

    with in_directory(repo_path):

        create_stdlayout()
        with in_directory("trunk"):
            for file in files:
                generate_file(file["path"], "some content")
        add_and_commit("Added files")
Esempio n. 2
0
def step_impl(context, name):
    repo_path = create_svn_server_and_repo(context, name)

    with in_directory(repo_path):
        for file in context.table:
            generate_file(file["path"], "some content")
        add_and_commit("Added files")
Esempio n. 3
0
 def is_git(self) -> bool:
     """Check if is git."""
     try:
         with in_directory(self._path):
             run_on_cmdline(logger, "git status")
         return True
     except (SubprocessCommandError, RuntimeError):
         return False
Esempio n. 4
0
 def check_path(path: str = ".") -> bool:
     """Check if is SVN."""
     try:
         with in_directory(path):
             run_on_cmdline(logger, "svn info")
         return True
     except (SubprocessCommandError, RuntimeError):
         return False
Esempio n. 5
0
    def get_last_file_hash(self, path: str) -> str:
        """Get the hash of a specific file."""
        with in_directory(self._path):
            result = run_on_cmdline(
                logger,
                ["git", "log", "-n", "1", "--pretty=format:%H", "--", path],
            )

        return str(result.stdout.decode())
Esempio n. 6
0
    def get_current_hash(self) -> str:
        """Get the last revision."""
        with in_directory(self._path):
            result = run_on_cmdline(
                logger,
                ["git", "log", "-n", "1", "--pretty=format:%H"],
            )

        return str(result.stdout.decode())
Esempio n. 7
0
def step_impl(context):

    pathlib.Path("MyProject").mkdir(parents=True, exist_ok=True)
    with in_directory("MyProject"):
        create_repo()
        generate_manifest(context)
        context.execute_steps("""
            When I run "dfetch update"
            """)
        commit_all("Initial commit")
Esempio n. 8
0
def step_impl(context):

    repo_path = create_svn_server_and_repo(context, "MySvnProject")

    with in_directory(repo_path):
        generate_manifest(context)
        context.execute_steps("""
            When I run "dfetch update"
            """)
        add_and_commit("Initial commit")
Esempio n. 9
0
    def __call__(self, args: argparse.Namespace) -> None:
        """Perform the check."""
        manifest, path = dfetch.manifest.manifest.get_manifest()
        reporters = self._get_reporters(args, path)

        with in_directory(os.path.dirname(path)):
            exceptions: List[str] = []
            for project in manifest.selected_projects(args.projects):
                with catch_runtime_exceptions(exceptions) as exceptions:
                    dfetch.project.make(project).check_for_update(reporters)

                if not args.no_recommendations and os.path.isdir(project.destination):
                    with in_directory(project.destination):
                        check_child_manifests(manifest, project, path)

            for reporter in reporters:
                reporter.dump_to_file()

        if exceptions:
            raise RuntimeError("\n".join(exceptions))
Esempio n. 10
0
def step_impl(context):

    create_repo()

    for submodule in context.table:
        subprocess.call(
            ["git", "submodule", "add", submodule["url"], submodule["path"]])

        with in_directory(submodule["path"]):
            subprocess.call(["git", "checkout", submodule["revision"]])
    commit_all("Added submodules")
Esempio n. 11
0
def step_impl(context, name):
    remote_path = os.path.join(context.remotes_dir, name)
    pathlib.Path(remote_path).mkdir(parents=True, exist_ok=True)

    with in_directory(remote_path):
        create_repo()

        for file in context.table:
            generate_file(file["path"], "some content")

        commit_all("Initial commit")
        tag("v1")
Esempio n. 12
0
    def __call__(self, args: argparse.Namespace) -> None:
        """Perform the update."""
        manifest, path = dfetch.manifest.manifest.get_manifest()

        exceptions: List[str] = []
        destinations: List[str] = [
            os.path.realpath(project.destination) for project in manifest.projects
        ]
        with in_directory(os.path.dirname(path)):
            for project in manifest.selected_projects(args.projects):
                with catch_runtime_exceptions(exceptions) as exceptions:
                    self._check_destination(project, destinations)
                    dfetch.project.make(project).update(force=args.force)

                    if not args.no_recommendations and os.path.isdir(
                        project.destination
                    ):
                        with in_directory(project.destination):
                            check_child_manifests(manifest, project, path)

        if exceptions:
            raise RuntimeError("\n".join(exceptions))
Esempio n. 13
0
def step_impl(context, args, path=None):
    """Call a command."""
    context.log_capture.buffer = []
    with in_directory(path or "."):
        try:
            run(args.split())
            context.cmd_returncode = 0
        except DfetchFatalException:
            context.cmd_returncode = 1
    # Remove the color code + title
    context.cmd_output = dfetch_title.sub(
        "", ansi_escape.sub("", context.log_capture.getvalue())
    )
Esempio n. 14
0
    def _fetch_impl(self, version: Version) -> Version:
        """Get the revision of the remote and place it at the local path."""
        rev_or_branch_or_tag = self._determine_what_to_fetch(version)

        # When exporting a file, the destination directory must already exist
        pathlib.Path(self.local_path).mkdir(parents=True, exist_ok=True)

        with in_directory(self.local_path):
            self._checkout_version(self.remote, rev_or_branch_or_tag,
                                   self.source)

        safe_rmtree(os.path.join(self.local_path, self.METADATA_DIR))

        return self._determine_fetched_version(version)
Esempio n. 15
0
def step_impl(context, name):

    remote_path = os.path.join(context.remotes_dir, name)

    pathlib.Path(remote_path).mkdir(parents=True, exist_ok=True)

    with in_directory(remote_path):
        create_repo()

        generate_file("README.md", f"Generated file for {name}")
        if context.text:
            generate_manifest(context)

        commit_all("Initial commit")
        tag("v1")
Esempio n. 16
0
    def checkout_version(
        self,
        remote: str,
        version: str,
        src: Optional[str],
        must_keeps: Optional[List[str]],
    ) -> None:
        """Checkout a specific version from a given remote.

        Args:
            remote (str): Url or path to a remote git repository
            version (str): A target to checkout, can be branch, tag or sha
            src (Optional[str]): Optional path to subdirectory or file in repo
            must_keeps (Optional[List[str]]): Optional list of glob patterns to keep
        """
        with in_directory(self._path):
            run_on_cmdline(logger, "git init")
            run_on_cmdline(logger, f"git remote add origin {remote}")
            run_on_cmdline(logger, "git checkout -b dfetch-local-branch")

            if src:
                run_on_cmdline(logger, "git config core.sparsecheckout true")
                with open(
                    ".git/info/sparse-checkout", "a", encoding="utf-8"
                ) as sparse_checkout_file:
                    sparse_checkout_file.write(
                        "\n".join(list([f"/{src}"] + (must_keeps or [])))
                    )

            run_on_cmdline(logger, f"git fetch --depth 1 origin {version}")
            run_on_cmdline(logger, "git reset --hard FETCH_HEAD")

            if src:
                full_src = src
                if not os.path.isdir(src):
                    src = os.path.dirname(src)

                if not src:
                    return

                try:
                    for file_to_copy in os.listdir(src):
                        shutil.move(src + "/" + file_to_copy, ".")
                    safe_rmtree(PurePath(src).parts[0])
                except FileNotFoundError:
                    logger.warning(
                        f"The 'src:' filter '{full_src}' didn't match any files from '{remote}'"
                    )
Esempio n. 17
0
    def create_diff(self, old_hash: str, new_hash: Optional[str]) -> str:
        """Generate a relative diff patch."""
        with in_directory(self._path):
            cmd = [
                "git",
                "diff",
                "--relative",
                "--binary",  # Add binary content
                "--no-ext-diff",  # Don't allow external diff tools
                "--no-color",
                old_hash,
            ]
            if new_hash:
                cmd.append(new_hash)
            result = run_on_cmdline(logger, cmd)

        return str(result.stdout.decode())
Esempio n. 18
0
    def __call__(self, args: argparse.Namespace) -> None:
        """Perform the freeze."""
        del args  # unused

        manifest, path = get_manifest()

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

        with in_directory(os.path.dirname(path)):
            for project in manifest.projects:
                with catch_runtime_exceptions(exceptions) as exceptions:
                    on_disk_version = dfetch.project.make(
                        project).on_disk_version()

                    if project.version == on_disk_version:
                        logger.print_info_line(
                            project.name,
                            f"Already pinned in manifest on version {project.version}",
                        )
                    elif on_disk_version:
                        logger.print_info_line(
                            project.name,
                            f"Freezing on version {on_disk_version}")
                        project.version = on_disk_version
                    else:
                        logger.print_warning_line(
                            project.name,
                            "No version on disk, first update with 'dfetch update'",
                        )

                    projects.append(project)

            manifest = Manifest({
                "version": "0.0",
                "remotes": manifest.remotes,
                "projects": projects
            })

            shutil.move(DEFAULT_MANIFEST_NAME,
                        DEFAULT_MANIFEST_NAME + ".backup")

            manifest.dump(DEFAULT_MANIFEST_NAME)
            logger.info(
                f"Updated manifest ({DEFAULT_MANIFEST_NAME}) in {os.getcwd()}")
Esempio n. 19
0
    def find_branch_containing_sha(self, sha: str) -> str:
        """Try to find the branch that contains the given sha."""
        if not os.path.isdir(os.path.join(self._path, GitLocalRepo.METADATA_DIR)):
            return ""

        with in_directory(self._path):
            result = run_on_cmdline(
                logger,
                ["git", "branch", "--contains", sha],
            )

        branches: List[str] = [
            branch.strip()
            for branch in result.stdout.decode().split("*")
            if branch.strip() and "HEAD detached at" not in branch.strip()
        ]

        return "" if not branches else branches[0]
Esempio n. 20
0
    def __call__(self, args: argparse.Namespace) -> None:
        """Perform the diff."""
        manifest, path = dfetch.manifest.manifest.get_manifest()
        revs = [r for r in args.revs.strip(":").split(":", maxsplit=1) if r]

        with in_directory(os.path.dirname(path)):
            exceptions: List[str] = []
            projects = manifest.selected_projects(args.projects)
            if not projects:
                raise RuntimeError(
                    f"No (such) project found! {', '.join(args.projects)}")
            for project in projects:
                patch_name = f"{project.name}.patch"
                with catch_runtime_exceptions(exceptions) as exceptions:
                    repo = _get_repo(path, project)
                    patch = _diff_from_repo(repo, project, revs)

                    _dump_patch(path, revs, project, patch_name, patch)

        if exceptions:
            raise RuntimeError("\n".join(exceptions))
Esempio n. 21
0
    def _find_branch_in_local_repo_containing_sha(repo_path: str,
                                                  sha: str) -> str:
        if not os.path.isdir(repo_path):
            return ""

        with in_directory(repo_path):
            if not os.path.isdir(GitRepo.METADATA_DIR):
                return ""
            result = run_on_cmdline(
                logger,
                ["git", "branch", "--contains", sha],
            )

        branches: List[str] = []
        for branch in result.stdout.decode().split("*"):
            branch = branch.strip()

            if branch and "HEAD detached at" not in branch:
                branches.append(branch)

        return branches[0] if len(branches) == 1 else ""
Esempio n. 22
0
def step_impl(context, tagname, name):
    remote_path = os.path.join(context.remotes_dir, name)
    with in_directory(remote_path):
        extend_file("README.md", f"New line for creating {tagname}")
        commit_all("Extend readme")
        tag(tagname)
Esempio n. 23
0
def step_impl(context, name):
    repo_path = create_svn_server_and_repo(context, name)

    with in_directory(repo_path):
        generate_file("SomeFolder/SomeFile.txt", "some content")
        add_and_commit("Added files")
Esempio n. 24
0
def step_impl(context, directory, path):
    with in_directory(directory):
        extend_file(path, context.text)
        commit_all("A change")
Esempio n. 25
0
def step_impl(context, directory, path):
    with in_directory(directory):
        extend_file(path, context.text)