-
Notifications
You must be signed in to change notification settings - Fork 0
/
git-cleanuppatch
executable file
·51 lines (40 loc) · 1.1 KB
/
git-cleanuppatch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/bash
#
# Copyright (c) 2012 Daniel Gryniewicz
#
# Clean up crutf left over from patching a git repo
# Set usage output
DESCRIPTION="Clean up cruft left over from patching a git repo"
USAGE="[-h |--help]"
LONGUSAGE="\t-h, --help\n\t\tPrint this help message"
# Standard functions
GTWS_LOC=$(readlink -f $(dirname "$0"))
source ${GTWS_LOC}/gtws.sh
# Script name
ME=$(basename $0)
# Parse arguments
ARGS=`getopt -o h --long help -n "${ME}" -- "$@"`
if [ $? != 0 ] ; then
usage
fi
eval set -- "$ARGS"
while true ; do
case "$1" in
-h|--help) usage; shift ;;
--) shift ; break ;;
* ) usage "Invalid argument $1";;
esac
done
# Remaining arguments are in $1, $2, etc. as normal
SUBDIRECTORY_OK=Yes
OPTIONS_SPEC=
LONG_USAGE="${LONGUSAGE}"
# Source the git environment
source "$(git --exec-path)/git-sh-setup"
PREFIX=$(git rev-parse --show-prefix)
SEDC='s#?? ##'
if [ -n "${PREFIX}" ]; then
SEDC="${SEDC};s#${PREFIX}##"
fi
git status --porcelain | grep '^??' | grep ".orig" | sed "${SEDC}" | xargs rm -r 2>/dev/null
git status --porcelain | grep '^??' | grep ".rej" | sed "${SEDC}" | xargs rm -r 2>/dev/null