Skip to content
Browse files

utils: Fix a bug in strip_one()

If the path doesn't have a '/' then it can't access the index 1.
Handle it by returning path.split('/',1)[-1] instead of [1].

Signed-off-by: Karthik Manamcheri <karthik.manamcheri@gmail.com>
Signed-off-by: David Aguilar <davvid@gmail.com>
  • Loading branch information...
1 parent c4da1d8 commit abbd6470378c8386eac543bc9b43320813be82c7 Karthik Manamcheri committed with davvid May 21, 2012
Showing with 10 additions and 1 deletion.
  1. +10 −1 cola/utils.py
View
11 cola/utils.py
@@ -200,8 +200,17 @@ def strip_one(path):
>>> strip_one('/usr/bin/git')
'bin/git'
+ >>> strip_one('local/bin/git')
+ 'bin/git'
+
+ >>> strip_one('bin/git')
+ 'git'
+
+ >>> strip_one('git')
+ 'git'
+
"""
- return path.split('/', 1)[1]
+ return path.strip('/').split('/', 1)[-1]
def dirname(path):

0 comments on commit abbd647

Please sign in to comment.
Something went wrong with that request. Please try again.