Skip to content

Commit

Permalink
fix: push only tags to remote repo
Browse files Browse the repository at this point in the history
  • Loading branch information
pvdlg committed Nov 21, 2018
1 parent aa022e0 commit 2b082ac
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/git.js
Expand Up @@ -149,7 +149,7 @@ async function tag(tagName, execaOpts) {
* @throws {Error} if the push failed.
*/
async function push(repositoryUrl, branch, execaOpts) {
await execa('git', ['push', '--tags', repositoryUrl, `HEAD:${branch}`], execaOpts);
await execa('git', ['push', '--tags', repositoryUrl], execaOpts);
}

/**
Expand Down
16 changes: 15 additions & 1 deletion test/git.test.js
Expand Up @@ -151,7 +151,7 @@ test('Add tag on head commit', async t => {
await t.is(await gitCommitTag(commits[0].hash, {cwd}), 'tag_name');
});

test('Push tag and commit to remote repository', async t => {
test('Push tag to remote repository', async t => {
// Create a git repository with a remote, set the current working directory at the root of the repo
const {cwd, repositoryUrl} = await gitRepo(true);
const commits = await gitCommits(['Test commit'], {cwd});
Expand All @@ -162,6 +162,20 @@ test('Push tag and commit to remote repository', async t => {
t.is(await gitRemoteTagHead(repositoryUrl, 'tag_name', {cwd}), commits[0].hash);
});

test('Push tag to remote repository with remote branch ahaed', async t => {
const {cwd, repositoryUrl} = await gitRepo(true);
const commits = await gitCommits(['First'], {cwd});
await gitPush(repositoryUrl, 'master', {cwd});
const tmpRepo = await gitShallowClone(repositoryUrl);
await gitCommits(['Second'], {cwd: tmpRepo});
await gitPush('origin', 'master', {cwd: tmpRepo});

await tag('tag_name', {cwd});
await push(repositoryUrl, 'master', {cwd});

t.is(await gitRemoteTagHead(repositoryUrl, 'tag_name', {cwd}), commits[0].hash);
});

test('Return "true" if in a Git repository', async t => {
// Create a git repository with a remote, set the current working directory at the root of the repo
const {cwd} = await gitRepo(true);
Expand Down

6 comments on commit 2b082ac

@michael-wirth
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this commit breaks https://github.com/conveyal/maven-semantic-release and probably other plugins who use the git library.

Wouldn't it be better to add a new function "pushTags" instead?

@pvdlg
Copy link
Member Author

@pvdlg pvdlg commented on 2b082ac Nov 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does it breaks it? Without any explanation there is nothing we can do.

@michael-wirth
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for being inaccurate.

In this case the the https://github.com/conveyal/maven-semantic-release is using the 'git push' function to update the pom.xml with absolut and next-snapshot version. this doesn't work after the change of pushing tags only anymore.

also the new push function is confusion now what exactly it is doing now. i would expect if i wanna reuse this function to push my commits which is now longer working now

hope this helps

@pvdlg
Copy link
Member Author

@pvdlg pvdlg commented on 2b082ac Nov 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"It's broken" or "it doesn't work" doesn't mean anything and doesn't allow to analyze anything. You have to explain clearly what is supposed to happen that doesn't happen or what error message you get.

I don't understand the connection there. What does your plugin pushing a commit and semantic-release core pushing tags have to do with each other?
That's two distinguished even that doesn't impact each other. Moreover the push of the tags happen after the prepare step of your plugin that push a commit.

I don't understand either your comment about adding a pushTags function or the fact that the name push is confusing. That's internal code, it's never called by anything other than code in semantic-release core.

@michael-wirth
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for pointing that out. I'll update the plugin accordingly!

Thanks for your great plugin

@pvdlg
Copy link
Member Author

@pvdlg pvdlg commented on 2b082ac Nov 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, out of curiosity, what was the problem? Were you using those internal functions somehow?

Please sign in to comment.