mirror of
https://code.forgejo.org/actions/checkout.git
synced 2025-08-14 17:30:50 +00:00
try preserve local changes option
This commit is contained in:
parent
9f265659d3
commit
45fe6460ed
6 changed files with 59 additions and 6 deletions
|
@ -22,7 +22,7 @@ export interface IGitCommandManager {
|
|||
disableSparseCheckout(): Promise<void>
|
||||
sparseCheckout(sparseCheckout: string[]): Promise<void>
|
||||
sparseCheckoutNonConeMode(sparseCheckout: string[]): Promise<void>
|
||||
checkout(ref: string, startPoint: string): Promise<void>
|
||||
checkout(ref: string, startPoint: string, options?: string[]): Promise<void>
|
||||
checkoutDetach(): Promise<void>
|
||||
config(
|
||||
configKey: string,
|
||||
|
@ -203,8 +203,21 @@ class GitCommandManager {
|
|||
)
|
||||
}
|
||||
|
||||
async checkout(ref: string, startPoint: string): Promise<void> {
|
||||
const args = ['checkout', '--progress', '--force']
|
||||
async checkout(
|
||||
ref: string,
|
||||
startPoint: string,
|
||||
options: string[] = []
|
||||
): Promise<void> {
|
||||
const args = ['checkout', '--progress']
|
||||
|
||||
// Add custom options (like --merge) if provided
|
||||
if (options.length > 0) {
|
||||
args.push(...options)
|
||||
} else {
|
||||
// Default behavior - use force
|
||||
args.push('--force')
|
||||
}
|
||||
|
||||
if (startPoint) {
|
||||
args.push('-B', ref, startPoint)
|
||||
} else {
|
||||
|
|
|
@ -229,7 +229,15 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> {
|
|||
|
||||
// Checkout
|
||||
core.startGroup('Checking out the ref')
|
||||
await git.checkout(checkoutInfo.ref, checkoutInfo.startPoint)
|
||||
if (settings.preserveLocalChanges) {
|
||||
core.info('Attempting to preserve local changes during checkout')
|
||||
// Use --merge to preserve local changes if possible
|
||||
// This will fail if there are merge conflicts, but that's expected behavior
|
||||
await git.checkout(checkoutInfo.ref, checkoutInfo.startPoint, ['--merge'])
|
||||
} else {
|
||||
// Use the default behavior with --force
|
||||
await git.checkout(checkoutInfo.ref, checkoutInfo.startPoint)
|
||||
}
|
||||
core.endGroup()
|
||||
|
||||
// Submodules
|
||||
|
|
|
@ -25,10 +25,15 @@ export interface IGitSourceSettings {
|
|||
commit: string
|
||||
|
||||
/**
|
||||
* Indicates whether to clean the repository
|
||||
* Whether to execute git clean and git reset before fetching
|
||||
*/
|
||||
clean: boolean
|
||||
|
||||
/**
|
||||
* Whether to preserve local changes during checkout
|
||||
*/
|
||||
preserveLocalChanges: boolean
|
||||
|
||||
/**
|
||||
* The filter determining which objects to include
|
||||
*/
|
||||
|
|
|
@ -82,6 +82,10 @@ export async function getInputs(): Promise<IGitSourceSettings> {
|
|||
result.clean = (core.getInput('clean') || 'true').toUpperCase() === 'TRUE'
|
||||
core.debug(`clean = ${result.clean}`)
|
||||
|
||||
// Preserve local changes
|
||||
result.preserveLocalChanges = (core.getInput('preserveLocalChanges') || 'false').toUpperCase() === 'TRUE'
|
||||
core.debug(`preserveLocalChanges = ${result.preserveLocalChanges}`)
|
||||
|
||||
// Filter
|
||||
const filter = core.getInput('filter')
|
||||
if (filter) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue