diff mbox

[kteam-tools] Fix inconvenient usage of strip

Message ID 1371815646-8664-1-git-send-email-stefan.bader@canonical.com
State New
Headers show

Commit Message

Stefan Bader June 21, 2013, 11:54 a.m. UTC
From e5ea00c057f0541a1a9e319d3ed43700c44a0ba0 Mon Sep 17 00:00:00 2001
From: Stefan Bader <stefan.bader@canonical.com>
Date: Fri, 21 Jun 2013 13:47:49 +0200
Subject: [PATCH] ktl: Git.current_branch: Fix inconvenient usage of strip

The argument to strip is a list of letters to remove from one side,
not a prefix. This is inconvenient if the text after the prefix
happens to start with one or more of those letters.

Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
---
 ktl/git.py |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Brad Figg June 21, 2013, 2:41 p.m. UTC | #1
On 06/21/2013 04:54 AM, Stefan Bader wrote:
> From e5ea00c057f0541a1a9e319d3ed43700c44a0ba0 Mon Sep 17 00:00:00 2001
> From: Stefan Bader <stefan.bader@canonical.com>
> Date: Fri, 21 Jun 2013 13:47:49 +0200
> Subject: [PATCH] ktl: Git.current_branch: Fix inconvenient usage of strip
> 
> The argument to strip is a list of letters to remove from one side,
> not a prefix. This is inconvenient if the text after the prefix
> happens to start with one or more of those letters.
> 
> Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
> ---
>  ktl/git.py |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/ktl/git.py b/ktl/git.py
> index 28412af..3d6b3d3 100644
> --- a/ktl/git.py
> +++ b/ktl/git.py
> @@ -98,7 +98,7 @@ class Git:
>          status, result = run_command("git symbolic-ref HEAD", cls.debug)
>          if status != 0:
>              raise GitError("no current branch")
> -        return result[0].lstrip("refs/heads/")
> +        return result[0].split("/")[-1]
>  
>      # show
>      #
> 

Or how about a "replace('refs/heads/', '')" ?
Stefan Bader June 21, 2013, 2:46 p.m. UTC | #2
On 21.06.2013 16:41, Brad Figg wrote:
> On 06/21/2013 04:54 AM, Stefan Bader wrote:
>> From e5ea00c057f0541a1a9e319d3ed43700c44a0ba0 Mon Sep 17 00:00:00 2001
>> From: Stefan Bader <stefan.bader@canonical.com>
>> Date: Fri, 21 Jun 2013 13:47:49 +0200
>> Subject: [PATCH] ktl: Git.current_branch: Fix inconvenient usage of strip
>>
>> The argument to strip is a list of letters to remove from one side,
>> not a prefix. This is inconvenient if the text after the prefix
>> happens to start with one or more of those letters.
>>
>> Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
>> ---
>>  ktl/git.py |    2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/ktl/git.py b/ktl/git.py
>> index 28412af..3d6b3d3 100644
>> --- a/ktl/git.py
>> +++ b/ktl/git.py
>> @@ -98,7 +98,7 @@ class Git:
>>          status, result = run_command("git symbolic-ref HEAD", cls.debug)
>>          if status != 0:
>>              raise GitError("no current branch")
>> -        return result[0].lstrip("refs/heads/")
>> +        return result[0].split("/")[-1]
>>  
>>      # show
>>      #
>>
> 
> Or how about a "replace('refs/heads/', '')" ?
> 

That seams to work as well at least with the ec2 branch which would have become
a "c2" previously. So I would not care that much which variant.
Brad Figg June 21, 2013, 3:04 p.m. UTC | #3
On 06/21/2013 07:46 AM, Stefan Bader wrote:
> On 21.06.2013 16:41, Brad Figg wrote:
>> On 06/21/2013 04:54 AM, Stefan Bader wrote:
>>> From e5ea00c057f0541a1a9e319d3ed43700c44a0ba0 Mon Sep 17 00:00:00 2001
>>> From: Stefan Bader <stefan.bader@canonical.com>
>>> Date: Fri, 21 Jun 2013 13:47:49 +0200
>>> Subject: [PATCH] ktl: Git.current_branch: Fix inconvenient usage of strip
>>>
>>> The argument to strip is a list of letters to remove from one side,
>>> not a prefix. This is inconvenient if the text after the prefix
>>> happens to start with one or more of those letters.
>>>
>>> Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
>>> ---
>>>  ktl/git.py |    2 +-
>>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/ktl/git.py b/ktl/git.py
>>> index 28412af..3d6b3d3 100644
>>> --- a/ktl/git.py
>>> +++ b/ktl/git.py
>>> @@ -98,7 +98,7 @@ class Git:
>>>          status, result = run_command("git symbolic-ref HEAD", cls.debug)
>>>          if status != 0:
>>>              raise GitError("no current branch")
>>> -        return result[0].lstrip("refs/heads/")
>>> +        return result[0].split("/")[-1]
>>>  
>>>      # show
>>>      #
>>>
>>
>> Or how about a "replace('refs/heads/', '')" ?
>>
> 
> That seams to work as well at least with the ec2 branch which would have become
> a "c2" previously. So I would not care that much which variant.
> 
> 
> 
> 

I went with the replace since that seems to be what the author was
going for.
diff mbox

Patch

diff --git a/ktl/git.py b/ktl/git.py
index 28412af..3d6b3d3 100644
--- a/ktl/git.py
+++ b/ktl/git.py
@@ -98,7 +98,7 @@  class Git:
         status, result = run_command("git symbolic-ref HEAD", cls.debug)
         if status != 0:
             raise GitError("no current branch")
-        return result[0].lstrip("refs/heads/")
+        return result[0].split("/")[-1]
 
     # show
     #