Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
e90671c
add closest match finding script
Dieterbe Jun 4, 2010
028851a
make a tarball of a specific tag/commit
Dieterbe Jun 4, 2010
7b80d97
helper script which helps you to find useful dangling trees (WIP)
Dieterbe Aug 4, 2010
3dac186
experimental script that checks if a local git repository contains an…
Dieterbe Aug 4, 2010
261a473
document edge case
Dieterbe Aug 4, 2010
7a44992
note about git svn
Dieterbe Aug 4, 2010
42ea369
use no pager when showing git stash list
Dieterbe Aug 4, 2010
3b7be5e
add script that tells you where the git repository root of any file/d…
Dieterbe Aug 11, 2010
2eafcd1
Dmenu-based wizard to add a path to an ignore rule
Dieterbe Aug 11, 2010
484cbec
Don't use confusing (GIT_DIR) variable name
Dieterbe Aug 11, 2010
7b3506f
write warnings/errors to stderr
Dieterbe Dec 1, 2010
32cb6d4
thanks to git rev-parse's new --show-toplevel flag, we can find the t…
Dieterbe Dec 1, 2010
132f7f0
check whether there is no branch setup yet. in that case any file mi…
Dieterbe Dec 1, 2010
582742c
content could be unique if there are no remotes
Dieterbe Dec 1, 2010
9f5c973
explain use case
Dieterbe Dec 1, 2010
3a4c5f2
proper way to get the current branch, without empty lines
Dieterbe Dec 1, 2010
e7c1c01
Better way to check whether commits in all branches have been pushed
Dieterbe Dec 1, 2010
42d1ea9
strip trailing whitespace
Dieterbe Dec 1, 2010
523821d
add more info messages so you know what's going on
Dieterbe Dec 1, 2010
ae41c79
Merge remote branch 'upstream/master'
Dieterbe Dec 1, 2010
f06e3cc
strip trailing whitespace
Dieterbe Dec 1, 2010
711c329
add readme
Dieterbe Dec 16, 2010
5861c1b
add git-interactive-merge script
Dieterbe Dec 25, 2010
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Git scripts written by different people.
Note: some scripts depend on each other, so it's a good idea to put all of them in your $PATH
2 changes: 1 addition & 1 deletion git-addremove
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh

git add -A
git ls-files --deleted -z | xargs -0 git rm
git ls-files --deleted -z | xargs -0 git rm
6 changes: 3 additions & 3 deletions git-apply-url
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/sh

# Copyright (c) 2008 Andrew Raines
#
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation
# files (the "Software"), to deal in the Software without
Expand All @@ -10,10 +10,10 @@
# copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following
# conditions:
#
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
Expand Down
25 changes: 25 additions & 0 deletions git-closest-match
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/sh
# 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)
# very useful to process the results of `git fsck --unreachable | cut -d\ -f3`

spec=$1
mode=${2:-diff} # num: number of lines or diff: actual diff/log message?
range=${3:-30} # 'all' or most recent <num> in current branch?. 'all' can be quite slow
if [ "$range" = 'all' ]; then
all=`git-rev-list --all | awk '/^commit/ {print $NF}'`
else
all=`git log -n $range | awk '/^commit/ {print $NF}'`
fi

commit=`for i in $all; do
echo -n "$i "
# why is there no git diff --shortnumstat ?
git diff -M $spec $i | wc -l
done | sort -k 2 -n | head -n 1 | cut -f 1 -d ' '`
if [ "$mode" = diff ]; then
git log --no-walk $commit | cat -
git diff -M $spec $commit | cat -
else
echo -n "$commit: "
git diff -M $spec $commit | wc -l
fi
2 changes: 1 addition & 1 deletion git-find
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ end

if $search_reflogs
puts "Processing reflogs ..."
$refs.each do |ref|
$refs.each do |ref|
unless ref == "refs/stash"
# Handle each reflog entry
`git reflog show --abbrev=40 #{ref}`.split("\n").each do |line|
Expand Down
2 changes: 1 addition & 1 deletion git-find-blob
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ filename=$1
want=$(git-hash-object "$filename")

git-rev-list --since="6 months ago" HEAD | while read commit ; do
git-ls-tree -r $commit | while read perm type hash filename; do
git-ls-tree -r $commit | while read perm type hash filename; do
if test "$want" = "$hash"; then
echo matched $filename in commit $commit
fi
Expand Down
8 changes: 8 additions & 0 deletions git-find-usefull-dangling-trees
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
depth={1:-all} # 'all' or number of depth

for i in $(git fsck --unreachable | egrep 'tree|commit' | cut -d\ -f3)
do
echo -n "U:$i CM:"
git-closest-match $i num $depth
done
12 changes: 6 additions & 6 deletions git-flatten.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ def git_dir
end

def git_editor
$git_editor ||= execute("git config core.editor", :one => true) ||
$git_editor ||= execute("git config core.editor", :one => true) ||
ENV['VISUAL'] || ENV['EDITOR'] || 'vi'
end

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

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

Expand Down Expand Up @@ -242,8 +242,8 @@ def flatten ref, refs, opts={}
die "A flatten is in progress, try --continue, --skip or --abort." if stored_last
squash = opts[:squash] || []
orig = parse_flatten ref, :read => true
target = rev_list ref,
"^#{git_branch}", "^#{orig}",
target = rev_list ref,
"^#{git_branch}", "^#{orig}",
*[refs, squash.map{|s| "^#{s}"}].flatten
end
last = stored_last
Expand Down
45 changes: 45 additions & 0 deletions git-ignore-wizard
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/bash
# take a file/directory as arg1, to be added to ignore rules.
# the user selects which ignore rules using dmenu
# in the .gitconfig case, we should probably allow the user to edit it,
# because he probably wants a more generic pattern instead of the real
# basename

file=$1
if [ -z "$file" -o ! -e "$file" ]
then
echo 'No such file or directory' >&2
exit 2
fi

type=`echo \
".gitignore-root # files all developers of this repo will want to exclude, in one central location
.gitignore-dirname # same, but ignore file in parent directory, so you can have multiple .gitignore files
exclude # specific to it's repo, but irrelevant to other devs
.gitconfig # patterns you want to ignore, independent of the repository
" | dmenu | cut -d ' ' -f1`

[ -z "$type" ] && echo 'Cancelled' && exit 0

dirname=` dirname $file`
basename=`basename $file`
case $type in
.gitignore-root)
root=`git root $file` || exit 2
dirname=$(readlink -f $dirname)
relative_dir=$(echo $dirname | sed "s#^$root##") # ie: /src
echo "$relative_dir/$basename" >> $root/.gitignore
;;
.gitignore-dirname)
git root $file >/dev/null || exit 2
echo "$basename" >> $dirname/.gitignore
;;
exclude)
root=`git root $file` || exit 2
dirname=$(readlink -f $dirname)
relative_dir=$(echo $dirname | sed "s#^$root##")
echo "$relative_dir/$basename" >> $root/info/exclude
;;
.gitconfig)
#TODO. git config --get-all ?, then another dmenu? how many such config keys are allowed?
esac
15 changes: 15 additions & 0 deletions git-interactive-merge
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash
if [ -z "$1" -o -z "$2" ]
then
echo "usage: $0 <from> <to>" >&2
exit 2
fi
from=$1
to=$2
git checkout $from
git checkout -b ${from}_tmp
# drops you in an editor, pick the changes you want
git rebase -i $to
git checkout $to
git pull . ${from}_tmp
git branch -d ${from}_tmp
2 changes: 1 addition & 1 deletion git-merge-changelog.c
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,7 @@ conflict_write (FILE *fp, struct conflict *c)

/* Long options. */
static const struct option long_options[] =
{
{
{ "help", no_argument, NULL, 'h' },
{ "split-merged-entry", no_argument, NULL, CHAR_MAX + 1 },
{ "version", no_argument, NULL, 'V' },
Expand Down
2 changes: 1 addition & 1 deletion git-merge-from-svn
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require 'fileutils'

$name = "git merge-from-svn"
$name = "git merge-from-svn"

def usage retcode=0
puts <<USAGE
Expand Down
2 changes: 1 addition & 1 deletion git-merge-repo
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

# Check arguments
if [ $# -ne 2 ]; then
echo 1>&2 Usage:
echo 1>&2 Usage:
echo 1>&2 " cd bigrepo"
echo 1>&2 " $0 repo /path/to/repo"
exit 127
Expand Down
2 changes: 1 addition & 1 deletion git-rank-contributors
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
## Probably not without some editing, because people often commit from more
## than one address.
##
## git-rank-contributors Copyright 2008 William Morgan <wmorgan-git-wt-add@masanjin.net>.
## git-rank-contributors Copyright 2008 William Morgan <wmorgan-git-wt-add@masanjin.net>.
## This program is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License, or (at
Expand Down
6 changes: 3 additions & 3 deletions git-record
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Hunk:
self.lines = lines
self.keep = False
self.binary = binary

def format(self):
output = self.diff.header.modified + "\n"
if self.diff.header.deleted:
Expand Down Expand Up @@ -77,7 +77,7 @@ class Diff:
for hunk in self.hunks:
hunk.diff = self
self.keep = False

def filter(self):
output = '\n'.join(self.header.lines) + "\n"
for hunk in self.hunks:
Expand All @@ -94,7 +94,7 @@ class Diff:
continue
output += diff.filter()
return output

@classmethod
def parse(kls, lines):
in_header = True
Expand Down
134 changes: 134 additions & 0 deletions git-remote-in-sync.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
#!/bin/bash
# checks if the specified remote(s) are in sync with what we have
# in other words: do we have anything which is not at the remote?
# Any commit, tag, branch, dirty WC/index or stashed state?
# This is especially useful if you're wondering:
# "is it safe to delete this clone? is any work here that needs to be
# distributed/shared/pushed first?"
# Note that there are some special cases, like a branch here may
# have a different name on the remote. This script is not aware of
# stuff like that. Also, `git status` will not detect if the local
# repo is ahead of an svn repo (using git svn)

# written by Dieter Plaetinck

list="$@"
[ -z "$list" ] && list=`git remote`
ret=0

if [ -z "`git branch`" ]
then
if [ $(cd $(git root) && ls -Al | egrep -v "^(.git|total)" | wc -l) -gt 0 ]
then
echo "WARN: This repo doesn't contain any branch, but contains a bunch of files!" >&2
ls -Alh $(git root)
ret=1
else
echo "INFO: This repo doesn't contain any branch, and is empty"
# note that stashing doesn't work without a branch, so the above check is sufficient
exit 0
fi
else
echo -n "INFO: Valid git repo with branches: "
git branch | tr '\n' ' '
echo
fi

if [ -z "$list" ]
then
echo "WARN: At least one branch, but no remotes found! The content here might be unique!" >&2
ret=1
else
if [ -n "$@" ]
then
echo "INFO: working with remote(s): $@"
echo "INFO: fyi, all remotes: "`git remote`
else
echo "INFO: working with all remotes: $list"
fi
fi

for remote in $list;
do
echo "INFO: Checking remote $remote.."
# Check commits and branches
# An approach where you `git push --all -n $remote 2>&1` and check whether the result is
# 'Everything up-to-date' can (and often will) yield
# "To prevent you from losing history, non-fast-forward updates were rejected"
# Since such an approach does traffic with the remote anyway, I choose to fetch the origin
# and inspect it's branches. This is a bit inefficient network-wise, but couldn't see a better solution
if ! git fetch $remote
then
echo " WARN: could not git fetch $remote" >&2
ret=1
fi
IFS_BACKUP=$IFS
IFS=$'\n'
for branch in `git branch`
do
branch=${branch/\*/};
branch_local=${branch// /}; # git branch prefixes branches with spaces. and spaces in branchnames are illegal.
if ! git branch -r --contains $branch_local 2>/dev/null | grep -q "^ $remote/"
then
echo " WARN: Branch $branch_local is not contained within remote $remote!" >&2
ret=1
else
echo " INFO: Branch $branch_local is contained within remote $remote"
fi
if ! git branch -r | grep -q "^ $remote/$branch_local"
then
echo " WARN: Branch $branch_local exists, but not $remote/$branch_local" >&2
ret=1
else
echo " INFO: Branch $branch_local exists also as $remote/$branch_local"
fi
done
IFS=$IFS_BACKUP

# Check tags
out=`git push --tags -n $remote 2>&1`
if [ "$out" != 'Everything up-to-date' ];
then
echo -e " WARN: Some tags are not in $remote!\n$out" >&2
ret=1
else
echo " INFO: All tags ("`git tag`") exist at $remote as well"
fi
done

# Check WC/index
cur_branch=`git branch | grep '^\* ' | cut -d ' ' -f2`
cur_branch=${cur_branch// /}
exp="# On branch $cur_branch
nothing to commit (working directory clean)"
out=`git status`
wc_ok=1
if [ "$out" != "$exp" ]
then
# usually i'd use bash regex, but this case is multiple-lines so bash regex is no go
out=$(echo "$out" | egrep -v "^(# On branch $cur_branch|# Your branch is behind .* commits, and can be fast-forwarded.|#|nothing to commit \(working directory clean\))$")
if [ -n "$out" ]
then
wc_ok=0
echo "WARN: Dirty WC or index" >&2
git status
ret=1
fi
fi
if [ $wc_ok -eq 1 ]
then
echo "INFO: Working copy/index are clean"
git status
fi

# Check stash
if [ `git stash list | wc -l` -gt 0 ];
then
echo "WARN: Dirty stash:" >&2
GIT_PAGER= git stash list >&2
ret=1
else
echo "INFO: Stash clean"
GIT_PAGER= git stash list
fi
exit $ret
14 changes: 14 additions & 0 deletions git-root
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/sh -e
# inspired by http://stackoverflow.com/questions/957928/is-there-a-way-to-get-to-the-git-root-directory-in-one-command/3009378#3009378
# gives absolute path to git repository root, either for cwd, or directory (or files' dirname) given as $1
# when not a git repository, exit >0
if [ -n "$1" ]
then
if [ -d "$1" ]
then
cd $1
else
cd `dirname $1`
fi
fi
exec git rev-parse --show-toplevel
Loading