Skip to content

Commit e951a24

Browse files
author
jsbain
committed
Handle blank new/clone local path. Fix exception handling in several places. Added show log capability
1 parent fc51228 commit e951a24

File tree

2 files changed

+27
-10
lines changed

2 files changed

+27
-10
lines changed

gitui.py

+26-9
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ def diffact(sender):
121121
try:
122122
difftxt=[x['diff'] for x in self.g.diff_working() if x['new']['path']==str(self.list[section][row])]
123123
sys.stdout.write(difftxt[0])
124-
except ValueError,KeyError:
125-
print 'uhhhh'
124+
except (ValueError,KeyError):
125+
console.hud_alert('could not create a diff, for some strange reason!')
126126
def diffacthtml(sender,difftype=git_diff.source.PATH):
127127
f=git_diff.diff_working(self._repo(),str(self.list[section][row]),difftype)
128128
w=ui.WebView(frame=self.view.frame)
@@ -289,7 +289,7 @@ def _get_last_committer(self):
289289
elif last_commit.committer:
290290
author,author_email=(last_commit.committer.split('>')[0]+'<').split('<')[0:2]
291291
return author,author_email
292-
except KeyError, AttributeError:
292+
except (KeyError, AttributeError):
293293
return '',''
294294
def commit(self,sender):
295295
if list(itertools.chain(*porcelain.status(self.g.path).staged.itervalues())):
@@ -388,7 +388,7 @@ def remote_for_head(self):
388388
head=self._repo().head()
389389
remote, remote_branch=[ k.split('/')[-2:] for k,v in refs if v==head and k.startswith('refs/remotes')][0]
390390
return remote,remote_branch
391-
except IndexError, KeyError:
391+
except (IndexError, KeyError):
392392
return '',''
393393

394394
def checkout(self,sender):
@@ -420,7 +420,9 @@ def clone(self,clonedict):
420420
remote=clonedict['remote url']
421421
local=clonedict['local path']
422422
repo_name= os.path.join(self.view['repo'].base, local)
423-
423+
if not local:
424+
console.hud_alert('you must define a local path','error')
425+
return
424426
if remote:
425427
try:
426428
repo = Gittle.clone(remote, repo_name, bare=False)
@@ -432,14 +434,18 @@ def clone(self,clonedict):
432434
self.view['repo'].txt=repo_name
433435
self.refresh()
434436
except Exception as e:
435-
console.hud_alert(e.message)
437+
console.hud_alert(e.message,'error')
436438

437439
def clone_action(self,sender):
438440
d=UIDialog(root=self.view,title='Clone repo',items={'remote url':'https://github.com/','local path':''},ok_action=self.clone)
439441

440442
def new_action(self,sender):
441443
def ok(somedict):
442-
self.init_repo(somedict['repo name'])
444+
reponame=somedict['repo name']
445+
if reponame:
446+
self.init_repo(reponame)
447+
else:
448+
console.hud_alert('No repo created, name was blank!','error')
443449
d=UIDialog(root=self.view,title='Clone repo',items={'repo name':''},ok_action=ok)
444450

445451
def pull(self):
@@ -526,6 +532,18 @@ def resetPW(self,sender):
526532
console.hud_alert('removed password for {}@{}'.format( user,netloc))
527533
except KeyError:
528534
console.hud_alert('no saved auth for {}'.format( netloc))
535+
def log_action(self,sender):
536+
import StringIO
537+
s=StringIO.StringIO()
538+
w=ui.WebView(frame=self.view.frame)
539+
w.name='Log'
540+
porcelain.log(self._repo().path, outstream=s)
541+
log=s.getvalue()
542+
log=log.replace('\n','<p>')
543+
#print log
544+
w.load_html(log)
545+
w.present('popover')
546+
529547
def auth_urllib2_opener(config, top_level_url, username, password):
530548
if config is not None:
531549
proxy_server = config.get("http", "proxy")
@@ -556,8 +574,6 @@ def auth_urllib2_opener(config, top_level_url, username, password):
556574
return opener
557575

558576

559-
560-
561577
r=repoView()
562578
v=ui.load_view('gitui')
563579
r.view=v
@@ -576,6 +592,7 @@ def auth_urllib2_opener(config, top_level_url, username, password):
576592
v['clone'].action=r.clone_action
577593
v['new'].action=r.new_action
578594
v['resetPW'].action=r.resetPW
595+
v['log'].action=r.log_action
579596
#load current repo
580597
editorpath=os.path.split(editor.get_path())[0]
581598
if editorpath.startswith('/var'):

0 commit comments

Comments
 (0)