summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2010-10-01 21:51:43 +0200
committerJon Bergli Heier <snakebite@jvnv.net>2010-10-01 21:51:43 +0200
commit97aa60f5db1af6a984cedf474e6683178eb0cf81 (patch)
tree1a7debbfcc8dfee33c2b9df0bd804db85878cd8b
parent1814429bc645b7db8082744aa6fad2bdb84fd1c1 (diff)
Announce added and deleted tags.
-rwxr-xr-xgitnoti.py27
1 files changed, 18 insertions, 9 deletions
diff --git a/gitnoti.py b/gitnoti.py
index 82216a4..13bc6ae 100755
--- a/gitnoti.py
+++ b/gitnoti.py
@@ -43,8 +43,9 @@ class NotifyRepo(object):
self.bot = bot
self.repo = git.Repo(path)
flags = pyinotify.EventsCodes.ALL_FLAGS
- self.wdd = bot.wm.add_watch(os.path.join(path, 'refs/heads'), flags['IN_MODIFY'] | flags['IN_CREATE'])
+ self.wdd = bot.wm.add_watch([os.path.join(path, 'refs/heads'), os.path.join(path, 'refs/tags')], flags['IN_MODIFY'] | flags['IN_CREATE'])
self.heads = dict([(h.name, h.commit.sha) for h in self.repo.heads])
+ self.tags = [t.name for t in self.repo.tags]
def repo_commit_msg(repo, branch, commits):
reponame = os.path.splitext(os.path.basename(repo.working_dir))[0]
@@ -98,16 +99,14 @@ class ReposNotifyEvent(pyinotify.ProcessEvent):
tags = os.path.join(event.pathname, 'refs/tags')
i = 0
- # Wait max 10 seconds for refs/heads/ to appear.
- while not os.access(heads, os.F_OK) and i < 10:
+ # Wait max 10 seconds for refs/heads/ and refs/tags/ to appear.
+ while not os.access(heads, os.F_OK) and not os.access(tags, os.F_OK) and i < 10:
time.sleep(1)
i += 1
if not os.access(heads, os.F_OK):
- self.bot.gitmsg('Repo %s was found but couldn''t locate refs/heads/ (repo NOT added).' % os.path.splitext(event.name)[0])
+ self.bot.gitmsg('Repo %s was found but couldn''t locate refs/heads/ or refs/tags/ (repo NOT added).' % os.path.splitext(event.name)[0])
return
- wdd1 = self.bot.wm.add_watch(heads, flags['IN_MODIFY'] | flags['IN_CREATE'])
- wdd2 = self.bot.wm.add_watch(heads, flags['IN_MODIFY'] | flags['IN_CREATE'])
repos[event.pathname] = NotifyRepo(self.bot, event.pathname)
self.bot.gitmsg('New repo: %s' % os.path.splitext(event.name)[0])
@@ -129,9 +128,14 @@ class ReposNotifyEvent(pyinotify.ProcessEvent):
# Assume deleted if neither file exists.
if not os.access(newname, os.F_OK) and not os.access(event.pathname, os.F_OK):
- del repos[pathname].heads[os.path.basename(newname)]
- self.bot.gitmsg('Branch \002%s\002 from repo \002%s\002 was deleted.' %
- (os.path.basename(newname), os.path.splitext(os.path.basename(pathname))[0]))
+ if os.path.dirname(newname).endswith('refs/heads'):
+ del repos[pathname].heads[os.path.basename(newname)]
+ self.bot.gitmsg('Branch \002%s\002 from repo \002%s\002 was deleted.' %
+ (os.path.basename(newname), os.path.splitext(os.path.basename(pathname))[0]))
+ elif os.path.dirname(newname).endswith('refs/tags'):
+ repos[pathname].tags.remove(os.path.basename(newname))
+ self.bot.gitmsg('Tag \002%s\002 from repo \002%s\002 was deleted.' %
+ (os.path.basename(newname), os.path.splitext(os.path.basename(pathname))[0]))
return
l = repos[pathname]
@@ -155,6 +159,11 @@ class ReposNotifyEvent(pyinotify.ProcessEvent):
self.bot.gitmsg(msg)
l.heads[h.name] = h.commit.sha
+ for t in (t for t in repo.tags if t.name not in l.tags):
+ reponame = os.path.splitext(os.path.basename(repo.working_dir))[0]
+ self.bot.gitmsg('New tag \002%s\002 for repo \002%s\002 points to \002%s\002' % (t.name, reponame, t.commit.sha[:7]))
+ l.tags.append(t.name)
+
def process_IN_CREATE(self, event):
if os.path.dirname(event.pathname) == root:
self.new_repo(event)