From 45903206faa5fcb054522be027f36b937841fb2d Mon Sep 17 00:00:00 2001 From: Santiago Perez De Rosso Date: Mon, 20 Jan 2014 18:46:36 -0500 Subject: [PATCH 01/12] Improvements in the remote module (renamed method list_all to show_all) --- gitpylib/remote.py | 50 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 15 deletions(-) diff --git a/gitpylib/remote.py b/gitpylib/remote.py index 5c64da4..2c0f3b2 100644 --- a/gitpylib/remote.py +++ b/gitpylib/remote.py @@ -7,6 +7,7 @@ import common + SUCCESS = 1 REMOTE_NOT_FOUND = 2 REMOTE_UNREACHABLE = 3 @@ -14,14 +15,19 @@ def add(remote_name, remote_url): - """Adds the given remote.""" - common.safe_git_call('remote add %s %s' % (remote_name, remote_url)) + """Adds the given remote. + Args: + remote_name: the name of the remote to add. + remote_url: the url of the remote to add. -def list(): - """Returns a list with all the remotes.""" - out, unused_err = common.safe_git_call('remote') - return out.splitlines() + Returns: + SUCCESS or REMOTE_UNREACHABLE. + """ + if _show(remote_url)[0] == REMOTE_UNREACHABLE: + return REMOTE_UNREACHABLE + common.safe_git_call('remote add %s %s' % (remote_name, remote_url)) + return SUCCESS def show(remote_name): @@ -31,17 +37,18 @@ def show(remote_name): remote_name: the name of the remote to get info from. Returns: - None if remote doesn't exist or the output of the cmd if otherwise. + a tuple (status, out) where status is one of SUCCESS, REMOTE_NOT_FOUND, or + REMOTE_UNREACHABLE and out is the output of the show command on success. """ - ok, out, err = common.git_call('remote show %s' % remote_name) - if not ok: - if 'fatal: Could not read from remote repository' in err: - return (REMOTE_UNREACHABLE, None) - else: - raise Exception('Unexpected output %s, err %s' % (out, err)) - if not out: + if remote_name not in show_all(): return (REMOTE_NOT_FOUND, None) - return (SUCCESS, out) + return _show(remote_name) + + +def show_all(): + """Get information of all the remotes.""" + out, unused_err = common.safe_git_call('remote') + return out.splitlines() def rm(remote_name): @@ -54,3 +61,16 @@ def head_exist(remote_name, head): if not ok: return (False, REMOTE_UNREACHABLE) return (len(out) > 0, REMOTE_BRANCH_NOT_FOUND) + + +# Private functions. + + +def _show(remote): + ok, out, err = common.git_call('remote show %s' % remote) + if not ok: + if 'fatal: Could not read from remote repository' in err: + return (REMOTE_UNREACHABLE, None) + else: + raise Exception('Unexpected output %s, err %s' % (out, err)) + return (SUCCESS, out) From 42356048a167ef1efe8ec39c4583c056e71c93d2 Mon Sep 17 00:00:00 2001 From: Santiago Perez De Rosso Date: Tue, 21 Jan 2014 16:44:56 -0500 Subject: [PATCH 02/12] Added function to get the name of the branches in a remote --- gitpylib/remote.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/gitpylib/remote.py b/gitpylib/remote.py index 2c0f3b2..a1dd5f9 100644 --- a/gitpylib/remote.py +++ b/gitpylib/remote.py @@ -63,6 +63,18 @@ def head_exist(remote_name, head): return (len(out) > 0, REMOTE_BRANCH_NOT_FOUND) +def branches(remote_name): + """Gets the name of the branches in the given remote.""" + out, err = common.safe_git_call('branch -r') + remote_name_len = len(remote_name) + for line in out.splitlines(): + if '->' in line: + continue + line = line.strip() + if line.startswith(remote_name): + yield line[remote_name_len+1:] + + # Private functions. From 6848550929ad1e36c5ef61a8cdf02bcf4e352b44 Mon Sep 17 00:00:00 2001 From: Santiago Perez De Rosso Date: Thu, 23 Jan 2014 15:22:02 -0500 Subject: [PATCH 03/12] check if clone succeeds or not --- gitpylib/repo.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gitpylib/repo.py b/gitpylib/repo.py index f72ae97..bd1a8a0 100644 --- a/gitpylib/repo.py +++ b/gitpylib/repo.py @@ -7,7 +7,8 @@ def clone(repo): - common.safe_git_call('clone %s .' % repo) + """Returns True if the clone succeeded, False if otherwise.""" + return common.git_call('clone %s .' % repo)[0] def init(): From 6114a1f4556812695cfb18fa9c9b76841396d877 Mon Sep 17 00:00:00 2001 From: Santiago Perez De Rosso Date: Sat, 25 Jan 2014 17:39:23 -0500 Subject: [PATCH 04/12] python 3.3 support --- gitpylib/branch.py | 2 +- gitpylib/common.py | 5 +++++ gitpylib/config.py | 2 +- gitpylib/file.py | 2 +- gitpylib/hook.py | 2 +- gitpylib/remote.py | 2 +- gitpylib/repo.py | 2 +- gitpylib/stash.py | 2 +- gitpylib/status.py | 11 +++++++++-- gitpylib/sync.py | 2 +- 10 files changed, 22 insertions(+), 10 deletions(-) diff --git a/gitpylib/branch.py b/gitpylib/branch.py index 710f3d2..e4de08b 100644 --- a/gitpylib/branch.py +++ b/gitpylib/branch.py @@ -7,7 +7,7 @@ import re -import common +from . import common SUCCESS = 1 diff --git a/gitpylib/common.py b/gitpylib/common.py index a525518..1aec655 100644 --- a/gitpylib/common.py +++ b/gitpylib/common.py @@ -7,6 +7,7 @@ import os import subprocess +import sys # Detect if FS is case-sensitive. @@ -29,6 +30,10 @@ def git_call(cmd): 'git %s' % cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) out, err = p.communicate() + # Python 2/3 compatibility. + if sys.version > '3': + out = out.decode('utf-8') + err = err.decode('utf-8') return p.returncode == 0, out, err diff --git a/gitpylib/config.py b/gitpylib/config.py index 997e3db..9abe161 100644 --- a/gitpylib/config.py +++ b/gitpylib/config.py @@ -5,7 +5,7 @@ """Module for dealing with Git config.""" -import common +from . import common def get(var): diff --git a/gitpylib/file.py b/gitpylib/file.py index f9e4a61..316f7e9 100644 --- a/gitpylib/file.py +++ b/gitpylib/file.py @@ -9,7 +9,7 @@ import os.path import re -import common +from . import common SUCCESS = 1 diff --git a/gitpylib/hook.py b/gitpylib/hook.py index f163d70..4262cb5 100644 --- a/gitpylib/hook.py +++ b/gitpylib/hook.py @@ -9,7 +9,7 @@ import os import subprocess -import common +from . import common def pre_commit(): diff --git a/gitpylib/remote.py b/gitpylib/remote.py index a1dd5f9..9103cac 100644 --- a/gitpylib/remote.py +++ b/gitpylib/remote.py @@ -5,7 +5,7 @@ """Module for dealing with Git remotes.""" -import common +from . import common SUCCESS = 1 diff --git a/gitpylib/repo.py b/gitpylib/repo.py index bd1a8a0..2e5bedd 100644 --- a/gitpylib/repo.py +++ b/gitpylib/repo.py @@ -3,7 +3,7 @@ # Licensed under GNU GPL, version 2. -import common +from . import common def clone(repo): diff --git a/gitpylib/stash.py b/gitpylib/stash.py index d748fe1..84f04e7 100644 --- a/gitpylib/stash.py +++ b/gitpylib/stash.py @@ -5,7 +5,7 @@ """Module for dealing with Git stashes.""" -import common +from . import common import re diff --git a/gitpylib/status.py b/gitpylib/status.py index 07f7dca..45d1b05 100644 --- a/gitpylib/status.py +++ b/gitpylib/status.py @@ -8,7 +8,7 @@ import os import re -import common +from . import common SUCCESS = 1 @@ -79,7 +79,14 @@ def of_repo(include_tracked_unmodified_fps=True): for fp_under_cwd in all_fps_under_cwd: if fp_under_cwd not in status_codes: status_codes[fp_under_cwd] = None - for s_fp, s in status_codes.iteritems(): + # Python 2/3 compatibility. + status_codes_items = [] + try: + status_codes_items = status_codes.iteritems() + except AttributeError: + status_codes_items = status_codes.items() + + for s_fp, s in status_codes_items: status = _status_from_output(s, s_fp in au_fps, s_fp) yield (status, s_fp) diff --git a/gitpylib/sync.py b/gitpylib/sync.py index 9ca6742..b55b17b 100644 --- a/gitpylib/sync.py +++ b/gitpylib/sync.py @@ -8,7 +8,7 @@ import os import re -import common +from . import common SUCCESS = 1 From e6cc5856a28d83e621059c947ff197c90defb2aa Mon Sep 17 00:00:00 2001 From: Santiago Perez De Rosso Date: Sat, 25 Jan 2014 20:01:58 -0500 Subject: [PATCH 05/12] python 2.6 support --- gitpylib/branch.py | 2 +- gitpylib/hook.py | 2 +- gitpylib/status.py | 12 ++++++------ gitpylib/sync.py | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/gitpylib/branch.py b/gitpylib/branch.py index e4de08b..39e798a 100644 --- a/gitpylib/branch.py +++ b/gitpylib/branch.py @@ -44,7 +44,7 @@ def create(name, sp='HEAD'): Returns: SUCCESS, INVALID_NAME or BRANCH_ALREADY_EXISTS. """ - ok, _, err = common.git_call('branch {} {}'.format(name, sp)) + ok, _, err = common.git_call('branch {0} {1}'.format(name, sp)) if not ok: if 'is not a valid branch name' in err: return INVALID_NAME diff --git a/gitpylib/hook.py b/gitpylib/hook.py index 4262cb5..de8495b 100644 --- a/gitpylib/hook.py +++ b/gitpylib/hook.py @@ -19,7 +19,7 @@ def pre_commit(): def _hook_call(hook_name): HookCall = collections.namedtuple('hook_call', ['ok', 'out', 'err']) - hook_path = '{}/hooks/{}'.format(common.git_dir(), hook_name) + hook_path = '{0}/hooks/{1}'.format(common.git_dir(), hook_name) if not os.path.exists(hook_path): return HookCall(True, '', '') p = subprocess.Popen( diff --git a/gitpylib/status.py b/gitpylib/status.py index 45d1b05..d1da33c 100644 --- a/gitpylib/status.py +++ b/gitpylib/status.py @@ -100,8 +100,8 @@ def au_files(relative_to_cwd=False): to False.) """ out, unused_err = common.safe_git_call( - 'ls-files -v {}'.format( - '--full-name "{}"'.format( + 'ls-files -v {0}'.format( + '--full-name "{0}"'.format( common.repo_dir()) if not relative_to_cwd else '')) ret = [] # There could be dups in the output from ls-files if, for example, there are @@ -122,12 +122,12 @@ def _is_au_file(fp): fp: the filepath to check (fp must be a file not a dir). """ out, unused_err = common.safe_git_call( - 'ls-files -v --full-name "{}"'.format(fp)) + 'ls-files -v --full-name "{0}"'.format(fp)) ret = False if out: f_out = common.remove_dups(out.splitlines(), lambda x: x[2:]) if len(f_out) != 1: - raise Exception('Unexpected output of ls-files: {}'.format(out)) + raise Exception('Unexpected output of ls-files: {0}'.format(out)) ret = f_out[0][0] == 'h' return ret @@ -153,7 +153,7 @@ def sanitize_fp(fp): return os.path.relpath(os.path.join(repo_dir, fp), cwd) out_status, unused_err = common.safe_git_call( - 'status --porcelain -u --ignored "{}"'.format(pathspec)) + 'status --porcelain -u --ignored "{0}"'.format(pathspec)) ret = {} for f_out_status in out_status.splitlines(): # Output is in the form . @@ -188,4 +188,4 @@ def _status_from_output(s, is_au, fp): return ADDED_MODIFIED elif s == 'AA' or s == 'M ' or s == 'DD' or 'U' in s: return IN_CONFLICT - raise Exception('Failed to get status of file {}, s is "{}"'.format(fp, s)) + raise Exception('Failed to get status of file {0}, s is "{1}"'.format(fp, s)) diff --git a/gitpylib/sync.py b/gitpylib/sync.py index b55b17b..4dcb180 100644 --- a/gitpylib/sync.py +++ b/gitpylib/sync.py @@ -34,7 +34,7 @@ def commit(files, msg, skip_checks=False, stage_files=False): the output of the commit command. """ out, unused_err = common.safe_git_call( - 'commit {}{}-m"{}" "{}"'.format( + 'commit {0}{1}-m"{2}" "{3}"'.format( '--no-verify ' if skip_checks else '', '-i ' if stage_files else '', msg, '" "'.join(files))) From ae897f9d70e0e71e452905b143052bab8e264aa1 Mon Sep 17 00:00:00 2001 From: Santiago Perez De Rosso Date: Sun, 26 Jan 2014 15:30:43 -0500 Subject: [PATCH 06/12] removed unnecessary strip --- gitpylib/branch.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/gitpylib/branch.py b/gitpylib/branch.py index 39e798a..0195c70 100644 --- a/gitpylib/branch.py +++ b/gitpylib/branch.py @@ -158,5 +158,4 @@ def _parse_output(out): tracks = track_info.split(':')[0] else: tracks = track_info - - return (result.group(2).strip(), result.group(1) == '*', tracks) + return (result.group(2), result.group(1) == '*', tracks) From 0f14d50ac7c4c76f50253c8c98bb231dd15864ee Mon Sep 17 00:00:00 2001 From: Santiago Perez De Rosso Date: Sun, 26 Jan 2014 23:34:05 -0500 Subject: [PATCH 07/12] show all verbose --- gitpylib/remote.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/gitpylib/remote.py b/gitpylib/remote.py index 9103cac..7e669b7 100644 --- a/gitpylib/remote.py +++ b/gitpylib/remote.py @@ -5,6 +5,9 @@ """Module for dealing with Git remotes.""" +import collections +import re + from . import common @@ -51,6 +54,30 @@ def show_all(): return out.splitlines() +RemoteInfo = collections.namedtuple( + 'RemoteInfo', ['name', 'fetch', 'push']) + + +def show_all_v(): + """Get information of all the remotes (verbose).""" + out, unused_err = common.safe_git_call('remote -v') + # format is remote_name url (fetch/push) + pattern = '(\w+)\s+(.+)\s+\((\w+)\)' + ret = {} + for r in out.splitlines(): + result = re.match(pattern, r) + if not result: + raise Exception('Unexpected output "%s"' % r) + remote_name = result.group(1) + url = result.group(2) + url_type = result.group(3) + if remote_name not in ret: + ret[remote_name] = {} + ret[remote_name][url_type] = url + return [ + RemoteInfo(rn, ret[rn]['fetch'], ret[rn]['push']) for rn in ret.keys()] + + def rm(remote_name): common.safe_git_call('remote rm %s' % remote_name) From 2e1865edf8fa3ad8ca487d456dd000a2584902e2 Mon Sep 17 00:00:00 2001 From: Santiago Perez De Rosso Date: Mon, 27 Jan 2014 12:15:44 -0500 Subject: [PATCH 08/12] fixed bug in _parse_rebase_output (when pull --rebase is done the output msg changes a bit) --- gitpylib/sync.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/gitpylib/sync.py b/gitpylib/sync.py index 4dcb180..36e6b7c 100644 --- a/gitpylib/sync.py +++ b/gitpylib/sync.py @@ -84,9 +84,7 @@ def rebase(new_base): def _parse_rebase_output(ok, out, err): # print 'out is <%s>, err is <%s>' % (out, err) if not ok: - if err == ( - 'Cannot rebase: You have unstaged changes.\nPlease commit or stash ' - 'them.\n'): + if 'You have unstaged changes.\nPlease commit or stash them.\n' in err: # TODO(sperezde): add the files whose changes would be lost. return (LOCAL_CHANGES_WOULD_BE_LOST, None) elif ('The following untracked working tree files would be overwritten' From ec57179bc33301f2204257f18658c287e60d87fc Mon Sep 17 00:00:00 2001 From: Santiago Perez De Rosso Date: Wed, 29 Jan 2014 12:21:10 -0500 Subject: [PATCH 09/12] some cleanups --- .pylint.rc | 14 ++++++++++++++ gitpylib/branch.py | 12 ++++++------ gitpylib/common.py | 4 ++-- gitpylib/config.py | 2 +- gitpylib/file.py | 8 ++++---- gitpylib/remote.py | 10 +++++----- gitpylib/stash.py | 4 ++-- gitpylib/status.py | 9 ++++----- gitpylib/sync.py | 10 +++++----- 9 files changed, 43 insertions(+), 30 deletions(-) create mode 100644 .pylint.rc diff --git a/.pylint.rc b/.pylint.rc new file mode 100644 index 0000000..d9774a4 --- /dev/null +++ b/.pylint.rc @@ -0,0 +1,14 @@ +[FORMAT] + +indent-string=' ' + + +[MESSAGES CONTROL] + +# W0511 = fixme +# C0111 = missing docstring +# C0103 = invalid name +# I0011 = locally disabling +# W0142 = star-args + +disable=W0511,C0111,C0103,I0011,W0142 diff --git a/gitpylib/branch.py b/gitpylib/branch.py index 0195c70..43fe56d 100644 --- a/gitpylib/branch.py +++ b/gitpylib/branch.py @@ -72,7 +72,7 @@ def force_delete(name): def current(): """Get the name of the current branch.""" - for name, is_current, unused_tracks in status_all(): + for name, is_current, _ in status_all(): if is_current: return name @@ -89,11 +89,11 @@ def status(name): tracks (in the format 'remote_name/remote_branch') or None if it is a local branch. """ - out, unused_err = common.safe_git_call('branch --list -vv %s' % name) + out, _ = common.safe_git_call('branch --list -vv %s' % name) if not out: return (False, False, None) - unused_name, is_current, tracks = _parse_output(out) + _, is_current, tracks = _parse_output(out) return (True, is_current, tracks) @@ -106,7 +106,7 @@ def status_all(): the format 'remote_name/remote_branch') or None if it is a local branch. name could be equal to '(no branch)' if the user is in no branch. """ - out, unused_err = common.safe_git_call('branch --list -vv') + out, _ = common.safe_git_call('branch --list -vv') for b in out.splitlines(): yield _parse_output(b) @@ -118,7 +118,7 @@ def set_upstream(branch, upstream_branch): branch: the branch to set an upstream branch. upstream_branch: the upstream branch. """ - ok, out, err = common.git_call( + ok, _, err = common.git_call( 'branch --set-upstream %s %s' % (branch, upstream_branch)) if not ok: @@ -145,7 +145,7 @@ def _parse_output(out): if out.startswith('* (no branch)'): return ('(no branch)', True, None) - pattern = '([\*| ]) ([^\s]+)[ ]+\w+ (.+)' + pattern = r'([\*| ]) ([^\s]+)[ ]+\w+ (.+)' result = re.match(pattern, out) if not result: raise Exception('Unexpected output %s' % out) diff --git a/gitpylib/common.py b/gitpylib/common.py index 1aec655..b48d14e 100644 --- a/gitpylib/common.py +++ b/gitpylib/common.py @@ -14,8 +14,8 @@ import tempfile tmp_handle, tmp_path = tempfile.mkstemp() -with tempfile.NamedTemporaryFile() as f: - FS_CASE_SENSITIVE = not os.path.exists(f.name.upper()) +with tempfile.NamedTemporaryFile() as f_tmp: + FS_CASE_SENSITIVE = not os.path.exists(f_tmp.name.upper()) def safe_git_call(cmd): diff --git a/gitpylib/config.py b/gitpylib/config.py index 9abe161..304e555 100644 --- a/gitpylib/config.py +++ b/gitpylib/config.py @@ -9,5 +9,5 @@ def get(var): - ok, out, unused_err = common.git_call('config %s' % var) + ok, out, _ = common.git_call('config %s' % var) return out.strip() if ok else None diff --git a/gitpylib/file.py b/gitpylib/file.py index 316f7e9..e23c56f 100644 --- a/gitpylib/file.py +++ b/gitpylib/file.py @@ -76,7 +76,7 @@ def show(fp, cp): """ fp = common.real_case(fp) - ok, out, unused_err = common.git_call('show %s:"%s"' % (cp, fp)) + ok, out, _ = common.git_call('show %s:"%s"' % (cp, fp)) if not ok: return (FILE_NOT_FOUND_AT_CP, None) @@ -125,7 +125,7 @@ def diff(fp): """ fp = common.real_case(fp) - out, unused_err = common.safe_git_call('diff -- "%s"' % fp) + out, _ = common.safe_git_call('diff -- "%s"' % fp) return _process_diff_output(_strip_diff_header(out.splitlines())) @@ -140,7 +140,7 @@ def staged_diff(fp): """ fp = common.real_case(fp) - out, unused_err = common.safe_git_call('diff --cached -- "%s"' % fp) + out, _ = common.safe_git_call('diff --cached -- "%s"' % fp) return _process_diff_output(_strip_diff_header(out.splitlines())) @@ -186,7 +186,7 @@ def _process_diff_output(diff_out): for line in diff_out: # @@ -(start of old),(length of old) +(start of new),(length of new) @@ - new_hunk_regex = "^@@ -([0-9]+)[,]?([0-9]*) \+([0-9]+)[,]?([0-9]*) @@" + new_hunk_regex = r'^@@ -([0-9]+)[,]?([0-9]*) \+([0-9]+)[,]?([0-9]*) @@' new_hunk_info = re.search(new_hunk_regex, line) if new_hunk_info: get_info_or_zero = lambda g: 0 if g == '' else int(g) diff --git a/gitpylib/remote.py b/gitpylib/remote.py index 7e669b7..55f2a25 100644 --- a/gitpylib/remote.py +++ b/gitpylib/remote.py @@ -50,7 +50,7 @@ def show(remote_name): def show_all(): """Get information of all the remotes.""" - out, unused_err = common.safe_git_call('remote') + out, _ = common.safe_git_call('remote') return out.splitlines() @@ -60,9 +60,9 @@ def show_all(): def show_all_v(): """Get information of all the remotes (verbose).""" - out, unused_err = common.safe_git_call('remote -v') + out, _ = common.safe_git_call('remote -v') # format is remote_name url (fetch/push) - pattern = '(\w+)\s+(.+)\s+\((\w+)\)' + pattern = r'(\w+)\s+(.+)\s+\((\w+)\)' ret = {} for r in out.splitlines(): result = re.match(pattern, r) @@ -83,7 +83,7 @@ def rm(remote_name): def head_exist(remote_name, head): - ok, out, unused_err = common.git_call( + ok, out, _ = common.git_call( 'ls-remote --heads %s %s' % (remote_name, head)) if not ok: return (False, REMOTE_UNREACHABLE) @@ -92,7 +92,7 @@ def head_exist(remote_name, head): def branches(remote_name): """Gets the name of the branches in the given remote.""" - out, err = common.safe_git_call('branch -r') + out, _ = common.safe_git_call('branch -r') remote_name_len = len(remote_name) for line in out.splitlines(): if '->' in line: diff --git a/gitpylib/stash.py b/gitpylib/stash.py index 84f04e7..d40c413 100644 --- a/gitpylib/stash.py +++ b/gitpylib/stash.py @@ -57,12 +57,12 @@ def _stash_id(msg): the stash id of the stash with the given msg or None if no matching stash is found. """ - out, unused_err = common.safe_git_call('stash list --grep=": %s"' % msg) + out, _ = common.safe_git_call('stash list --grep=": %s"' % msg) if not out: return None - pattern = '(stash@\{.+\}): ' + pattern = r'(stash@\{.+\}): ' result = re.match(pattern, out) if not result: raise Exception('Unexpected output %s' % out) diff --git a/gitpylib/status.py b/gitpylib/status.py index d1da33c..348fbb3 100644 --- a/gitpylib/status.py +++ b/gitpylib/status.py @@ -6,7 +6,6 @@ import os -import re from . import common @@ -47,7 +46,7 @@ def of_file(fp): """ fp = common.real_case(fp) - ok, out_ls_files, unused_err = common.git_call( + ok, out_ls_files, _ = common.git_call( 'ls-files -tvco --error-unmatch "%s"' % fp) if not ok: # The file doesn't exist. @@ -99,7 +98,7 @@ def au_files(relative_to_cwd=False): reported. If False, all au files in the repository are reported. (Defaults to False.) """ - out, unused_err = common.safe_git_call( + out, _ = common.safe_git_call( 'ls-files -v {0}'.format( '--full-name "{0}"'.format( common.repo_dir()) if not relative_to_cwd else '')) @@ -121,7 +120,7 @@ def _is_au_file(fp): Args: fp: the filepath to check (fp must be a file not a dir). """ - out, unused_err = common.safe_git_call( + out, _ = common.safe_git_call( 'ls-files -v --full-name "{0}"'.format(fp)) ret = False if out: @@ -152,7 +151,7 @@ def sanitize_fp(fp): # them relative to the cwd. return os.path.relpath(os.path.join(repo_dir, fp), cwd) - out_status, unused_err = common.safe_git_call( + out_status, _ = common.safe_git_call( 'status --porcelain -u --ignored "{0}"'.format(pathspec)) ret = {} for f_out_status in out_status.splitlines(): diff --git a/gitpylib/sync.py b/gitpylib/sync.py index 36e6b7c..693cd3b 100644 --- a/gitpylib/sync.py +++ b/gitpylib/sync.py @@ -33,7 +33,7 @@ def commit(files, msg, skip_checks=False, stage_files=False): Returns: the output of the commit command. """ - out, unused_err = common.safe_git_call( + out, _ = common.safe_git_call( 'commit {0}{1}-m"{2}" "{3}"'.format( '--no-verify ' if skip_checks else '', '-i ' if stage_files else '', @@ -92,13 +92,13 @@ def _parse_rebase_output(ok, out, err): # TODO(sperezde): add the files whose changes would be lost. return (LOCAL_CHANGES_WOULD_BE_LOST, None) return (CONFLICT, None) - if re.match('Current branch [^\s]+ is up to date.\n', out): + if re.match(r'Current branch [^\s]+ is up to date.\n', out): return (NOTHING_TO_REBASE, None) return (SUCCESS, out) def rebase_continue(): - ok, out, err = common.git_call('rebase --continue') + ok, out, _ = common.git_call('rebase --continue') # print 'out is <%s>, err is <%s>' % (out, err) if not ok: return (CONFLICT, None) @@ -106,7 +106,7 @@ def rebase_continue(): def skip_rebase_commit(): - ok, out, err = common.git_call('rebase --skip') + ok, out, _ = common.git_call('rebase --skip') # print 'out is <%s>, err is <%s>' % (out, err) if not ok: return (CONFLICT, ['tbd1', 'tbd2']) @@ -122,7 +122,7 @@ def rebase_in_progress(): def push(src_branch, dst_remote, dst_branch): - ok, out, err = common.git_call( + ok, _, err = common.git_call( 'push %s %s:%s' % (dst_remote, src_branch, dst_branch)) if err == 'Everything up-to-date\n': return (NOTHING_TO_PUSH, None) From d964282d08e90d34af8f76780d82a743bc708eb2 Mon Sep 17 00:00:00 2001 From: Santiago Perez De Rosso Date: Wed, 29 Jan 2014 18:35:31 -0500 Subject: [PATCH 10/12] do a fetch when remote.add is called --- gitpylib/remote.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/gitpylib/remote.py b/gitpylib/remote.py index 55f2a25..e936db5 100644 --- a/gitpylib/remote.py +++ b/gitpylib/remote.py @@ -20,6 +20,8 @@ def add(remote_name, remote_url): """Adds the given remote. + Adds the remote mapping and also does a fetch. + Args: remote_name: the name of the remote to add. remote_url: the url of the remote to add. @@ -30,6 +32,7 @@ def add(remote_name, remote_url): if _show(remote_url)[0] == REMOTE_UNREACHABLE: return REMOTE_UNREACHABLE common.safe_git_call('remote add %s %s' % (remote_name, remote_url)) + common.safe_git_call('fetch %s' % remote_name) return SUCCESS From a27ee3aa2b3524aab681573b043b8aeac00d48da Mon Sep 17 00:00:00 2001 From: Santiago Perez De Rosso Date: Mon, 3 Feb 2014 22:23:25 -0500 Subject: [PATCH 11/12] release 0.5 --- RELEASE_NOTES.md | 11 ++++++++++- setup.py | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index f8740f1..e28024d 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -2,13 +2,22 @@ Gitpylib's Release Notes ======================== +3rd Feb 2014 - 0.5 +------------------ + +* gitpylib now works in python 2.6, 3.2 and 3.3 (in addition to 2.7). +* Added a function to get the names of the branches in a remote. +* remote.add will also do a fetch. +* Bug fixes. + + 16th Jan 2014 - 0.4.3 --------------------- * More performance improvements in status. * Added an option to not report tracked unmodified files if desired (which makes status much faster if the caller doesn't care about knowing which files are - tracked unmodified) + tracked unmodified). 15th Jan 2014 - 0.4.2 diff --git a/setup.py b/setup.py index 3ed4aac..557147f 100755 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setup( name='gitpylib', - version='0.4.3', + version='0.5', description='A Python library for Git', long_description=open('README.md').read(), author='Santiago Perez De Rosso', From 0137b96b8cab653a7ed0015e8645273c4e607111 Mon Sep 17 00:00:00 2001 From: Santiago Perez De Rosso Date: Mon, 3 Feb 2014 22:25:30 -0500 Subject: [PATCH 12/12] fix in release notes --- RELEASE_NOTES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index e28024d..c15984f 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -8,7 +8,7 @@ Gitpylib's Release Notes * gitpylib now works in python 2.6, 3.2 and 3.3 (in addition to 2.7). * Added a function to get the names of the branches in a remote. * remote.add will also do a fetch. -* Bug fixes. +* Bug fixes and code cleanups. 16th Jan 2014 - 0.4.3