Skip to content

Conversation

@pranavz28
Copy link
Contributor

This pull request introduces the new @percy/git-utils package, 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:

  • Added a comprehensive README.md for @percy/git-utils, detailing installation, usage, API reference, advanced features, and development instructions.

Package Configuration:

  • Created package.json for @percy/git-utils with metadata, build scripts, dependencies, and export settings for both ESM and CommonJS compatibility.

Implementation:

  • Added src/index.js as the public entry point, exporting all utility functions individually and as a grouped PercyGitUtils object, supporting both named and default exports.

Test Setup:

  • Added a local ESLint configuration for tests, enabling Jasmine and disabling certain import rules.

@pranavz28 pranavz28 requested a review from a team as a code owner November 2, 2025 23:10
@pranavz28 pranavz28 requested a review from Copilot November 3, 2025 05:28
Copy link
Contributor

Copilot AI left a 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.

@pranavz28 pranavz28 requested a review from Copilot November 3, 2025 08:21
Copy link
Contributor

Copilot AI left a 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.

@pranavz28 pranavz28 changed the title Git utils [PER-5885] Git utils package addition Nov 3, 2025
Comment on lines 236 to 244
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
}
Copy link
Contributor

Choose a reason for hiding this comment

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

revisit this logic,

Copy link
Contributor Author

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';
Copy link
Contributor

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

Copy link
Contributor Author

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';
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Comment on lines 223 to 229
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;
}
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Comment on lines 259 to 267
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
}
Copy link
Contributor

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,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Comment on lines 28 to 31
errorMsg.includes('index.lock') ||
errorMsg.includes('unable to create') ||
errorMsg.includes('file exists') ||
errorMsg.includes('another git process');
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

}
}

if (state.isShallow) {
Copy link
Contributor

Choose a reason for hiding this comment

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

add comment above

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added comments everywhere

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

Successfully merging this pull request may close these issues.

3 participants