From 77b438c4e9c634ffcc55f6f1449b833caa4392aa Mon Sep 17 00:00:00 2001 From: mmirate Date: Tue, 29 May 2012 09:15:13 -0300 Subject: [PATCH 01/13] Preliminary support for pushing from ghar. --- bin/ghar | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/bin/ghar b/bin/ghar index 59393af..f7989c2 100755 --- a/bin/ghar +++ b/bin/ghar @@ -156,6 +156,10 @@ class Repo: def pull(self): cmd = 'git pull' return self._git_cmd(cmd) + + def push(self) + cmd = 'git push' + return self._git_cmd(cmd) def clean(self): cmd = 'git status -s 2> /dev/null' From 8a1bc7f77f8c1bb1c9a5bc747b9c52b265f42a96 Mon Sep 17 00:00:00 2001 From: mmirate Date: Tue, 29 May 2012 09:18:53 -0300 Subject: [PATCH 02/13] Fix silly syntactical mistake. --- bin/ghar | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/ghar b/bin/ghar index f7989c2..df99366 100755 --- a/bin/ghar +++ b/bin/ghar @@ -157,7 +157,7 @@ class Repo: cmd = 'git pull' return self._git_cmd(cmd) - def push(self) + def push(self): cmd = 'git push' return self._git_cmd(cmd) From ab922f7403b115889682afe77fa33c13700bfb58 Mon Sep 17 00:00:00 2001 From: mmirate Date: Tue, 29 May 2012 09:23:10 -0300 Subject: [PATCH 03/13] Put push function into argument parser. --- bin/ghar | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/bin/ghar b/bin/ghar index df99366..474a99c 100755 --- a/bin/ghar +++ b/bin/ghar @@ -223,6 +223,13 @@ def pull(args): _git_subcommand(args, "pull") argp_pull.set_defaults(func=pull) +argp_push = argp_sub.add_parser('push', help='push all or a few repos') +argp_push.add_argument('repos', metavar='repos', nargs='*', + help='repos to push [defaults to pushing all repos]') +def push(args): + _git_subcommand(args, "push") +argp_push.set_defaults(func=push) + argp_status = argp_sub.add_parser('status', help='clean/dirty status of repos') argp_status.add_argument('repos', metavar='repos', nargs='*', help='repos to check [defaults to checking all repos]') From 6c7b981d32244a4b417114f677aa84a9ef9ea64b Mon Sep 17 00:00:00 2001 From: mmirate Date: Tue, 29 May 2012 09:33:37 -0300 Subject: [PATCH 04/13] Add "commit" and "commit-and-push" functions and argument parser entries. --- bin/ghar | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/bin/ghar b/bin/ghar index 474a99c..2bb2a6f 100755 --- a/bin/ghar +++ b/bin/ghar @@ -161,6 +161,17 @@ class Repo: cmd = 'git push' return self._git_cmd(cmd) + def commit(self): + cmd = 'git add . && git commit -m "Changes up to $(date -Imin)."' + return self._git_cmd(cmd) + + def cap(self): + failure1, ret1 = self.commit() + if failure1: + return (failure1, ret1) + else: + return self.push() + def clean(self): cmd = 'git status -s 2> /dev/null' ok, ret = self._git_cmd(cmd) @@ -230,6 +241,20 @@ def push(args): _git_subcommand(args, "push") argp_push.set_defaults(func=push) +argp_commit = argp_sub.add_parser('commit', help='commit all or a few repos') +argp_commit.add_argument('repos', metavar='repos', nargs='*', + help='repos to commit [defaults to committing all repos]') +def commit(args): + _git_subcommand(args, "commit") +argp_commit.set_defaults(func=commit) + +argp_cap = argp_sub.add_parser('cap', help='commit and push all or a few repos') +argp_cap.add_argument('repos', metavar='repos', nargs='*', + help='repos to cap [defaults to committing and pushing all repos]') +def cap(args): + _git_subcommand(args, "cap") +argp_cap.set_defaults(func=cap) + argp_status = argp_sub.add_parser('status', help='clean/dirty status of repos') argp_status.add_argument('repos', metavar='repos', nargs='*', help='repos to check [defaults to checking all repos]') From 9f878e68bc72b9e636ad4124512c2558721c222c Mon Sep 17 00:00:00 2001 From: Milo Mirate Date: Wed, 30 May 2012 16:13:04 -0400 Subject: [PATCH 05/13] Fix a problem with the invocation of git-add. The -A argument should be provided but previously was not. --- bin/ghar | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/ghar b/bin/ghar index 2bb2a6f..8f2ff0f 100755 --- a/bin/ghar +++ b/bin/ghar @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python2 # # Copyright (C) 2010 Brandon Philips # @@ -162,7 +162,7 @@ class Repo: return self._git_cmd(cmd) def commit(self): - cmd = 'git add . && git commit -m "Changes up to $(date -Imin)."' + cmd = 'git add -A . && git commit -m "Changes up to $(date -Imin)."' return self._git_cmd(cmd) def cap(self): From 704527f0f607819e8d3b4dd183113eeae363d432 Mon Sep 17 00:00:00 2001 From: mmirate Date: Sun, 10 Jun 2012 09:05:40 -0300 Subject: [PATCH 06/13] Fix shebang of bin/ghar --- bin/ghar | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/ghar b/bin/ghar index 8f2ff0f..d8e854a 100755 --- a/bin/ghar +++ b/bin/ghar @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python # # Copyright (C) 2010 Brandon Philips # From 2ddedc7666d8577557287e17b5706b621257a6e7 Mon Sep 17 00:00:00 2001 From: mmirate Date: Fri, 22 Jun 2012 18:58:27 -0300 Subject: [PATCH 07/13] Add commit message customization. --- bin/ghar | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/bin/ghar b/bin/ghar index d8e854a..e23b9cf 100755 --- a/bin/ghar +++ b/bin/ghar @@ -153,24 +153,32 @@ class Repo: return (True, ret) return (False, ret) - def pull(self): - cmd = 'git pull' + def pull(self, args): + cmd = 'git pulsl' return self._git_cmd(cmd) - def push(self): + def push(self, args): cmd = 'git push' return self._git_cmd(cmd) - def commit(self): - cmd = 'git add -A . && git commit -m "Changes up to $(date -Imin)."' + def commit(self, args): + message = '' + cmd = 'git add -A . && git commit %s' + if args.auto: + message = '"Changes up to $(date -Imin)."' + elif args.message: + message = "'%s'" % args.message + else: + message = False + cmd = cmd % (('-m ' if message else '') + message) return self._git_cmd(cmd) - def cap(self): - failure1, ret1 = self.commit() + def cap(self, args): + failure1, ret1 = self.commit(args) if failure1: return (failure1, ret1) else: - return self.push() + return self.push(args) def clean(self): cmd = 'git status -s 2> /dev/null' @@ -221,7 +229,7 @@ def _git_subcommand(args, action): for r in pull_repos: try: - status, string = getattr(r, action)() + status, string = getattr(r, action)(args) print "%s: %s" % (str(r), string) except NoGitException as e: print "%s is not a git repo" % str(r) @@ -244,6 +252,10 @@ argp_push.set_defaults(func=push) argp_commit = argp_sub.add_parser('commit', help='commit all or a few repos') argp_commit.add_argument('repos', metavar='repos', nargs='*', help='repos to commit [defaults to committing all repos]') +argp_commit.add_argument('-m','--message', metavar='message', nargs=1, + help='commit message [defaults to opening an editor]') +argp_commit.add_argument('-a','--auto', + help='automatically generate commit message from current date+time [defaults to False]') def commit(args): _git_subcommand(args, "commit") argp_commit.set_defaults(func=commit) From a97e643457f5bf6aa50a5ebf07f1d3463e2e3681 Mon Sep 17 00:00:00 2001 From: Jacob Kaplan-Moss Date: Mon, 20 May 2013 09:54:41 -0500 Subject: [PATCH 08/13] Have a better error message when dealing with non-ghar symlinks. --- bin/ghar | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/ghar b/bin/ghar index d08b8ff..e78a4df 100755 --- a/bin/ghar +++ b/bin/ghar @@ -204,7 +204,7 @@ class Repo: new_path = os.path.join(path, fname) dir_links += self.list_directory_links(new_path) elif link_status.startswith("link to "): - print "We can't yet handle non-ghar symlinks." + print fname,"- we can't yet non-ghar symlinks." else: dir_links.append(Link(os.path.join(path, fname), base=self.path)) return dir_links From 8c3dcb1c4635cb18273c53088cb154967101da4c Mon Sep 17 00:00:00 2001 From: Jacob Kaplan-Moss Date: Mon, 20 May 2013 10:46:37 -0500 Subject: [PATCH 09/13] Fixed clean and commit commands. --- bin/ghar | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/bin/ghar b/bin/ghar index e78a4df..a8647f1 100755 --- a/bin/ghar +++ b/bin/ghar @@ -25,6 +25,8 @@ __version__= '1' import sys import os import re +import pipes +import datetime from urlparse import urlparse import subprocess from stat import * @@ -158,23 +160,23 @@ class Repo: def pull(self, args): cmd = 'git pulsl' return self._git_cmd(cmd) - + def push(self, args): cmd = 'git push' return self._git_cmd(cmd) def commit(self, args): + if self.is_clean(): + return (True, "nothing to commit (working directory clean)") message = '' - cmd = 'git add -A . && git commit %s' if args.auto: - message = '"Changes up to $(date -Imin)."' + now = datetime.datetime.now() + message = "Changes up to %s" % now.strftime("%Y-$m-%d %H:%I") elif args.message: - message = "'%s'" % args.message - else: - message = False - cmd = cmd % (('-m ' if message else '') + message) + message = args.message + cmd = 'git add -A . && git commit -m ' + pipes.quote(message) return self._git_cmd(cmd) - + def cap(self, args): failure1, ret1 = self.commit(args) if failure1: @@ -182,12 +184,15 @@ class Repo: else: return self.push(args) - def clean(self): + def clean(self, args): cmd = 'git status -s 2> /dev/null' ok, ret = self._git_cmd(cmd) - if len(ret) > 0: return (False, "dirty") + if len(ret) > 0: return (False, "dirty", ret) return (True, "clean") + def is_clean(self): + return self.clean(None)[0] + # This function processes all the links in a directory from the repository, # depending on whether the corresponding directory already exists in $HOME. # If the directory _doesn't_ already exist, simply symlink it. @@ -254,8 +259,12 @@ def _git_subcommand(args, action): for r in pull_repos: try: - status, string = getattr(r, action)(args) + resp = getattr(r, action)(args) + status, string = resp[:2] + extra = resp[2:] print "%s: %s" % (str(r), string) + if extra: + print extra[0] except NoGitException as e: print "%s is not a git repo" % str(r) return 0 @@ -277,11 +286,14 @@ argp_push.set_defaults(func=push) argp_commit = argp_sub.add_parser('commit', help='commit all or a few repos') argp_commit.add_argument('repos', metavar='repos', nargs='*', help='repos to commit [defaults to committing all repos]') -argp_commit.add_argument('-m','--message', metavar='message', nargs=1, +argp_commit.add_argument('-m','--message', metavar='message', help='commit message [defaults to opening an editor]') argp_commit.add_argument('-a','--auto', help='automatically generate commit message from current date+time [defaults to False]') def commit(args): + if not args.message and not args.auto: + print "error: must give a commit message; use -m/--message or -a/--auto" + return _git_subcommand(args, "commit") argp_commit.set_defaults(func=commit) From 944fd13069b1f11e2c0ac5918ea7369040754842 Mon Sep 17 00:00:00 2001 From: Jacob Kaplan-Moss Date: Mon, 20 May 2013 10:47:11 -0500 Subject: [PATCH 10/13] Fixed commit --auto flag. --- bin/ghar | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/ghar b/bin/ghar index a8647f1..c2b220b 100755 --- a/bin/ghar +++ b/bin/ghar @@ -288,7 +288,7 @@ argp_commit.add_argument('repos', metavar='repos', nargs='*', help='repos to commit [defaults to committing all repos]') argp_commit.add_argument('-m','--message', metavar='message', help='commit message [defaults to opening an editor]') -argp_commit.add_argument('-a','--auto', +argp_commit.add_argument('-a','--auto', action="store_true", default=False, help='automatically generate commit message from current date+time [defaults to False]') def commit(args): if not args.message and not args.auto: From 9952662502075e916b2f5c6a408204e875cc43f7 Mon Sep 17 00:00:00 2001 From: Jacob Kaplan-Moss Date: Mon, 20 May 2013 10:50:12 -0500 Subject: [PATCH 11/13] Added -m/-a flags to cap command. --- bin/ghar | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/bin/ghar b/bin/ghar index c2b220b..6ad84ba 100755 --- a/bin/ghar +++ b/bin/ghar @@ -300,7 +300,14 @@ argp_commit.set_defaults(func=commit) argp_cap = argp_sub.add_parser('cap', help='commit and push all or a few repos') argp_cap.add_argument('repos', metavar='repos', nargs='*', help='repos to cap [defaults to committing and pushing all repos]') +argp_cap.add_argument('-m','--message', metavar='message', + help='commit message [defaults to opening an editor]') +argp_cap.add_argument('-a','--auto', action="store_true", default=False, + help='automatically generate commit message from current date+time [defaults to False]') def cap(args): + if not args.message and not args.auto: + print "error: must give a commit message; use -m/--message or -a/--auto" + return _git_subcommand(args, "cap") argp_cap.set_defaults(func=cap) From 627e015d219ef17aa6b47c94d02292794d43d5ed Mon Sep 17 00:00:00 2001 From: Jacob Kaplan-Moss Date: Mon, 20 May 2013 11:01:52 -0500 Subject: [PATCH 12/13] Updated bash completion. --- ghar-bash-completion.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ghar-bash-completion.sh b/ghar-bash-completion.sh index cfdd1d2..458b6e5 100755 --- a/ghar-bash-completion.sh +++ b/ghar-bash-completion.sh @@ -5,12 +5,12 @@ # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2 as # published by the Free Software Foundation. -# +# # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. -# +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA @@ -25,14 +25,14 @@ function _ghar { top="${COMP_WORDS[1]}" if [ $COMP_CWORD -eq 1 ]; then - opts="status pull list add install uninstall" + opts="status pull list add install uninstall commit push cap" COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) return 0 fi case "$top" in - status|pull|install|uninstall) # one or more repos + status|pull|install|uninstall|commit|push|cap) # one or more repos # only present --status right after top level install command if [ "$top" = "install" -a $COMP_CWORD -eq 2 ]; then From 140f491d68a877a904fd247bcff9b0c4d94f565b Mon Sep 17 00:00:00 2001 From: Jacob Kaplan-Moss Date: Mon, 20 May 2013 13:57:35 -0500 Subject: [PATCH 13/13] Fixed a typo in pull, not sure how that got there. --- bin/ghar | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/ghar b/bin/ghar index 6ad84ba..4122624 100755 --- a/bin/ghar +++ b/bin/ghar @@ -158,7 +158,7 @@ class Repo: return (False, ret) def pull(self, args): - cmd = 'git pulsl' + cmd = 'git pull' return self._git_cmd(cmd) def push(self, args):