Created
April 4, 2013 13:30
-
-
Save yudai/5310346 to your computer and use it in GitHub Desktop.
Rewrite .git files to use a relative path in them
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'fileutils' | |
require 'pathname' | |
def ensure_relative_gitdir() | |
%x{git ls-files --error-unmatch --stage}.split("\n").each do |line| | |
value = line.split(" ") | |
if value[0] == "160000" | |
FileUtils.cd(value[3]) do | |
gitfile = ".git" | |
if File.file?(gitfile) && open(gitfile).read.match(/^gitdir: (.*)$/) && Pathname.new($1).absolute? | |
%x{git config --local core.worktree #{Pathname.new(FileUtils.pwd).relative_path_from(Pathname.new($1))}} | |
open(gitfile, "w") do |file| | |
file.puts("gitdir: #{Pathname.new($1).relative_path_from(Pathname.new(FileUtils.pwd))}") | |
end | |
ensure_relative_gitdir() | |
end | |
end | |
end | |
end | |
end | |
ensure_relative_gitdir() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment