Skip to content

Commit

Permalink
Add automatic stash/unstash
Browse files Browse the repository at this point in the history
  • Loading branch information
dacmot committed Jul 19, 2022
1 parent 332d003 commit 8d29d30
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
3 changes: 1 addition & 2 deletions builder/lib-build-whynot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ function process_update_mods {
local TMPV=''
[[ $VERBOSITY == '--verbose' ]] && TMPV=$VERBOSITY
git add $TMPV .
TMPV=''
[[ $VERBOSITY == '--quiet' ]] && TMPV=$VERBOSITY
[[ $VERBOSITY == '--quiet' ]] && TMPV=$VERBOSITY || TMPV=''
git reset $TMPV $LOG
git commit $VERBOSITY -m "Update $modname from upstream."
fi
Expand Down
33 changes: 25 additions & 8 deletions builder/update_mods.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@ source "$PROJ"/builder/lib-build-whynot.sh
mkdir -p "$DST"
cd "$SRC"

# Overwrite old log
>"$LOG"
OLDSTASHSIZE=$(git stash list | wc -l)
echo -n "Stashing uncommited changes..."
[[ $VERBOSITY == '--quiet' ]] && TMPV=$VERBOSITY || TMPV=''
git stash push $VERBOSITY --include-untracked -m "update_mod.sh: stashing uncommitted changes before updating mods"
NEWSTASHSIZE=$(git stash list | wc -l)
[[ $OLDSTASHSIZE -lt $NEWSTASHSIZE ]] && echo " done." || echo " nothing to stash."

echo -n "Updating local repository..."
git submodule sync $VERBOSITY
Expand All @@ -37,15 +41,28 @@ echo -n "Updating submodules..."
git submodule update --init --recursive $VERBOSITY --jobs 4
echo " done."

# Overwrite old log
>"$LOG"

echo "Process updates of submodules..."
git submodule status | xargs -P 1 -n 3 bash -c 'source "$PROJ"/builder/lib-config-whynot.sh; process_update_mods "$@"' _

mkdir -p $DST/libs/whynot_compat
$RSYNC $SRC/libs/whynot_compat/ $DST/libs/whynot_compat/
git diff --quiet $DST/libs/whynot_compat || git commit $VERBOSITY -m "Update whynot_compat" $DST/libs/whynot_compat
# Update built-in mods (not submodules)
$RSYNC $SRC/libs/whynot_compat $DST/libs/
git diff --quiet -- $DST/libs/whynot_compat || git commit $VERBOSITY -m "Update whynot_compat" $DST/libs/whynot_compat

# Finalize mods update by commiting mod_sources.txt
git diff --quiet -- $LOG || git commit $VERBOSITY -m "Update mod_sources.txt" $LOG

git diff --quiet $LOG || git commit $VERBOSITY -m "Update mod_sources.txt" $LOG
if [[ $OLDSTASHSIZE -lt $NEWSTASHSIZE ]]; then
echo -n "Restoring uncommited changes from stash..."
git stash pop --index $VERBOSITY
echo " done."
fi

echo "Mods have been updated. Please review your commits before pushing using: "
echo ""
echo " git difftool origin/main"
echo "Mods have been updated as per your selections."
echo "Please review your commits before pushing using: "
echo ""
echo " git difftool origin/main"
echo ""

0 comments on commit 8d29d30

Please sign in to comment.