This repository has been archived by the owner on Jan 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 477
[expo-cli] detect git changes on credentials.json update #2482
Merged
wkozyra95
merged 2 commits into
master
from
@wkozyra95/detect-git-change-one-credentials-update
Aug 21, 2020
Merged
[expo-cli] detect git changes on credentials.json update #2482
wkozyra95
merged 2 commits into
master
from
@wkozyra95/detect-git-change-one-credentials-update
Aug 21, 2020
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dsokal
approved these changes
Aug 21, 2020
async function isFileUntrackedAsync(path: string): Promise<boolean> { | ||
const withUntrackedFiles = await gitStatusAsync({ showUntracked: true }); | ||
const trackedFiles = await gitStatusAsync({ showUntracked: false }); | ||
const pathWithouLeadingDot = path.replace(/^\.\//, ''); // remove leading './' from path |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggested change
const pathWithouLeadingDot = path.replace(/^\.\//, ''); // remove leading './' from path | |
const pathWithoutLeadingDot = path.replace(/^\.\//, ''); // remove leading './' from path |
Comment on lines
172
to
173
withUntrackedFiles.includes(pathWithouLeadingDot) && | ||
!trackedFiles.includes(pathWithouLeadingDot) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggested change
withUntrackedFiles.includes(pathWithouLeadingDot) && | |
!trackedFiles.includes(pathWithouLeadingDot) | |
withUntrackedFiles.includes(pathWithoutLeadingDot) && | |
!trackedFiles.includes(pathWithoutLeadingDot) |
function displayUntrackedFilesWarning(newFilePaths: string[]) { | ||
if (newFilePaths.length === 1) { | ||
log.warn( | ||
`File ${newFilePaths[0]} is currently untracked, remember to add it to .gitignore or to encrypt it.` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggested change
`File ${newFilePaths[0]} is currently untracked, remember to add it to .gitignore or to encrypt it.` | |
`File ${newFilePaths[0]} is currently untracked, remember to add it to .gitignore or to encrypt it (e.g. with git-crypt).` |
log.warn( | ||
`Files ${newFilePaths.join( | ||
', ' | ||
)} are currently untracked, remember to add them to .gitignore or to encrypt them.` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggested change
)} are currently untracked, remember to add them to .gitignore or to encrypt them.` | |
)} are currently untracked, remember to add them to .gitignore or to encrypt them (e.g. with git-crypt).` |
Remember to add an entry to the changelog! |
wkozyra95
deleted the
@wkozyra95/detect-git-change-one-credentials-update
branch
August 21, 2020 13:14
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Why
Writing credentials to the project directory is potentially dangerous for inexperienced users, we want to detect situations where files created by us are not gitignored and warn users to take action.
How
We are checking if the file is visible to git but untracked, doing that this way ensures that only new files will trigger that warning.
We don't warn in other cases because if the file is tracked or staged it means that the user added it intentionally, plus we can't easily distinguish cases where credentials are encrypted and we don't want to warn the user in that case.
Test plan
run sync command in the turtle-v2-example repo with and without credentials.json