Commits

Stefan Saasen committed 44b2324

Moved the git related scripts out of https://github.com/juretta/bin

Comments (0)

Files changed (5)

git-filesize-history

+#!/usr/bin/env ruby
+# == Synopsis 
+#
+# Show the filesize history of blobs for a given path in the current git repository
+#
+# == Usage
+#
+# git filesize-history PATH
+#
+# E.g.
+#
+# git filesize-history src/Test.hs
+#
+#   Commit  b5388a5:  976.56 KB
+#   Commit  18898db:   329.00 B
+#   Commit  ac52f2f:     7.00 B
+require 'rubygems'
+require 'rdoc/usage'
+
+begin
+  require 'grit'
+rescue LoadError
+  puts 'Please install the "grit" gem first.'
+  puts "\t[sudo] gem install grit"
+  exit -1
+end
+
+RDoc::usage('usage') if ARGV.size < 1
+
+class Numeric
+  def to_human
+    units = %w{B KB MB GB TB}
+    e = (Math.log(self)/Math.log(1024)).floor
+    s = "%.2f" % (to_f / 1024**e)
+    #s.sub(/\.?0*$/, units[e])
+    "#{s} #{units[e]}"
+  end
+end
+
+def clean_path_relative(path)
+  File.expand_path(path).gsub(File.expand_path("."), '').gsub(/^\//, '')
+end
+
+
+PATH = clean_path_relative(ARGV.first.to_s)
+
+repo = Grit::Repo.new('.')
+commits = repo.log('master', PATH)
+commits.each do |commit|
+  blob = commit.tree/PATH
+  puts "Commit #{commit.id_abbrev.rjust(8)}: #{blob.size.to_human.rjust(10)}" if blob
+end
+
+# vim: set filetype=ruby
+#!/bin/sh
+
+#
+# Find the commits that contain the given object id
+#
+
+if [ $# -lt 1 ]; then
+  echo "Usage: git find-blob SHA1 [git log options]"
+  echo ""
+  echo "    git find-blob 8e67180a935d28eba77ef1dbdb3daf5a837a67ac"
+  echo ""
+  exit -1
+fi
+
+blob="$1"
+shift
+git log "$@" --pretty=format:'%T %h %s' | while read tree commit subject ; do
+    if git ls-tree -r $tree | grep -q "${blob}" ; then
+        echo "${commit} ${subject}"
+    fi
+done
+
+# vim: set filetype=sh
+#!/bin/bash
+
+# vim :set ft=sh
+
+set -u
+
+# Show the changes on the remote that would be pulled in.
+# The script fetches all the changes first.
+#
+# If this script is in your $PATH it can be called like this:
+#
+#   git incoming
+#
+# The script requires git and ruby to be installed on your system.
+#
+# Copied from: https://raw.github.com/juretta/bin/master/git-incoming
+
+# Return the name of the current branch
+function current_branch {
+    git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'; 
+}
+
+CURRENT_BRANCH=`current_branch`
+
+# What branch are we tracking?
+TRACKING=$(git config branch.${CURRENT_BRANCH}.merge | ruby -ne 'print $_.gsub(/refs\/heads\//, "").strip')
+
+# What's the name of the remote?
+REMOTE=$(git config branch.${CURRENT_BRANCH}.remote)
+
+# Log options
+OPTS="--pretty=oneline --abbrev-commit --decorate"
+
+# URL of the remote we are tracking
+REMOTE_URL=$(git remote -v | ruby -e "puts STDIN.each_line.grep(/^${REMOTE}/).first.split[1]")
+
+# Fetch the changes from the remote.
+echo "Fetching changes from '"${REMOTE}"' (${REMOTE_URL})"
+git fetch -q
+
+# E.g. for 'master':
+#  git log master..origin/master
+CHANGES=$(env PAGER="" git log --color --exit-code $OPTS ${CURRENT_BRANCH}..${REMOTE}/${TRACKING})
+if [ $? -eq 0 ]; then
+    echo "No changes on ${REMOTE} that are not already available on this branch."
+else
+    echo "Changes on ${REMOTE}:"
+    echo "${CHANGES}"
+fi
+
+#!/bin/bash
+
+# vim :set ft=sh
+
+# Show the changes that need to be pushed to the remote the current branch is tracking.
+# If this script is in your $PATH it can be called like this:
+#
+#   git outgoing
+#
+# The script requires git and ruby to be installed on your system.
+#
+# Copied from: https://raw.github.com/juretta/bin/master/git-outgoing
+
+# Return the name of the current branch
+function current_branch {
+    git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'; 
+}
+
+CURRENT_BRANCH=`current_branch`
+
+# What branch are we tracking?
+TRACKING=$(git config branch.${CURRENT_BRANCH}.merge | ruby -ne 'print $_.gsub(/refs\/heads\//, "").strip')
+
+# What's the name of the remote?
+REMOTE=$(git config branch.${CURRENT_BRANCH}.remote)
+
+# Log options
+OPTS="--pretty=oneline --abbrev-commit --decorate --color"
+
+# URL of the remote we are tracking
+REMOTE_URL=$(git remote -v | ruby -e "puts STDIN.each_line.grep(/^${REMOTE}/).first.split[1]")
+
+# E.g. for 'master':
+#  git log master..origin/master
+CHANGES=$(env PAGER="" git log --exit-code $OPTS ${REMOTE}/${TRACKING}..${CURRENT_BRANCH})
+if [ $? -eq 0 ]; then
+    echo "No changes need to be pushed to ${REMOTE}"
+else
+    echo "Local changes that need to be pushed to ${REMOTE}:"
+    echo "${CHANGES}"
+fi
+

git-sync-local-tags

+#!/usr/bin/env ruby == Synopsis 
+#
+# Delete local tags that have been removed in the remote
+#
+# == Usage
+#
+#   git sync-local-tags
+#
+# Or use "-n" for dry-run and print out what would be deleted without actually
+# deleting any local tags.
+#
+#   git sync-local-tags -n
+
+module Git
+  class SyncTags
+
+    def orphaned_tags
+      local_tags - remote_tags
+    end
+
+    def remove_unused_tags(print_only = false)
+      puts "No orphaned tags" if orphaned_tags.empty?
+      orphaned_tags.each do |tag|
+        puts "deleting local tag #{tag}"
+        `git tag -d #{tag}` unless print_only
+      end
+    end
+
+    def local_tags
+    `git tag -l`.split
+    end
+
+    def remote_tags
+    `git ls-remote --tags origin | grep -v '\^{' | awk '{print $2}' | awk -F '/' '{print $3}'`.split
+    end
+
+  end
+end
+
+
+Git::SyncTags.new.remove_unused_tags(ARGV.include?("-n"))
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.