def execute()

in dusty/commands/git_clone.py [0:0]


    def execute(self, args):
        """ Run the command """
        log.debug("Starting")
        # Check args
        if not args.source or not args.target:
            log.error("Please specify source and target.")
            return
        # Patch dulwich to work without valid UID/GID
        dulwich.repo.__original__get_default_identity = dulwich.repo._get_default_identity  # pylint: disable=W0212
        dulwich.repo._get_default_identity = _dulwich_repo_get_default_identity  # pylint: disable=W0212
        # Patch dulwich to use paramiko SSH client
        dulwich.client.get_ssh_vendor = ParamikoSSHVendor
        # Patch paramiko to skip key verification
        paramiko.transport.Transport._verify_key = _paramiko_transport_verify_key  # pylint: disable=W0212
        # Set USERNAME if needed
        try:
            getpass.getuser()
        except:  # pylint: disable=W0702
            os.environ["USERNAME"] = "git"
        # Fill args
        depth = None
        if args.depth:
            depth = args.depth
        # Prepare auth
        auth_args = dict()
        # Take from env variables
        if args.username_variable and args.username_variable in os.environ:
            auth_args["username"] = os.environ[args.username_variable]
            os.environ["USERNAME"] = os.environ[args.username_variable]
        if args.password_variable and args.password_variable in os.environ:
            auth_args["password"] = os.environ[args.password_variable]
        if args.key_variable and args.key_variable in os.environ:
            auth_args["key_filename"] = os.environ[args.key_variable]
        if args.key_data_variable and args.key_data_variable in os.environ:
            key_obj = io.StringIO(os.environ[args.key_data_variable].replace("|", "\n"))
            pkey = paramiko.RSAKey.from_private_key(key_obj)
            # Patch paramiko to use our key
            paramiko.client.SSHClient._auth = _paramiko_client_SSHClient_auth(  # pylint: disable=W0212
                paramiko.client.SSHClient._auth, pkey  # pylint: disable=W0212
            )
        # Take from commandline parameters
        if args.username:
            auth_args["username"] = args.username
            os.environ["USERNAME"] = args.username
        if args.password:
            auth_args["password"] = args.password
        if args.key:
            auth_args["key_filename"] = args.key
        if args.key_data:
            key_obj = io.StringIO(args.key_data.replace("|", "\n"))
            pkey = paramiko.RSAKey.from_private_key(key_obj)
            # Patch paramiko to use our key
            paramiko.client.SSHClient._auth = _paramiko_client_SSHClient_auth(  # pylint: disable=W0212
                paramiko.client.SSHClient._auth, pkey  # pylint: disable=W0212
            )
        # Clone repository
        log.info("Cloning repository %s into %s", args.source, args.target)
        repository = porcelain.clone(
            args.source, args.target,
            checkout=False, depth=depth,
            errstream=log.DebugLogStream(),
            **auth_args
        )
        # Checkout branch
        log.info("Checking out branch %s", args.branch)
        branch = args.branch.encode("utf-8")
        repository[b"refs/heads/" + branch] = repository[b"refs/remotes/origin/" + branch]
        repository.refs.set_symbolic_ref(b"HEAD", b"refs/heads/" + branch)
        repository.reset_index(repository[b"HEAD"].tree)