Skip to content

Commit 038221d

Browse files
committed
Support git-uncommit and recommit from any subdirectory in addition to the worktree's top-level
1 parent de909f4 commit 038221d

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

git-recommit

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ fi
9292

9393
if [ -n "$patchdir" ]; then
9494
f="$patchdir""$(basename "$f")"
95+
else
96+
case "$f" in
97+
/*) : ;;
98+
*) f="$topleveldir"/"$f" ;;
99+
esac
95100
fi
96101

97102
if [ -z "$f" ]; then

git-uncommit

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/sh
22

3-
# Copyright (c) 2013 Michele Bini
3+
# Copyright (c) 2013, 2014 Michele Bini
44

55
# This program is free software: you can redistribute it and/or modify
66
# it under the terms of the version 3 of the GNU General Public License
@@ -49,6 +49,28 @@ selectbranch() {
4949
git symbolic-ref HEAD refs/heads/"$1"
5050
}
5151

52+
noerr() {
53+
"$@" 2>/dev/null
54+
}
55+
56+
# Top level of the work tree, if possible relative to current directory
57+
topleveldir="$(noerr git rev-parse --show-cdup || noerr git rev-parse --show-toplevel)"
58+
59+
# Current directory, relative to top level of work tree
60+
prefixdir="$(noerr git rev-parse --show-prefix)"
61+
62+
withfinalslash() {
63+
if [ -z "$1" ]; then return; fi
64+
case "$1" in
65+
*/) println "$1" ;;
66+
*) println "$1"/ ;;
67+
esac
68+
}
69+
70+
topleveldir="$(withfinalslash "$topleveldir")"
71+
prefixdir="$(withfinalslash "$prefixdir")"
72+
73+
5274
f="$(namecommit HEAD)"
5375
[ -z "f" ] && die "Internal error: Could not create patch name"
5476
f="$f".patch
@@ -61,9 +83,11 @@ git format-patch --binary -M70% -C70% -N -1 --stdout >"$f"
6183

6284
b="$(branchname)"
6385

86+
f="$prefixdir$f"
87+
6488
git checkout --quiet --detach HEAD^
6589

6690
println "Uncommit: $f"
67-
println "Uncommit: $f" >>.uncommitted-patches
91+
println "Uncommit: $f" >>"$topleveldir".uncommitted-patches
6892

6993
[ -n "$b" ] && selectbranch "$b" && git reset --soft HEAD^

0 commit comments

Comments
 (0)