让作曲家更新从 git repo 获取最新版本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14595772/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 08:06:26  来源:igfitidea点击:

have composer update get latest version from git repo

phpgitcomposer-php

提问by wkjagt

I am trying to move away from git submodules for the development in my team. The most important reason for this is that when a team member commits changes in a submodule, but forgets to push to origin, but does push the reference to this new commit in the "root" project, origin is broken, and the other developers get the reference is not a treeerror. This can be problematic if the developer in question pushed before going home, and that reference that is not a tree points to a commit on the developers laptop, which is in his bag, in a train somewhere.

我正试图摆脱 git 子模块以在我的团队中进行开发。最重要的原因是,当一个团队成员在子模块中提交更改,但忘记推送到源,但确实在“根”项目中推送了对这个新提交的引用时,源被破坏,其他开发人员得到该reference is not a tree错误。如果有问题的开发人员在回家之前推送,并且不是树的引用指向开发人员笔记本电脑上的提交,这可能是有问题的,笔记本电脑在他的包里,在火车上的某个地方。

I am trying to replace git submodules with composer. My reasoning is that if git doesn't know about my dependencies, these dependencies can't break the repo. I know how to add packages from packagist, and I also managed to add our own git repositories to composer, mainly with the help from this blog post.

我正在尝试用作曲家替换 git 子模块。我的理由是,如果 git 不知道我的依赖项,这些依赖项就不能破坏 repo。我知道如何从 packagist 添加包,我还设法将我们自己的 git 存储库添加到 composer,主要是在这篇博文的帮助下。

The problem, and the last piece of the puzzle, is that our dependencies are git repositories that we are actively working on. If I push an update to one of our dependencies, I would like the local copies of the developers to update to this latest version when they do a composer update. The closest I got is to create a tag for each change to a dependency, and then update my composer.json with the id of this new tag.

问题,也是最后一个难题,是我们的依赖项是我们正在积极处理的 git 存储库。如果我将更新推送到我们的一个依赖项,我希望开发人员的本地副本在执行composer update. 我得到的最接近的是为依赖项的每个更改创建一个标签,然后用这个新标签的 id 更新我的 composer.json。

What I would like to know, is if there is a way to have composer always check out the latest commit of a certain branch, or, if this is not possible, to always get the latest tag when I do a composer update. I don't really mind the tagging, I just don't want to keep updating composer.json during development.

我想知道的是,是否有办法让作曲家始终检查某个分支的最新提交,或者,如果这不可能,则在我执行composer update. 我真的不介意标记,我只是不想在开发过程中不断更新 composer.json。

The composer file I have for testing:

我用于测试的作曲家文件:

{
    "config": {
        "vendor-dir": "app/vendor"
    },
    "repositories":
    [
        {
            "type": "package",
            "package": {
                "name": "wkjagt/seagull",
                "version": "1.0",
                "source": {
                    "url": "[email protected]:wkjagt/Seagull.git",
                    "type": "git",
                    "reference": "master"
                }
            }
        }
    ],
    "require": {
        "wkjagt/seagull": "1.0.*"
    }
}

I was expecting the 1.0.*to take the latest tag starting with 1.0, but once composer already has 1.0.1, it won't get 1.0.2 if I create it. Any help with this would be very much appreciated.

我希望1.0.*从 1.0 开始采用最新的标签,但是一旦 composer 已经有了 1.0.1,如果我创建它,它就不会得到 1.0.2。对此的任何帮助将不胜感激。

回答by schmunk

If you won't have to specify each version separately in your repositories section, you'll need to add a composer.jsonfile to wkjagt/Seagulland include the package like this:

如果您不必在存储库部分中单独指定每个版本,则需要将composer.json文件添加到wkjagt/Seagull并包含如下所示的包:

{
   "type": "vcs",
   "url": "https://github.com/wkjagt/Seagull"
},

Composer can then read through your tags and treat them as versions. If you always want the get the latest version require your package with the dev flag:

然后 Composer 可以通读您的标签并将它们视为版本。如果您总是希望获得最新版本,则需要带有 dev 标志的包:

"require": {
    "wkjagt/seagull": "@dev"
}