Skip to content

Instantly share code, notes, and snippets.

@ys
Created November 7, 2016 13:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ys/6b933d2371ba5adcfed4623ade25631d to your computer and use it in GitHub Desktop.
Save ys/6b933d2371ba5adcfed4623ade25631d to your computer and use it in GitHub Desktop.
def tar(path)
base_path = path.split("/")[0..-2].join("/")
folder = path.split("/")[-1]
if File.exist?(".gitignore")
ok = system("/usr/bin/tar -C \"#{base_path}\" --exclude='.git' --exclude-from=.gitignore -cvzf \"#{tempfile}\" \"#{folder}\"")
else
ok = system("/usr/bin/tar -C \"#{base_path}\" -cvzf \"#{tempfile}\" \"#{folder}\"")
end
unless ok
raise StandardError, $?
end
tempfile
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment