Skip to content

Instantly share code, notes, and snippets.

@gipi
Last active April 4, 2023 05:10
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
  • Save gipi/5559210 to your computer and use it in GitHub Desktop.
Save gipi/5559210 to your computer and use it in GitHub Desktop.
Split a patch created with repo diff in a set of usable patches
#!/bin/sh
## Script to patch up diff reated by `repo diff`
# from https://groups.google.com/d/msg/repo-discuss/43juvD1qGIQ/7maptZVcEjsJ
if [ -z "$1" ] || [ ! -e "$1" ]; then
echo "Usages: $0 <repo_diff_file>";
exit 0;
fi
rm -fr _tmp_splits*
cat $1 | csplit -qf '' -b "_tmp_splits.%d.diff" - '/^project.*\/$/' '{*}'
working_dir=`pwd`
for proj_diff in `ls _tmp_splits.*.diff`
do
chg_dir=`cat $proj_diff | grep '^project.*\/$' | cut -d " " -f 2`
echo "FILE: $proj_diff $chg_dir"
if [ -e $chg_dir ]; then
( cd $chg_dir; \
cat $working_dir/$proj_diff | grep -v '^project.*\/$' | patch -Np1;);
else
echo "$0: Project directory $chg_dir don't exists.";
fi
@tot0rokr
Copy link

tot0rokr commented Apr 4, 2023

You missed the done statement in the for statement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment