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

[WIP] Add git version #28

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

ImpulseDeer
Copy link

Tried adding a git version macro using
git describe --tags --long --dirty
Based on a fork by martatesar: master...martatesar:react-git-info:master

I envisioned GitInfo and GitVersion as two different macros in the same way as they are different git commands.
But haven't figured out if that is doable or not with babel-plugin-macros yet.
Current state of the branch is that I have inactivated the original GitInfo macro to test the new GitVersion macro.

Help and feedback is welcome on how to proceed.

@ImpulseDeer
Copy link
Author

Closes: #26

Copy link
Owner

@AbhyudayaSharma AbhyudayaSharma left a comment

Choose a reason for hiding this comment

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

Hi @ImpulseDeer! Thank you for the PR. Generally looks great. I only have two concerns:

  • Exporting a new macro doesn't seem like the best idea. It would be better to add this to the existing macro, especially when there is some duplication of returned data.
  • Adding a new execSync call will have performance implications. I remember reducing the number of calls we make to git to 1 to speed up compilation. I would have to check but would it be possible to get this information directly from a single call to git-log?

/**
* Abbreviated commit hash.
*/
readonly shortHash: string;
Copy link
Owner

Choose a reason for hiding this comment

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

Isn't this duplicated from the original macro?

@@ -1,2 +1,2 @@
// Inspired by https://github.com/kentcdodds/babel-plugin-preval/blob/master/macro.js
module.exports = require('./src/GitInfo.macro')
module.exports = require('./src/GitVersion.macro')
Copy link
Owner

Choose a reason for hiding this comment

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

Hmm... the export of two macros would be somewhat complicated. I would suggest having it be part of the same macro.

});
};

module.exports = createMacro(getGitVersion);
Copy link
Owner

Choose a reason for hiding this comment

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

I think the name GitVersion doesn't seem too accurate for what it does.

@@ -4,7 +4,7 @@ const gitInfo = GitInfo();

describe('Git information', () => {
test('gets correct branch', () => {
expect(gitInfo.branch).toBe('master');
expect(gitInfo.branch).toBe('main');
Copy link
Owner

Choose a reason for hiding this comment

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

Did upstream Git change the default branch name already?

@AbhyudayaSharma AbhyudayaSharma added enhancement New feature or request hacktoberfest-accepted Hacktoberfest! labels Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request hacktoberfest-accepted Hacktoberfest!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants