【问题标题】:Azure Databricks - Clone git repository from a notebookAzure Databricks - 从笔记本克隆 git 存储库
【发布时间】:2021-02-16 12:50:56
【问题描述】:

我正在尝试使用 GitPython 库从笔记本中克隆托管在 Azure DevOps 上的 git 存储库。我在 git 存储库上生成了具有读/写访问权限的个人访问令牌。

目的是将 git 存储库保留在 DBFS 中,因为它不仅会填充笔记本源,还会填充输出和 MLFlow 模型。

为此,我尝试了以下方法,但仍然面临来自 Git 的错误 128:

from git import Repo

git_url = 'https://<myPAT>@dev.azure.com/<org>/<project>/_git/<repo>'
repo = Repo.clone_from(git_url, '/git/')

总是导致错误,没有更多细节:

GitCommandError: Cmd('git') failed due to: exit code(128)

我从其他地方检查过,我的 PAT 工作正常。

我也试过用 Base64 编码 PAT 并使用下面的命令添加标题'Authorization : Basic &lt;base64PAT&gt;',但结果是一样的。

encodedBytes= base64.urlsafe_b64encode(PAT.encode("utf-8"))
base64PAT= str(encodedBytes, "utf-8")
header = 'Authorization : Basic ' + base64PAT
git.Git().config_writer().set_value("http", "extraHeader", header).release()

对此有任何提示吗? GitPython 是否依赖于我需要更新的另一个配置,还是应该使用其他方法?

【问题讨论】:

    标签: git azure-devops azure-databricks azure-notebooks


    【解决方案1】:

    GitCommandError: Cmd('git') failed 由于: exit code(128)

    根据您的描述,您的 PAT 有足够的权限来克隆 repo。

    所以这个问题与 PAT 无关。

    这个问题的根本原因应该是目标路径('/git/')已经存在并且不是空目录。

    要解决此问题,您需要指定路径中不存在的文件夹。然后脚本将创建一个新文件夹并将 repo 克隆到新文件夹。

    这是我的示例:

    from git import Repo
    
    full_local_path = "C:\kevin1234"
    
    remote = f"https://PAT@dev.azure.com/{Org]/{Project}/_git/{repo}"
    
    Repo.clone_from(remote, full_local_path)
    

    结果:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-03-07
      • 1970-01-01
      • 2013-07-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-04
      • 2012-07-15
      相关资源
      最近更新 更多