Skip to content

Commit a999a0a

Browse files
committed
Merge pull request #2 from Dieterbe/master
some new scripts which are useful to me + whitespace cleanups
2 parents f3d27b0 + 5861c1b commit a999a0a

19 files changed

+285
-23
lines changed

README

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Git scripts written by different people.
2+
Note: some scripts depend on each other, so it's a good idea to put all of them in your $PATH

git-apply-url

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

33
# Copyright (c) 2008 Andrew Raines
4-
#
4+
#
55
# Permission is hereby granted, free of charge, to any person
66
# obtaining a copy of this software and associated documentation
77
# files (the "Software"), to deal in the Software without
@@ -10,10 +10,10 @@
1010
# copies of the Software, and to permit persons to whom the
1111
# Software is furnished to do so, subject to the following
1212
# conditions:
13-
#
13+
#
1414
# The above copyright notice and this permission notice shall be
1515
# included in all copies or substantial portions of the Software.
16-
#
16+
#
1717
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
1818
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
1919
# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND

git-closest-match

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/sh
2+
# find the closest match from all (or a limited amount) of the reachable trees to a specified tree (where tree is referenced by it's checksum)
3+
# very useful to process the results of `git fsck --unreachable | cut -d\ -f3`
4+
5+
spec=$1
6+
mode=${2:-diff} # num: number of lines or diff: actual diff/log message?
7+
range=${3:-30} # 'all' or most recent <num> in current branch?. 'all' can be quite slow
8+
if [ "$range" = 'all' ]; then
9+
all=`git-rev-list --all | awk '/^commit/ {print $NF}'`
10+
else
11+
all=`git log -n $range | awk '/^commit/ {print $NF}'`
12+
fi
13+
14+
commit=`for i in $all; do
15+
echo -n "$i "
16+
# why is there no git diff --shortnumstat ?
17+
git diff -M $spec $i | wc -l
18+
done | sort -k 2 -n | head -n 1 | cut -f 1 -d ' '`
19+
if [ "$mode" = diff ]; then
20+
git log --no-walk $commit | cat -
21+
git diff -M $spec $commit | cat -
22+
else
23+
echo -n "$commit: "
24+
git diff -M $spec $commit | wc -l
25+
fi

git-find

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ end
193193

194194
if $search_reflogs
195195
puts "Processing reflogs ..."
196-
$refs.each do |ref|
196+
$refs.each do |ref|
197197
unless ref == "refs/stash"
198198
# Handle each reflog entry
199199
`git reflog show --abbrev=40 #{ref}`.split("\n").each do |line|

git-find-blob

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ filename=$1
55
want=$(git-hash-object "$filename")
66

77
git-rev-list --since="6 months ago" HEAD | while read commit ; do
8-
git-ls-tree -r $commit | while read perm type hash filename; do
8+
git-ls-tree -r $commit | while read perm type hash filename; do
99
if test "$want" = "$hash"; then
1010
echo matched $filename in commit $commit
1111
fi

git-find-usefull-dangling-trees

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
depth={1:-all} # 'all' or number of depth
3+
4+
for i in $(git fsck --unreachable | egrep 'tree|commit' | cut -d\ -f3)
5+
do
6+
echo -n "U:$i CM:"
7+
git-closest-match $i num $depth
8+
done

git-flatten.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,13 @@ def git_dir
5454
end
5555

5656
def git_editor
57-
$git_editor ||= execute("git config core.editor", :one => true) ||
57+
$git_editor ||= execute("git config core.editor", :one => true) ||
5858
ENV['VISUAL'] || ENV['EDITOR'] || 'vi'
5959
end
6060

6161
def git_branch
62-
$git_branch ||= execute("git branch",
63-
:select => lambda{|l| l =~ /^\*/},
62+
$git_branch ||= execute("git branch",
63+
:select => lambda{|l| l =~ /^\*/},
6464
:filter => lambda{|l| l.sub(/\* /, '')},
6565
:one => true)
6666
end
@@ -71,7 +71,7 @@ def ref_to_hash ref
7171

7272
def hash_to_str hash
7373
token = '--token--'
74-
execute("git log -1 --pretty=format:'%h#{token}%s' #{hash}",
74+
execute("git log -1 --pretty=format:'%h#{token}%s' #{hash}",
7575
:one => true).split(/#{token}/)
7676
end
7777

@@ -242,8 +242,8 @@ def flatten ref, refs, opts={}
242242
die "A flatten is in progress, try --continue, --skip or --abort." if stored_last
243243
squash = opts[:squash] || []
244244
orig = parse_flatten ref, :read => true
245-
target = rev_list ref,
246-
"^#{git_branch}", "^#{orig}",
245+
target = rev_list ref,
246+
"^#{git_branch}", "^#{orig}",
247247
*[refs, squash.map{|s| "^#{s}"}].flatten
248248
end
249249
last = stored_last

git-ignore-wizard

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/bin/bash
2+
# take a file/directory as arg1, to be added to ignore rules.
3+
# the user selects which ignore rules using dmenu
4+
# in the .gitconfig case, we should probably allow the user to edit it,
5+
# because he probably wants a more generic pattern instead of the real
6+
# basename
7+
8+
file=$1
9+
if [ -z "$file" -o ! -e "$file" ]
10+
then
11+
echo 'No such file or directory' >&2
12+
exit 2
13+
fi
14+
15+
type=`echo \
16+
".gitignore-root # files all developers of this repo will want to exclude, in one central location
17+
.gitignore-dirname # same, but ignore file in parent directory, so you can have multiple .gitignore files
18+
exclude # specific to it's repo, but irrelevant to other devs
19+
.gitconfig # patterns you want to ignore, independent of the repository
20+
" | dmenu | cut -d ' ' -f1`
21+
22+
[ -z "$type" ] && echo 'Cancelled' && exit 0
23+
24+
dirname=` dirname $file`
25+
basename=`basename $file`
26+
case $type in
27+
.gitignore-root)
28+
root=`git root $file` || exit 2
29+
dirname=$(readlink -f $dirname)
30+
relative_dir=$(echo $dirname | sed "s#^$root##") # ie: /src
31+
echo "$relative_dir/$basename" >> $root/.gitignore
32+
;;
33+
.gitignore-dirname)
34+
git root $file >/dev/null || exit 2
35+
echo "$basename" >> $dirname/.gitignore
36+
;;
37+
exclude)
38+
root=`git root $file` || exit 2
39+
dirname=$(readlink -f $dirname)
40+
relative_dir=$(echo $dirname | sed "s#^$root##")
41+
echo "$relative_dir/$basename" >> $root/info/exclude
42+
;;
43+
.gitconfig)
44+
#TODO. git config --get-all ?, then another dmenu? how many such config keys are allowed?
45+
esac

git-interactive-merge

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
if [ -z "$1" -o -z "$2" ]
3+
then
4+
echo "usage: $0 <from> <to>" >&2
5+
exit 2
6+
fi
7+
from=$1
8+
to=$2
9+
git checkout $from
10+
git checkout -b ${from}_tmp
11+
# drops you in an editor, pick the changes you want
12+
git rebase -i $to
13+
git checkout $to
14+
git pull . ${from}_tmp
15+
git branch -d ${from}_tmp

git-merge-changelog.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,7 @@ conflict_write (FILE *fp, struct conflict *c)
808808

809809
/* Long options. */
810810
static const struct option long_options[] =
811-
{
811+
{
812812
{ "help", no_argument, NULL, 'h' },
813813
{ "split-merged-entry", no_argument, NULL, CHAR_MAX + 1 },
814814
{ "version", no_argument, NULL, 'V' },

0 commit comments

Comments
 (0)