Last active
August 29, 2015 14:06
-
-
Save konstantinbe/e601a15c2f8424c3824e to your computer and use it in GitHub Desktop.
git-auto-commit
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
... | |
[alias] | |
... | |
ac = auto-commit | |
... |
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 | |
# | |
# Copyright (c) 2010 Konstantin Bender. | |
# | |
# 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 restriction, including without limitation the rights | |
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
# 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 NONINFRINGEMENT. IN NO EVENT SHALL THE | |
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
# THE SOFTWARE. | |
# Getting Started | |
# | |
# Put this script into your path, then use with: | |
# | |
# git auto-commit | |
# | |
# You can also add a short git alias `ac` for that: | |
# | |
# git --global config alias.ac auto-commit | |
# | |
# ---------------------------------------------------------------- constants --- | |
OK = "\33[0m\33[32mOK\33[0m" | |
FAILED = "\33[0m\33[31mFAILED\33[0m" | |
# ---------------------------------------------------------------- functions --- | |
def assert(condition, message = "") | |
unless condition | |
puts message + "\n\n" | |
exit 1 | |
end | |
end | |
def check(condition) | |
unless condition | |
puts FAILED | |
exit 1 | |
end | |
end | |
def run(command) | |
success = system command | |
check success | |
end | |
def delete_file_if_exists(path) | |
run "rm -rf #{path}" if File.exists? path | |
end | |
def put(string) | |
print string | |
STDOUT.flush | |
end | |
def invoke(task) | |
Rake::Task[task].invoke | |
end | |
# ------------------------------------------------------------------- script --- | |
run "git add ." | |
status = `git status --porcelain` | |
added = status.scan(/\s*A\s+(.*)/) || [] | |
updated = status.scan(/\s*M\s+(.*)/) || [] | |
removed = status.scan(/\s*D\s+(.*)/) || [] | |
message = "Automatic commit" | |
# message << "\n\n" + "Updated: " if updated.size > 0 | |
# message << "\n\n " + updated.join("\n ") if updated.size > 0 | |
# | |
# message << "\n\n" + "Added: " if added.size > 0 | |
# message << "\n\n " + added.join("\n ") if added.size > 0 | |
# | |
# message << "\n\n" + "Removed: " if removed.size > 0 | |
# message << "\n\n " + removed.join("\n ") if removed.size > 0 | |
run "git commit -a -m '#{message}'" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment