Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not working on Azure Git Pipeline #13

Open
Makio64 opened this issue Apr 7, 2020 · 4 comments
Open

Not working on Azure Git Pipeline #13

Makio64 opened this issue Apr 7, 2020 · 4 comments

Comments

@Makio64
Copy link

Makio64 commented Apr 7, 2020

Hi,

git-branch return null when executed from a Azure Git Pipeline, I dont think it come from the git as there is no problem with another utility : git-last-commit

@doowb
Copy link
Collaborator

doowb commented Apr 7, 2020

This package looks for the .git directory in relation to the current working directory. There is an option to pass in the current working directory to specify where to start.

It also looks like Azure Pipelines allows configuring checkout paths, which might affect the current working directory.

I'm not familiar with how Azure Pipelines runs your code, so I don't know which directory it will start in, without more information.

@Makio64
Copy link
Author

Makio64 commented Apr 7, 2020

I switch to another utility current-git-branch which work locally and on Azure, it indicate me Azure create a detached HEAD for the pipeline, I think detached HEAD are the problem here.

@joscha
Copy link

joscha commented Feb 19, 2021

current-git-branch relies on git and a few unix built-ins (grep) to be there, whilst this package has no dependencies of this sort. Detached state means there is explicitly no branch name, which is why this library returns null. Looking at https://github.com/JPeer264/node-current-git-branch/blob/d6914733978f4ccb0490e5601093b1f154aa37c5/index.js#L23 I believe the code run is:

git branch | grep '\*'

which actually means that current-git-branch does not return a branch either but:

* (HEAD detached at c9db328)

which is not null, but arguably more incorrect. I think this ticket should probably be closed, we can potentially add a test case for explicitly not supporting detached HEAD state. After merging #14 we can easily do so by adding:

diff --git a/test/test.js b/test/test.js
index bf04550..6996af4 100644
--- a/test/test.js
+++ b/test/test.js
@@ -38,4 +38,8 @@ describe('git-branch', function() {
     });
   });
   it('should work with a git worktree', () => assert.strictEqual(branch.sync(worktreeFixtures), 'some-branch'));
+  it('should work with a detached HEAD', async () => {
+    await exec(['git', 'checkout', '--detach'].join(' '), { cwd: fixtures });
+    assert.strictEqual(branch.sync(fixtures), null)
+  });
 });

cc @jonschlinkert

@slikts
Copy link

slikts commented Oct 26, 2021

Azure Pipelines check out detached commits, not branches, because the branch can change between pipeline runs. You can get the actual branch name with process.env.SYSTEM_PULLREQUEST_SOURCEBRANCH for pipelines triggered by PRs and with process.env.BUILD_SOURCEBRANCH for other triggers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants