Azure Databricks - 从笔记本克隆 git 存储库

时间:2021-02-16 12:50:56

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

我正在尝试使用 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 <base64PAT>'”,但结果相同。

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 是依赖于我需要更新的另一个配置还是应该使用其他方法?

1 个答案:

答案 0 :(得分:2)

<块引用>

GitCommandError:Cmd('git') 失败,原因是:退出代码(128)

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

所以这个问题与 PAT 无关。

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

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

这是我的示例:

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)

结果:

enter image description here