Composer Releases Name - composer-php

Why is that the composer repository generated by Satis always add "dev" into the releases?
For example:
If my branch name is "master", it will become "dev-master"
If my branch name is "1.0.0", it will become "1.0.0.x-dev"
If my branch name is "1.0.1m", it will become "dev-1.0.1m"
How can I prevent it adding the extra "dev" into the release?

The dev prefix or suffix is added to branch names to clearly identify them as such to both users and composer. They must be treated differently because they are not fixed point-in-time snapshots like tags are.
If you create a git or svn tag called 1.0.0 then the composer version will still be 1.0.0.
Since the branch 1.0 for example can be the source for the 1.0.0 tag, then the 1.0.1 tag, and so on, it is suffixed and shown as 1.0-dev, which shows it is under development and not a real release.

Related

How to resolve Go module declares its path as "x" but was required as "y" between 2 versions

I recently had to move private repositories from SaaS Gitlab to an on-premise version. Everything was going well where I did:
Update old go module paths in repo a from old.com/workspace/a to new.com/workspace/a
Add a new tag v1.2.3-new to the latest commit
Update repo b to reference latest tag v1.2.3-new from new.com/workspace/a
Run go mod tidy in repo b and verify it works
Now I have a requirement to reference an older version tag of new.com/workspace/a (originally old.com/workspace/a). So in repo a, I checked out the older tag, fixed up the module path to new.com/workspace/a from old.com/workspace/a and tagged it as v1.1.1-new.
In repo b then I referenced new.com/workspace/a with v1.1.1-new. However, this results in:
go: new.com/workspace/a#v1.1.1-new: parsing go.mod:
module declares its path as: old.com/workspace/b
but was required as: new.com/workspace/b
If I check the v1.1.1-new tag in repo a, the module path is set correctly in the go.modfile:
module new.com/workspace/a
It is unclear to me why it works with the tag v1.2.3-new on the latest commit but fails when I reference an older commit.
So I can't say I fully understood why this worked but here are the steps that made it work (including what didn't).
I resorted to clearing the cache with go clean -modcache
Tested with the following but it still failed.
go get new.com/workspace/a#v1.1.1-new
As per my comment in the original question, this worked via the v1.1.1-new commit hash So I resorted to that again.
go get new.com/workspace/a#27ca81f7
Now it picked up the version for that commit and was successful. The
go.mod file was also correctly updated with the tag/version despite
using the commit hash in the go get command.
new.com/workspace/a v1.1.1-new

How to use git in vendor folder of fork?

I always use composer packages in Laravel but I never changed one. This is my first time and I don't want to do it incorrect.
I need to use and change a packages foo/bar. Everything that follows now is just guessed:
I forked the repo
I created a develop branch
I added a vcs to my composer.json
"require": {
//...
"foo/bar": "dev-develop",
},
"repositories": [
{
"type": "vcs",
"url": "https://github.com/thisisme/bar"
}
],
composer update
Now I have the thisisme/bar fork in my vendor folder in foo.
So far so good. Now I can use my own fork.
But currently, as I don't know what is good practice to modify the repo, I cloned the repo to a completely different location. Then I push my changes there and run composer update in my project to get the changes. But this is a pain.
Do I need to have a sub git in my project in vendor/foo with
git remote add origin https://github.com/thisisme/bar.git. Because "git in git" feels wrong and finally is not really working as git commands seem to interact with the "parent git".
While VonCs answer is correct regarding git, I'm not certainly sure that git submodule support is well aligned with composer(1) vendor dir for packages from a VCS repository. At least I have not experimented much with it and when I use a composer configuration with a VCS git repository, I normally don't need that1.
While composer(1) has support for git for vendor packages, it is on repository level, that is, you can have your own repository for your package (as you have configured it shown in your question) and then composer takes care of updating (or giving a warnings about local changes).
composer(1) supports this with its own remote for the packages (non-bare) clone (in the source install, read on).
So yes, what you describe ("But this is a pain."), is as long as you don't use it to your benefit. While you develop your (cloned) package, you don't need to run composer update all the time.
.git
composer.json
vendor/foo/bar/.git
A Composer project with two Git repositories
This is why IMHO "git in git" must not feel wrong. Similar to git sub-modules, git supports this very well. By default it even keeps track in the parent project of the current revision (changes) of the sub-project but without having the information of the remote - as it is local (gitlink).
You won't see this thought as within the tree, the gitlink would be at vendor/foo/bar and commonly (& given that) vendor is git ignored, no version tracking in the main project for vendor/foo/bar/.git - but there in the sub-project.
This is not a problem as Composer manages that git sub-project for you (the initial clone and further checkouts) in terms of your main project.
And git realizes it is a different project.
You should be able to cd into the package directory within the vendor folder (vendor/foo/bar) and configure your remote(s) there. You can then work within that project and git(1) will work there and not within the parent repository.
To have this work with composer(1) it is important that you configure composer to prefer the source install variant for that repository. This is the preferred-install option and you can configure it for your repository specifically.
{
"config": {
"preferred-install": {
"foo/bar": "source"
}
}
}
From the wording in your question, I assume that you have not yet configured it.
And this is somewhat important as only with the source install, there will be a (non-bare) git clone in vendor/foo/bar and therefore the git checkout with the overall git configuration within the packages folder in the vendor directory (as you have Github configured as the repository source and composer optimizes to take the dist version by default IIRC).
After you changed your configuration to the source install and updated it, cd into vendor/foo/bar and then run git remote -v. It now should show you the "composer" remote(s) for that package.
As you use the develop branch, you can add changes locally but mind the gap that you would also need to push them to the remote repository (Github) before you use composer again to update (at least) that foo/bar package - as while you use git for the development of the foo/bar package now, in your main project you use composer to manage the dependency.
This is the price you have on the payroll using Github instead of a configuration that is more near to the place of work, but at least locally, you can handle the package with "git in git".
This is normally straight forward. One overall price remains thought, due to managing two instead of one repository but that you can't prevent with this kind of composer project [composer only versioned vendor folder]).
Note: If development takes longer than a few hours, it may also make sense to include the new Git sub-project in the backup routine of your parenting project, so that when you remove the folder vendor/foo/bar you have a backup of the (local) Git repository and working tree in it. However, this depends on the project configuration and is your own responsibility.
A bit of a workflow with some hints is also outlined in the composer documentation in Loading a package from a VCS repository.
1 There is a type of setup for a composer project where vendor itself is under git version control, with that git sub-modules can work (very well), but this is most likely not the kind of setup you have for your project, so I skip it for this answer.
If you're working with sail or docker-compose and linking the foo/bar project in the vendor dir is only a temporary until 'it works' solution you could just add it as a volume link. This is what I usually do.
Eg: I'm working on my-project in ~/projects/my-project, I clone the foo/bar repo to ~/projects/bar
Then in the docker-compose.yml I can add the volume:
volumes:
- .:/var/www/html
- ../bar:/var/www/html/vendor/foo/bar
Again, this has a huge assumption on docker being used, but I like to think that everybody is using it these days.
Do I need to have a sub git in my project in vendor/foo with git remote add origin https://github.com/thisisme/bar.git.
That could be achieved with a submodule which allows for your parent Git repository to only store a reference to another repository.
You would use git submodule add for that.
A git clone --recurse-submodule would therefore clone your project with the submodule Git repository in it cloned as well, and checked out to the exact reference you previously committed.

store tag value from git repo into file

I am new to git and I have a repo stored on git. I want to implement version control the tag value that is available on git.
I have a file calledversion.rb which specifies the version of the plugin that I am currently using, which look like this :
Version = "0.1.0"
and the tag associated with this commit would be "0.1.0".
Issue :
Sometimes when I create a new tag for the repo, I would forget to update the value of `Version` in version.rb.
I want to update the Version value in version.rb to be the same value as a the tag value on the repo. Is there a way to do this?
Changing a file in a tagged commit does not make the changed file part of the previously tagged commit. So if you change version.rb you still have to create another tagged version of your repo.
Looks like you just have to remember to bump the version in version.rb.

Pointing bundler to local fork besides master branch?

I was looking into what options there were for pointing bundler/Gemfile to local forks of repos and came across "Local Git Repositories" on the bundler.io site but it appears since you have to specify a branch, if you're working off a specific feature branch such as ticket###-some-task then you would have to go into the Gemfile and update the branch: parameter to point to that instead otherwise bundler will complain that a different branch is checked out.
Is there a simpler way to point at a feature branch if you're working on 2 or more projects at the same time? Here's an example:
# project-1 Gemfile
gem 'project-2', git: 'git#local.repo.com:org/project-2', branch: 'master'
# project-2 is checked out to a branch called 'new-changes'
I then run: bundle config local.project-2 /path/to/project-2
Do I have to go into project-1 Gemfile and change the branch to new-changes every time I encounter something like this? Then when I'm done with the code change in project-2 and it's been merged into master, I would have to remember to go back into the Gemfile and change new-changes back to master?
It seems like you could run into the issue where developers would forget to change the branch back to master in the project-1 Gemfile?

Composer option to use alternative to composer.json?

I've just started using the Composer feature where you tell it to look at local directories for dependencies, so that you can develop a library and something that uses that library in parallel without having to push to git to update all the time, which is awesome. e.g.
"repositories": [
{
"type": "vcs",
"url": "/documents/projects/github/guzzle"
}
],
"require":{
"guzzle/guzzle": "3.7.*#dev"
}
So when you do a composer update, Composer will pull in the version of Guzzle from the local directory, so you can test the code for a library in another application that uses that library without having to push to a repository between each code change.
However I just almost checked in the composer.json for my project with that set - which is obviously not going to work on anyone elses machine.
Is there anyway to tell composer to use a different file than composer.json, or other way to be able to tell composer to use local directories safely, without the high probability of accidentally committing a broken version of composer.json to your repository?
Use the COMPOSER environment variable:
env COMPOSER=composer-dev.json composer install
It has actually been available since at least 2012.
Instead of fetching from a local repository elsewhere you could add the option --prefer-source to the composer install/update command and remove the local repository reference.
That way composer will call git clone the software into the vendor directory, and you can develop both your software and commit to the vendor software, because that also is a fully working git repo.
Adding local repository references is not really recommended. It works when using them for real local software, but maintaining it has it's overhead: You have to mention this repository in every composer.json file that will ever load that software, even if it is only an indirect dependency (i.e. you add a software that needs THIS software as a dependency in your local repo).
Hardcoding the URL of the repository will also prevent you from changing it at will. Even though you could move the repo and change the URL accordingly, all older versions of your software still have the old URL in both composer.json and composer.lock files, and will try to load from there.
It looks like there isn't a way to do this nicely within Composer, however it is possible to hack around it.
In your composer.json file put a comment where you want to hack in some data.
{
"name": "base-reality/intahwebz",
"//": "LOCALHACK",
"require":{
"base-reality/php-to-javascript": ">=0.1.17",
"guzzle/danackguzzle": "3.3.*#dev",
...
...
}
...
}
Then have a separate file composer.local (not committed to Git) that contains the references to local directories:
"LOCALHACK",
"repositories": [
{
"type": "vcs",
"url": "/documents/projects/github/intahwebz-core"
}
],
Add a tiny PHP script called composerLocal.php to generate the new composer.json file
<?php
$srcFile = file_get_contents("composer.json");
$hackFile = file_get_contents("composer.local");
$finalString = str_replace('"LOCALHACK",', $hackFile, $srcFile);
file_put_contents("composer.json", $finalString);
?>
And a little bash script called localupdate.sh to backup the real composer.json file, generate the hacked composer.json, run Composer and then restore the original composer.json file
cp -f composer.json composer.json.bak
php composerLocal.php
composer update
cp -f composer.json.bak composer.json
Running the localupdate.sh script allows you to test the commits locally without having the danger of modifying the actual composer.json file used by the project, so there is less chance of accidentally pushing an invalid composer.json into the repository.
Just to note, Composer doesn't read the files from the respository directory, it reads the commited files in Git so you do need to commit changes made to the library code. The above process just skips the pushing step.
This should also work:
composer config --file=composer2.json && composer install
see https://getcomposer.org/doc/03-cli.md#usage
Easy, just use artifact.
In repositories add this:
{
"type": "artifact",
"url": "path/to/artifact/files/"
},
Now you just need to create the directory and zip a copy of your repository into that dir.
Name zipped files like so:
[vendorname]-[packagename]-[version].zip
example:
querypath-QueryPath-3.0.0.zip
Now you can modify the package locally and it will pull from the zip file instead of the online repo.
In require add it like so and specify version as defined in zip:
"querypath/QueryPath": "3.0.0",
With this method you will have the ability to edit the vendor files and composer will still update any autoloaders relative to the changes and it will leave your changes alone.

Resources