File tree 2 files changed +21
-1
lines changed
2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -458,5 +458,19 @@ def is_dirty(self):
458
458
459
459
return len (self .git .diff ('HEAD' ).strip ()) > 0
460
460
461
+ @property
462
+ def active_branch (self ):
463
+ """
464
+ The name of the currently active branch.
465
+
466
+ Returns
467
+ str (the branch name)
468
+ """
469
+ branch = self .git .symbolic_ref ('HEAD' ).strip ()
470
+ if branch .startswith ('refs/heads/' ):
471
+ branch = branch [len ('refs/heads/' ):]
472
+
473
+ return branch
474
+
461
475
def __repr__ (self ):
462
476
return '<GitPython.Repo "%s">' % self .path
Original file line number Diff line number Diff line change @@ -307,10 +307,16 @@ def test_is_dirty_with_clean_working_dir(self, git):
307
307
git .return_value = ''
308
308
assert_false (self .repo .is_dirty )
309
309
assert_equal (git .call_args , (('diff' , 'HEAD' ), {}))
310
-
310
+
311
311
@patch (Git , '_call_process' )
312
312
def test_is_dirty_with_dirty_working_dir (self , git ):
313
313
self .repo .bare = False
314
314
git .return_value = '''-aaa\n +bbb'''
315
315
assert_true (self .repo .is_dirty )
316
316
assert_equal (git .call_args , (('diff' , 'HEAD' ), {}))
317
+
318
+ @patch (Git , '_call_process' )
319
+ def test_active_branch (self , git ):
320
+ git .return_value = 'refs/heads/major-refactoring'
321
+ assert_equal (self .repo .active_branch , 'major-refactoring' )
322
+ assert_equal (git .call_args , (('symbolic_ref' , 'HEAD' ), {}))
You can’t perform that action at this time.
0 commit comments