From b27ec72efe8e74359a0b4831c7b21465d5b12193 Mon Sep 17 00:00:00 2001 From: raccoon Date: Mon, 2 Mar 2026 12:06:35 +0500 Subject: [PATCH] Added convenience shell scripts --- README.md | 8 ++++++++ repo-cleanup.cmd | 25 +++++++++++++++++++++++++ repo-cleanup.sh | 18 ++++++++++++++++++ repo-discard.cmd | 27 +++++++++++++++++++++++++++ repo-discard.sh | 20 ++++++++++++++++++++ repo-reset.cmd | 42 ++++++++++++++++++++++++++++++++++++++++++ repo-reset.sh | 33 +++++++++++++++++++++++++++++++++ 7 files changed, 173 insertions(+) create mode 100644 repo-cleanup.cmd create mode 100755 repo-cleanup.sh create mode 100644 repo-discard.cmd create mode 100755 repo-discard.sh create mode 100644 repo-reset.cmd create mode 100755 repo-reset.sh diff --git a/README.md b/README.md index 110844a..819c0a7 100644 --- a/README.md +++ b/README.md @@ -61,6 +61,14 @@ or run this command in project's folder on Windows > this is because VPM has not loaded yet and didn't resolved the required packages, ignore the errors and continue loading. > Sometimes you may need to reopen the project couple times for all packages to resolve and scripts to recompile. +## Convenience scripts + +The template also have some convenience shell scripts for both Windows and Linux: + +- `./repo-cleanup.*` - Cleans up all untracked trash in the working tree (i.e. `Library/`, `Build/`, etc.) +- `./repo-discard.*` - Reverts all changed files back to the state of the last commit +- `./repo-reset.*` - Completely resets the state of the local repo to the state of the remote repository (dangerous, use with caution!) + ## License For project's license see [LICENSE](./LICENSE) file. diff --git a/repo-cleanup.cmd b/repo-cleanup.cmd new file mode 100644 index 0000000..2353c9c --- /dev/null +++ b/repo-cleanup.cmd @@ -0,0 +1,25 @@ +@ECHO OFF +TITLE Clean up Unity Project repo +SETLOCAL EnableDelayedExpansion + +CD "%~dp0" +git rev-parse --is-inside-work-tree >NUL || GOTO die + +git clean -dfX --dry-run "%~dp0." || GOTO die + +ECHO. +CHOICE /M "Execute" +IF !ERRORLEVEL! NEQ 1 ( + ECHO Aborting cleanup... +) ELSE ( + git clean -dfX "%~dp0." || GOTO die + ECHO Done. +) + +:end +PAUSE +EXIT /B 0 + +:die +PAUSE +EXIT /B %ERRORLEVEL% diff --git a/repo-cleanup.sh b/repo-cleanup.sh new file mode 100755 index 0000000..78d0f39 --- /dev/null +++ b/repo-cleanup.sh @@ -0,0 +1,18 @@ +#!/bin/sh -e + +repository="$(dirname "$(readlink -f "$0")")/." + +cd "${repository}" +git rev-parse --is-inside-work-tree >/dev/null + +git clean -dfX --dry-run "${repository}" + +printf "\nExecute [Y,N]?"; read -r yn +if [ "$yn" = "${yn#[Yy]}" ]; then + echo "Aborting cleanup..." +else + git clean -dfX "${repository}" + echo "Done." +fi + +exit 0 diff --git a/repo-discard.cmd b/repo-discard.cmd new file mode 100644 index 0000000..162bf12 --- /dev/null +++ b/repo-discard.cmd @@ -0,0 +1,27 @@ +@ECHO OFF +TITLE Restore Unity Project repo +SETLOCAL + +CD "%~dp0" +git rev-parse --is-inside-work-tree >NUL || GOTO die + +ECHO. +ECHO *** WARNING: The following files were changed and will be reverted: +git diff --name-only HEAD + +ECHO. +CHOICE /M "Execute" +IF %ERRORLEVEL% NEQ 1 ( + ECHO Aborting discard... +) ELSE ( + git restore "%~dp0." || GOTO die + ECHO Done. +) + +:end +PAUSE +EXIT /B 0 + +:die +PAUSE +EXIT /B %ERRORLEVEL% diff --git a/repo-discard.sh b/repo-discard.sh new file mode 100755 index 0000000..cf32509 --- /dev/null +++ b/repo-discard.sh @@ -0,0 +1,20 @@ +#!/bin/sh -e + +repository="$(dirname "$(readlink -f "$0")")/." + +cd "${repository}" +git rev-parse --is-inside-work-tree >/dev/null + +echo "" +echo "*** WARNING: The following files were changed and will be reverted:" +git diff --name-only HEAD + +printf "\nExecute [Y,N]?"; read -r yn +if [ "$yn" = "${yn#[Yy]}" ]; then + echo "Aborting discard..." +else + git restore "${repository}" + echo "Done." +fi + +exit 0 diff --git a/repo-reset.cmd b/repo-reset.cmd new file mode 100644 index 0000000..a5b3b15 --- /dev/null +++ b/repo-reset.cmd @@ -0,0 +1,42 @@ +@ECHO OFF +TITLE Reset Unity Project repo +SETLOCAL + +CD "%~dp0" +git rev-parse --is-inside-work-tree >NUL || GOTO die + +FOR /F "delims=" %%x IN ('git rev-parse --abbrev-ref "@{u}" 2^>NUL') DO SET "upstream=%%x" +IF NOT DEFINED upstream ( + ECHO *** ERROR: No upstream is configured for current branch + GOTO die +) + +git fetch --all || GOTO die + +ECHO. +ECHO Going to reset current branch to: %upstream% + +ECHO. +ECHO *** WARNING: These local commits will be lost: +git log "%upstream%..HEAD" --oneline + +ECHO. +ECHO *** WARNING: These local files will be reset: +git diff "HEAD..%upstream%" --name-only + +ECHO. +CHOICE /M "Execute" +IF %ERRORLEVEL% NEQ 1 ( + ECHO Aborting reset... +) ELSE ( + git reset --hard "%upstream%" || GOTO die + ECHO Done. +) + +:end +PAUSE +EXIT /B 0 + +:die +PAUSE +EXIT /B %ERRORLEVEL% diff --git a/repo-reset.sh b/repo-reset.sh new file mode 100755 index 0000000..7db61c6 --- /dev/null +++ b/repo-reset.sh @@ -0,0 +1,33 @@ +#!/bin/sh -e + +cd "$(dirname "$(readlink -f "$0")")" +git rev-parse --is-inside-work-tree >/dev/null + +upstream="$(git rev-parse --abbrev-ref "@{u}" 2>/dev/null || true)" +if [ -z "$upstream" ]; then + echo "*** ERROR: No upstream is configured for current branch" + exit 1 +fi + +git fetch --all + +echo "" +echo "Going to reset current branch to: ${upstream}" + +echo "" +echo "*** WARNING: These local commits will be lost:" +git log "${upstream}..HEAD" --oneline + +echo "" +echo "*** WARNING: These local files will be reset:" +git diff "HEAD..${upstream}" --name-only + +printf "\nExecute [Y,N]?"; read -r yn +if [ "$yn" = "${yn#[Yy]}" ]; then + echo "Aborting reset..." +else + git reset --hard "$upstream" + echo "Done." +fi + +exit 0