Last active
February 1, 2023 03:32
-
-
Save ItaruTran/18e6bdbfba769cb02851b6df6e9bb5cd to your computer and use it in GitHub Desktop.
Save and restore work-in-progress code π§
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ErrorActionPreference = "Stop" | |
$PREFIX='WIP' | |
$IGNORE_FILE='.working.gitignore' | |
$SAVED_IGNORE_FILE='.project.gitignore' | |
$is_restore = $args[0] -eq '-r' | |
if ($is_restore) { | |
echo 'restore' | |
$branch_name="$(git rev-parse --abbrev-ref HEAD)" | |
if ($branch_name.StartsWith($PREFIX)) { | |
git reset HEAD~ | |
git push origin --delete $branch_name | |
if ([System.IO.File]::Exists($SAVED_IGNORE_FILE)) { | |
mv .gitignore $IGNORE_FILE | |
mv $SAVED_IGNORE_FILE .gitignore | |
} | |
} else { | |
echo "Can't restore $branch_name" | |
} | |
} else { | |
echo 'saving' | |
if ([System.IO.File]::Exists($IGNORE_FILE)) { | |
mv .gitignore $SAVED_IGNORE_FILE | |
mv $IGNORE_FILE .gitignore | |
} | |
$branch_name="$PREFIX/$(Get-Date -format 'yyyy-MM-dd')" | |
git checkout -b $branch_name | |
git add -A | |
git commit -m "$(echo 'π§ Save working code')" | |
git push origin $branch_name | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
PREFIX=WIP | |
IGNORE_FILE='.working.gitignore' | |
SAVED_IGNORE_FILE='.project.gitignore' | |
if [[ $1 == '-r' ]]; then | |
echo 'restore ...' | |
branch_name="$(git rev-parse --abbrev-ref HEAD)" | |
if [[ $branch_name == "$PREFIX"* ]] ; then | |
git reset HEAD~ | |
git push origin --delete $branch_name | |
if test -f "$SAVED_IGNORE_FILE"; then | |
mv .gitignore $IGNORE_FILE | |
mv $SAVED_IGNORE_FILE .gitignore | |
fi | |
else | |
echo "Can't restore $branch_name" | |
fi | |
else | |
echo 'saving ...' | |
if test -f "$IGNORE_FILE"; then | |
mv .gitignore $SAVED_IGNORE_FILE | |
mv $IGNORE_FILE .gitignore | |
fi | |
branch_name="$PREFIX/$(date '+%Y-%m-%d')" | |
git checkout -b $branch_name | |
git add -A | |
git commit -m 'π§ Save working code' | |
git push origin $branch_name | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment