How to manage replace directive during development?

Hi,

I am currently developping a module A depending on module B. We need to update both A and B and test them together. I then added a replace directive for module B in the go.mod file of A. But how to deal with this file for continuous integration? Should we manually add and remove the replace directive? This can be error prone. Can’t we specify another go.mod file to the go build command for example, with a replace directive and one without? Or make the replace directive conditionnal?

Many Thanks,
Regards,
Sylvain

Why is it necessary to change the replace directive? The docs say:

The replace directive allows you to supply another import path that might be another module located in VCS (GitHub or elsewhere), or on your local filesystem with a relative or absolute file path.

Does the import path of B have to be different between development and CI?

Because module A is using a specific version of module B for example:

require (
...
gitlab.mycompany.com/mymoduleB v1.0.0
...

But in development I want to use my local updates without commiting them to the central repo:

replace gitlab.mycompany.com/mymoduleB => ../mymoduleB

and I don’t want to commit the replace neither when my dev is done.

I wonder why you are not using branches for the environments?

Are you suggesting to remove “replace” directives and always commit on branches then reference the branch in the module version?

if you are under developing branch, use below:

replace gitlab.mycompany.com/mymoduleB => ../mymoduleB

if you are under production branch, use this:

gitlab.mycompany.com/mymoduleB v1.0.0
1 Like

Ok so we must create a branch for every development and add the replace directive.
Then remove it when merging on the master branch.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.