Skip to content

Commit

Permalink
Fixes #88: If merge.tool doesn't exist in ~/.gitconfig then inform user
Browse files Browse the repository at this point in the history
Signed-off-by: Petr Hracek <phracek@redhat.com>
  • Loading branch information
phracek committed Mar 11, 2015
1 parent 0cfdd1f commit e18d64a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 15 deletions.
2 changes: 1 addition & 1 deletion rebasehelper/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ def patch_sources(self, sources):
# Patch sources
self.kwargs['diff_tool'] = self.conf.difftool
git_helper = GitHelper(sources[0])
git_helper.check_git_config()
patch = Patcher(self.conf.patchtool)

self.rebase_spec_file.update_changelog(self.rebase_spec_file.get_new_log(git_helper))
Expand Down Expand Up @@ -399,7 +400,6 @@ def print_summary(self):
def run(self):
sources = self.prepare_sources()

GitHelper.check_git_config()
if not self.conf.build_only:
self.patch_sources(sources)

Expand Down
18 changes: 4 additions & 14 deletions rebasehelper/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,25 +512,13 @@ def _call_git_command(self, command, input_file=None, output_file=None):
output_data.append(o.strip())
return ret_code, output_data

@staticmethod
def check_git_config():
def check_git_config(self):
"""
Function checks whether you have setup a merge tool in ~/.gitconfig
:return: True or False
"""
git_config = []
merge = self.command_config('--get', 'merge.tool')
git_config_name = os.path.expanduser('~/{0}'.format(settings.GIT_CONFIG))
try:
with open(git_config_name) as f:
git_config = f.readlines()
except IOError as ioer:
raise RebaseHelperError("Unable to open and read SPEC file '{0}'. {1}".format(git_config_name,
exc_as_decode_string(ioer)))

if not git_config:
raise RebaseHelperError("File {0} is empty".format(git_config_name))

merge = [x.strip() for x in git_config if x.startswith('[merge]')]
if not merge:
message = """[merge] section is not defined in {0}.\n
One of the possible configuration can be:\n
Expand Down Expand Up @@ -687,4 +675,6 @@ def command_config(self, parameters, variable=None):
cmd.append(parameters)
cmd.append(variable)
ret_code, output = self._call_git_command(cmd)
if not output:
return None
return output[0]

0 comments on commit e18d64a

Please sign in to comment.