From b002bc4e2bed7f49f6c3877339bf58c7d95eba10 Mon Sep 17 00:00:00 2001 From: Bill Peck Date: Wed, 6 May 2015 16:18:29 -0400 Subject: Updated list tasks --- git_taskrepo/sub_commands/cmd_init.py | 41 ++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 13 deletions(-) (limited to 'git_taskrepo/sub_commands/cmd_init.py') diff --git a/git_taskrepo/sub_commands/cmd_init.py b/git_taskrepo/sub_commands/cmd_init.py index 592f7d3..e59f6a5 100644 --- a/git_taskrepo/sub_commands/cmd_init.py +++ b/git_taskrepo/sub_commands/cmd_init.py @@ -50,7 +50,7 @@ class Init(Command): self.parser.error("Your git repo doesn't have a origin specified. use --origin") remote = kwargs.get("origin") or self.repo.remotes.origin.url - if remote.startswith("ssh://"): + if remote.startswith("ssh://") or remote.startswith("git+ssh://"): self.parser.error("remote origin is %s, you must specify an origin that doesn't need authentication. use --origin" % remote) print("Initializing taskrepo:") @@ -63,9 +63,10 @@ class Init(Command): cur = self.taskrepo.cursor() # Create tables if needed cur.execute("CREATE TABLE IF NOT EXISTS config(origin TEXT NOT NULL)") - cur.execute("CREATE TABLE IF NOT EXISTS tasks(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL)") - cur.execute("CREATE TABLE IF NOT EXISTS key_value_inc(task_id INTEGER, key TEXT NOT NULL, value TEXT NOT NULL)") - cur.execute("CREATE TABLE IF NOT EXISTS key_value_exc(task_id INTEGER, key TEXT NOT NULL, value TEXT NOT NULL)") + cur.execute("CREATE TABLE IF NOT EXISTS tasks(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL, description TEXT, owner TEXT)") + cur.execute("CREATE TABLE IF NOT EXISTS types(task_id INTEGER, value TEXT NOT NULL)") + cur.execute("CREATE TABLE IF NOT EXISTS runfor(task_id INTEGER, value TEXT NOT NULL)") + cur.execute("CREATE TABLE IF NOT EXISTS bugs(task_id INTEGER, value TEXT NOT NULL)") cur.execute("DELETE FROM config") cur.execute("INSERT INTO config(origin) VALUES (?)", (remote,)) @@ -84,7 +85,7 @@ class Init(Command): index.add([gitignore]) # if we updated the repo then commit it - if self.repo.is_dirty(): + if self.repo.is_dirty(working_tree=False): assert index.commit("Initialized to use git taskrepo.").type == 'commit' print(" - committed to git") @@ -92,9 +93,7 @@ class Init(Command): post_commit_hook = """\ #!/bin/sh -echo "post-commit" - -git diff --name-only HEAD@{1} HEAD | \ +git diff-tree -r --name-only --no-commit-id HEAD@{1} HEAD | \ while read file; do echo "$file" | grep 'Makefile$' -q if [ $? -eq 0 ]; then @@ -112,13 +111,11 @@ done post_checkout_hook = """\ #!/bin/sh -echo "post-checkout" - previous_head=$1 new_head=$2 is_branch_checkout=$3 -git diff --name-only $1 $2 | \ +git diff-tree -r --name-only --no-commit-id $1 $2 | \ while read file; do echo "$file" | grep 'Makefile$' -q if [ $? -eq 0 ]; then @@ -133,6 +130,24 @@ done os.chmod("%s/hooks/post-checkout" % self.repo.git_dir, 0755) print(" - Installed post-checkout hook") + post_merge_hook = """\ +#!/bin/sh + +git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD | \ +while read file; do + echo "$file" | grep 'Makefile$' -q + if [ $? -eq 0 ]; then + dirname=$(dirname $file) + git taskrepo update $dirname + fi +done +""" + if not os.path.exists("%s/hooks/post-merge" % self.repo.git_dir): + with open("%s/hooks/post-merge" % self.repo.git_dir,'w') as f: + f.write(post_merge_hook) + os.chmod("%s/hooks/post-merge" % self.repo.git_dir, 0755) + print(" - Installed post-merge hook") + # walk the git repo from working_tree_dir and import all tasks # unless option --no-import was passed in. if kwargs.get("no_import") is False: @@ -141,9 +156,9 @@ done try: update_taskrepo(self.repo, self.taskrepo, dirpath) except ParserError, e: - print >> sys.stderr, (" - %s FAIL (%s)." % (dirpath, e)) + print >> sys.stderr, (" - %s FAIL (%s)." % (dirpath, e)) except TRX_TestInfo: pass else: - print(" - %s Imported." % dirpath) + print(" - %s Imported." % dirpath) print("Done!") -- cgit