#! /usr/bin/perl -w # git-track -- a program to mark uncommitted files as tracked by Git # See http://aaroncrane.co.uk/2008/04/tracking_git_files/ # Copyright 2008 Aaron Crane # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License version 2. use 5.008; use strict; use Getopt::Long qw; my $usage = "Usage: git-track FILE_OR_DIR...\n"; my %opt; if (!GetOptions(\%opt, 'help|?')) { print STDERR $usage; exit 1; } if ($opt{help}) { print STDOUT $usage; exit 0; } # Find the SHA-1 digest of a zero-byte file. It would be trivial to just # embed it as a constant instead, but advantage of asking `git hash-object` # to do it is that we can also ask it to put such an object into the object # database. Without that, we'd get spurious errors saying "unable to find # e69de29bb2d1d6434b8b29ae775ad8c2e48c5391" when diffing later. my $digest = qx[git hash-object -w --stdin < /dev/null]; exit $? if $?; chomp $digest; my @ls_files = qw; open my $ls_files, '-|', @ls_files, @ARGV or die "Can't pipe from git ls-files: $!\n"; open my $update_index, '| git update-index --index-info' or die "Can't pipe from git update-index: $!\n"; local $/ = "\0"; while (defined(my $file = <$ls_files>)) { chomp $file; my $mode = -x $file ? '100755' : '100644'; print {$update_index} "$mode $digest\t$file\n"; } close $ls_files; close $update_index or die "git update-index failed\n";