Skip to content
This repository
Browse code

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...
commit abbd6470378c8386eac543bc9b43320813be82c7 1 parent c4da1d8
Karthik Manamcheri authored davvid committed

Showing 1 changed file with 10 additions and 1 deletion. Show diff stats Hide diff stats

  1. +10 1 cola/utils.py
11 cola/utils.py
@@ -200,8 +200,17 @@ def strip_one(path):
200 200 >>> strip_one('/usr/bin/git')
201 201 'bin/git'
202 202
  203 + >>> strip_one('local/bin/git')
  204 + 'bin/git'
  205 +
  206 + >>> strip_one('bin/git')
  207 + 'git'
  208 +
  209 + >>> strip_one('git')
  210 + 'git'
  211 +
203 212 """
204   - return path.split('/', 1)[1]
  213 + return path.strip('/').split('/', 1)[-1]
205 214
206 215
207 216 def dirname(path):

0 comments on commit abbd647

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