Scripts to restore commonly changes files (#18578)
This commit is contained in:
parent
c0f4c586c2
commit
c885fca733
2 changed files with 125 additions and 0 deletions
45
src/SourceBuild/content/eng/restore-build-edited-files.ps1
Normal file
45
src/SourceBuild/content/eng/restore-build-edited-files.ps1
Normal file
|
@ -0,0 +1,45 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
Script to perform git restore for a set of commonly edited paths when building the VMR.
|
||||
|
||||
.DESCRIPTION
|
||||
This script restores the specified paths using git restore command. It provides options for logging, confirmation, and parameterized restore.
|
||||
|
||||
.PARAMETER PathsToRestore
|
||||
Specifies the paths to be restored. Default paths are:
|
||||
- src/*/eng/common/*
|
||||
- src/*global.json
|
||||
|
||||
.PARAMETER LogPath
|
||||
Specifies the path to save the log file. Default is 'restore.log' in the script directory.
|
||||
|
||||
.PARAMETER NoPrompt
|
||||
Indicates whether to skip the confirmation prompt. If specified, the script will restore the paths without confirmation.
|
||||
|
||||
#>
|
||||
|
||||
param (
|
||||
[string[]]$PathsToRestore = @(
|
||||
"src/*/eng/common/*",
|
||||
"src/*global.json"
|
||||
),
|
||||
[Alias("y")]
|
||||
[switch]$NoPrompt = $false
|
||||
)
|
||||
|
||||
# Confirmation prompt
|
||||
if (-not $NoPrompt) {
|
||||
Write-Host "Will restore changes in the following paths:"
|
||||
foreach ($path in $PathsToRestore) {
|
||||
Write-Host " $path"
|
||||
}
|
||||
$choice = Read-Host "Do you want to proceed with restoring the paths? (Y/N)"
|
||||
if (-not $($choice -ieq "Y")) {
|
||||
exit 0
|
||||
}
|
||||
}
|
||||
|
||||
# Perform git restore for each path
|
||||
foreach ($path in $PathsToRestore) {
|
||||
git -C (Split-Path -Path $PSScriptRoot -Parent) restore $path
|
||||
}
|
80
src/SourceBuild/content/eng/restore-build-edited-files.sh
Executable file
80
src/SourceBuild/content/eng/restore-build-edited-files.sh
Executable file
|
@ -0,0 +1,80 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Help message
|
||||
show_help() {
|
||||
echo "Script to perform git restore for a set of commonly edited paths when building the VMR."
|
||||
echo ""
|
||||
echo "Usage: $0 [-h] [-p <path>] [-n]"
|
||||
echo ""
|
||||
echo "Options:"
|
||||
echo " -h, --help Show this help message and exit"
|
||||
echo " -p, --path <path> Specify the paths to be restored (default: src/*/eng/common/*, src/*global.json)"
|
||||
echo " -y, --noprompt Skip the confirmation prompt"
|
||||
echo ""
|
||||
echo "Example:"
|
||||
echo " $0 -p \"src/*/eng/common/*\" -p \"src/*global.json\""
|
||||
echo ""
|
||||
exit 0
|
||||
}
|
||||
|
||||
source="${BASH_SOURCE[0]}"
|
||||
# resolve $source until the file is no longer a symlink
|
||||
while [[ -h "$source" ]]; do
|
||||
scriptroot="$( cd -P "$( dirname "$source" )" && pwd )"
|
||||
source="$(readlink "$source")"
|
||||
# if $source was a relative symlink, we need to resolve it relative to the path where the
|
||||
# symlink file was located
|
||||
[[ $source != /* ]] && source="$scriptroot/$source"
|
||||
done
|
||||
scriptroot="$( cd -P "$( dirname "$source" )" && pwd )"
|
||||
|
||||
# Default paths to restore
|
||||
DefaultPathsToRestore=(
|
||||
"src/*/eng/common/*"
|
||||
"src/*global.json"
|
||||
)
|
||||
PathsToRestore=()
|
||||
NoPrompt=false
|
||||
|
||||
# Parse command line arguments
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case $1 in
|
||||
-h|--help)
|
||||
show_help
|
||||
;;
|
||||
-p|--path)
|
||||
shift
|
||||
PathsToRestore+=("$1")
|
||||
;;
|
||||
-y|--noprompt)
|
||||
NoPrompt=true
|
||||
;;
|
||||
*)
|
||||
echo "Invalid option: $1"
|
||||
show_help
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
# Use default paths if no paths are passed
|
||||
if [ ${#PathsToRestore[@]} -eq 0 ]; then
|
||||
PathsToRestore=("${DefaultPathsToRestore[@]}")
|
||||
fi
|
||||
|
||||
# Confirmation prompt
|
||||
if [ "$NoPrompt" = false ]; then
|
||||
echo "Will restore changes in the following paths:"
|
||||
for path in "${PathsToRestore[@]}"; do
|
||||
echo " $path"
|
||||
done
|
||||
read -p "Do you want to proceed with restoring the paths? (Y/N)" choice
|
||||
if [[ ! "$choice" =~ ^[Yy]$ ]]; then
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
|
||||
# Perform git restore for each path
|
||||
for path in "${PathsToRestore[@]}"; do
|
||||
git -C "$(dirname "$scriptroot")" restore "$path"
|
||||
done
|
Loading…
Reference in a new issue