Skip to content

Handle missing git user.email config #375

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

Merged
merged 5 commits into from
May 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions src/screens/Errors/GitError.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,33 @@

const meta = {
component: GitError,
args: {
gitInfoError: new Error('Chromatic only works from inside a Git repository.'),
},
} satisfies Meta<typeof GitError>;

export default meta;
type Story = StoryObj<typeof meta>;

export const Default: Story = {};
export const NotInitialized: Story = {
args: {
gitInfoError: new Error(`

Check warning on line 14 in src/screens/Errors/GitError.stories.tsx

View check run for this annotation

Codecov / codecov/patch

src/screens/Errors/GitError.stories.tsx#L12-L14

Added lines #L12 - L14 were not covered by tests
Unable to execute command: git rev-parse --abbrev-ref HEAD
Chromatic only works from inside a Git repository.

You can initialize a new Git repository with \`git init\`.
`),
},
};

Check warning on line 21 in src/screens/Errors/GitError.stories.tsx

View check run for this annotation

Codecov / codecov/patch

src/screens/Errors/GitError.stories.tsx#L19-L21

Added lines #L19 - L21 were not covered by tests

export const NoCommit: Story = {
args: {
gitInfoError: new Error('Chromatic requires your Git repository to have at least one commit.'),
gitInfoError: new Error(`

Check warning on line 25 in src/screens/Errors/GitError.stories.tsx

View check run for this annotation

Codecov / codecov/patch

src/screens/Errors/GitError.stories.tsx#L25

Added line #L25 was not covered by tests
Unable to execute command: git --no-pager log -n 1 --format="%H ## %ct ## %ae ## %an"
Chromatic requires your Git repository to have at least one commit.
`),
},
};

Check warning on line 30 in src/screens/Errors/GitError.stories.tsx

View check run for this annotation

Codecov / codecov/patch

src/screens/Errors/GitError.stories.tsx#L28-L30

Added lines #L28 - L30 were not covered by tests

export const NoEmail: Story = {
args: {
gitInfoError: new Error('Command failed with exit code 1: git config user.email'),

Check warning on line 34 in src/screens/Errors/GitError.stories.tsx

View check run for this annotation

Codecov / codecov/patch

src/screens/Errors/GitError.stories.tsx#L32-L34

Added lines #L32 - L34 were not covered by tests
},
};
127 changes: 78 additions & 49 deletions src/screens/Errors/GitError.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,67 +74,96 @@
},
});

const Instructions = styled.div(({ theme }) => ({
const Instructions = styled.div({

Check warning on line 77 in src/screens/Errors/GitError.tsx

View check run for this annotation

Codecov / codecov/patch

src/screens/Errors/GitError.tsx#L77

Added line #L77 was not covered by tests
width: '100%',
display: 'flex',
flexDirection: 'column',
gap: 8,
pre: {
margin: 0,
padding: '10px 12px',
fontSize: '12px',
background: theme.background.content,
border: `1px solid ${theme.appBorderColor}`,
borderRadius: 4,
},
});

Check warning on line 82 in src/screens/Errors/GitError.tsx

View check run for this annotation

Codecov / codecov/patch

src/screens/Errors/GitError.tsx#L82

Added line #L82 was not covered by tests

const Pre = styled.pre(({ theme }) => ({
margin: 0,
padding: '10px 12px',
fontSize: '12px',
background: theme.background.content,
border: `1px solid ${theme.appBorderColor}`,
borderRadius: 4,

Check warning on line 90 in src/screens/Errors/GitError.tsx

View check run for this annotation

Codecov / codecov/patch

src/screens/Errors/GitError.tsx#L84-L90

Added lines #L84 - L90 were not covered by tests
}));

export const GitError = ({ gitInfoError }: { gitInfoError?: Error }) => {
const hasGitRepo = gitInfoError?.message.includes('one commit');
useTelemetry('Errors', hasGitRepo ? 'GitError' : 'GitNotFound');
const requireInit = gitInfoError?.message.includes('git init');
const requireCommit = requireInit || gitInfoError?.message.includes('one commit');
const requireEmail = gitInfoError?.message.includes('user.email');
useTelemetry('Errors', requireInit ? 'GitNotFound' : 'GitError');

Check warning on line 97 in src/screens/Errors/GitError.tsx

View check run for this annotation

Codecov / codecov/patch

src/screens/Errors/GitError.tsx#L94-L97

Added lines #L94 - L97 were not covered by tests
return (
<Screen footer={null}>
<Container>
<Stack>
<div>
<Heading>Set up a Git repository</Heading>
{requireEmail ? (
<Stack>
<div>
<Heading>Configure your Git email</Heading>
<Text center muted>

Check warning on line 105 in src/screens/Errors/GitError.tsx

View check run for this annotation

Codecov / codecov/patch

src/screens/Errors/GitError.tsx#L101-L105

Added lines #L101 - L105 were not covered by tests
Chromatic requires Git to be configured with an email address to connect local
builds to CI builds and link builds to user accounts.
</Text>
</div>

Check warning on line 109 in src/screens/Errors/GitError.tsx

View check run for this annotation

Codecov / codecov/patch

src/screens/Errors/GitError.tsx#L108-L109

Added lines #L108 - L109 were not covered by tests
<Text center muted>
Chromatic requires Git to associate test results with commits and branches. Run these
steps to get started:
Run this command to set an email address:
</Text>
<Pre>git config user.email "[email protected]"</Pre>
<Text muted small>
<Link
target="_blank"
href="https://www.chromatic.com/docs/privacy-policy/"
withArrow
secondary
>

Check warning on line 120 in src/screens/Errors/GitError.tsx

View check run for this annotation

Codecov / codecov/patch

src/screens/Errors/GitError.tsx#L112-L120

Added lines #L112 - L120 were not covered by tests
Privacy policy
</Link>

Check warning on line 122 in src/screens/Errors/GitError.tsx

View check run for this annotation

Codecov / codecov/patch

src/screens/Errors/GitError.tsx#L122

Added line #L122 was not covered by tests
</Text>
</div>
<CheckList>
<li>
{hasGitRepo ? <Check /> : <Step />}
<Instructions>
<span>Initialize a Git repository</span>
{!hasGitRepo && <pre>git init</pre>}
</Instructions>
</li>
<li>
<Step />
<Instructions>
<span>Stage all files</span>
<pre>git add .</pre>
</Instructions>
</li>
<li>
<Step />
<Instructions>
<span>Commit the changes</span>
<pre>git commit -m "Initial commit"</pre>
</Instructions>
</li>
</CheckList>
<Link
target="_blank"
href="https://www.chromatic.com/docs/visual-tests-addon#git-addon"
withArrow
secondary
>
Visual tests requirements
</Link>
</Stack>
</Stack>

Check warning on line 124 in src/screens/Errors/GitError.tsx

View check run for this annotation

Codecov / codecov/patch

src/screens/Errors/GitError.tsx#L124

Added line #L124 was not covered by tests
) : (
<Stack>
<div>
<Heading>Set up a Git repository</Heading>
<Text center muted>

Check warning on line 129 in src/screens/Errors/GitError.tsx

View check run for this annotation

Codecov / codecov/patch

src/screens/Errors/GitError.tsx#L126-L129

Added lines #L126 - L129 were not covered by tests
Chromatic requires Git to associate test results with commits and branches. Run
these steps to get started:
</Text>
</div>
<CheckList>
<li>
{requireInit ? <Step /> : <Check />}
<Instructions>
<span>Initialize a Git repository</span>
{requireInit && <Pre>git init</Pre>}
</Instructions>
</li>
<li>
{requireCommit ? <Step /> : <Check />}
<Instructions>
<span>Stage all files</span>
{requireCommit && <Pre>git add .</Pre>}
</Instructions>
</li>
<li>
{requireCommit ? <Step /> : <Check />}
<Instructions>
<span>Commit the changes</span>
{requireCommit && <Pre>git commit -m "Initial commit"</Pre>}
</Instructions>
</li>
</CheckList>
<Link
target="_blank"
href="https://www.chromatic.com/docs/visual-tests-addon#git-addon"
withArrow
secondary
>

Check warning on line 162 in src/screens/Errors/GitError.tsx

View check run for this annotation

Codecov / codecov/patch

src/screens/Errors/GitError.tsx#L132-L162

Added lines #L132 - L162 were not covered by tests
Visual tests requirements
</Link>
</Stack>

Check warning on line 165 in src/screens/Errors/GitError.tsx

View check run for this annotation

Codecov / codecov/patch

src/screens/Errors/GitError.tsx#L164-L165

Added lines #L164 - L165 were not covered by tests
)}
</Container>
</Screen>
);
Expand Down