gpt4 book ai didi

php - 我怎样才能从 git status "On branch master\n Nothing to commit.."到 "On branch master\n Your branch is up to date\n Nothing to .."?”

转载 作者:太空宇宙 更新时间:2023-11-04 09:59:35 25 4
gpt4 key购买 nike

我正在构建一个控制 git 存储库的 PHP 应用程序。我有一个执行命令 git status 的同步函数,虽然没有返回“你的分支是最新的”,但可能会提前采取必要的行动,比如远程或本地分支。

我还构建了如果本地 repo 文件夹被删除然后 mkdir、chmod 和 git pull 的逻辑。为了测试它,我删除了本地 repo 文件夹并创建了新的本地 repo 并且 git pull 成功了。

现在我的逻辑在很大程度上依赖于字符串“你的分支是最新的”但是 git status 只返回“On branch master\n Nothing ..”之前你的分支字符串曾经在现在返回的两个语句之间.

我想问一下我怎样才能从“在分支主机上\n什么都没有..”到“在分支主机上\n你的分支是最新的\n什么都没有..”?

我正在使用 PHP 脚本来实现上述逻辑并使用 shell_exec() 来执行 git 命令,将输出收集到变量中并使用 this->contains() 来匹配状态并采取相应的行动

Sync()
{
//If folder was deleted
if(!is_dir($repo))
{
if(mkdir($repo))
{
shell_exec(chmod)
shell_exec(git pull)
}
}

//For rest of the cases
$output = shell_exec("git status")
while(!this->contains("Your branch is up to date", $output))
{
//Take necessary actions
}
}

最佳答案

我找到了解决方案。我使用以下命令解决了我的问题:

git branch --set-upstream-to=origin/master

关于php - 我怎样才能从 git status "On branch master\n Nothing to commit.."到 "On branch master\n Your branch is up to date\n Nothing to .."?”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57436481/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com