-
Notifications
You must be signed in to change notification settings - Fork 52
[PER-5885] Git utils package addition #2037
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
base: master
Are you sure you want to change the base?
Conversation
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.
Pull Request Overview
This PR introduces a new @percy/git-utils package that provides utility functions for Git operations with smart error handling, retry logic, and diagnostic capabilities. The package is designed for internal use by Percy CLI packages.
Key changes:
- New Git utility functions with retry logic for concurrent operations
- Comprehensive repository state diagnostics with helpful error messages
- Smart merge-base detection with fallback strategies
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/git-utils/src/git.js | Core implementation of Git utility functions including repository checks, commit operations, state diagnostics, and file operations |
| packages/git-utils/src/index.js | Package entry point that exports all Git utilities and provides a PercyGitUtils namespace |
| packages/git-utils/test/git.test.js | Comprehensive test suite covering all Git utility functions with unit and integration tests |
| packages/git-utils/test/.eslintrc | ESLint configuration for test files enabling Jasmine globals |
| packages/git-utils/package.json | Package configuration defining dependencies, scripts, and Node.js 14+ requirement |
| packages/git-utils/README.md | Documentation covering API reference, usage examples, and feature descriptions |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Pull Request Overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
| const commonBranches = ['main', 'master', 'develop', 'development']; | ||
| for (const branch of commonBranches) { | ||
| try { | ||
| await execGit(`git rev-parse --verify ${remoteName}/${branch}`); | ||
| state.defaultBranch = branch; | ||
| break; | ||
| } catch { | ||
| // Try next branch | ||
| } |
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.
revisit this logic,
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.
removed the array
| @@ -0,0 +1,500 @@ | |||
| import { spawn } from 'cross-spawn'; | |||
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.
move all git cmds into a config file
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.
done
| @@ -0,0 +1,500 @@ | |||
| import { spawn } from 'cross-spawn'; | |||
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.
add short description / comments above each method and the places wherever we're executing any git cmd
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.
done
packages/git-utils/src/git.js
Outdated
| const parents = await execGit('git rev-list --parents HEAD'); | ||
| const lines = parents.split('\n').filter(Boolean); | ||
| if (lines.length > 0) { | ||
| const firstLine = lines[lines.length - 1]; | ||
| const shas = firstLine.trim().split(/\s+/); | ||
| state.isFirstCommit = shas.length === 1; | ||
| } |
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.
try to find some shorter method to find the isFirstCommit
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.
done
packages/git-utils/src/git.js
Outdated
| const localBranches = ['main', 'master', 'develop', 'development']; | ||
| for (const branch of localBranches) { | ||
| try { | ||
| await execGit(`git rev-parse --verify ${branch}`); | ||
| state.defaultBranch = branch; | ||
| break; | ||
| } catch { | ||
| // Try next branch | ||
| } |
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.
revisit this as well, just like above,
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.
done
packages/git-utils/src/git.js
Outdated
| errorMsg.includes('index.lock') || | ||
| errorMsg.includes('unable to create') || | ||
| errorMsg.includes('file exists') || | ||
| errorMsg.includes('another git process'); |
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.
implement this in a single check
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.
done
| } | ||
| } | ||
|
|
||
| if (state.isShallow) { |
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.
add comment above
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.
added comments everywhere
This pull request introduces the new
@percy/git-utilspackage, which provides robust utility functions for interacting with git repositories. The changes include adding documentation, configuration, implementation, and test setup for the package.New Package Introduction and Documentation:
README.mdfor@percy/git-utils, detailing installation, usage, API reference, advanced features, and development instructions.Package Configuration:
package.jsonfor@percy/git-utilswith metadata, build scripts, dependencies, and export settings for both ESM and CommonJS compatibility.Implementation:
src/index.jsas the public entry point, exporting all utility functions individually and as a groupedPercyGitUtilsobject, supporting both named and default exports.Test Setup: