FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
frontend/dev/git-branch-cleaner-remote at 90-appnexus-customData · devhttps/frontend · GitHub
devhttps
/
frontend
Public
forked from
guardian/frontend
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
frontend
/
dev
/
git-branch-cleaner-remote
Copy path
More file actions
More file actions
Latest commit
History
History
History
executable file
·
51 lines (39 loc) · 1.61 KB
Breadcrumbs
frontend
/
dev
/
git-branch-cleaner-remote
Copy path
File metadata and controls
executable file
·
51 lines (39 loc) · 1.61 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# This scripts helps removing remote Git branches.
# Run it from a git repo dir. It will open the Git branches list
# in your favorite editor. Delete some branches from the list.
# Save and close the file. The script applies the changes to the repo.
from
subprocess
import
call
,
Popen
,
PIPE
from
os
import
getenv
import
re
# configure commands used in this script
editor_command
=
getenv
(
'EDITOR'
)
branch_command
=
'git branch -r'
mktemp_command
=
'mktemp'
# takes 'git branch' output and returns a set of branches
def
branches_to_list
(
text
):
branches
=
set
()
for
branch
in
re
.
split
(
'
\n
'
,
text
):
branch
=
re
.
sub
(
' .+'
,
''
,
branch
.
lstrip
());
if
branch
is
not
''
:
branches
.
add
(
branch
)
return
branches
# create a temp file
tmp_file
=
Popen
(
mktemp_command
,
stdout
=
PIPE
).
communicate
()[
0
].
decode
().
rstrip
()
# write git branches to the temp file
call
(
'%s > %s'
%
(
branch_command
,
tmp_file
),
shell
=
True
)
# get original branches
original_branches
=
branches_to_list
(
open
(
tmp_file
,
'r'
).
read
())
# edit the temp file with the editor command
call
(
'%s %s'
%
(
editor_command
,
tmp_file
),
shell
=
True
)
# get new branches
new_branches
=
branches_to_list
(
open
(
tmp_file
,
'r'
).
read
())
# adding and renaming branches is not supported
if
(
new_branches
.
difference
(
original_branches
)):
exit
(
'Aborting! Do not add or rename branches, just remove them.'
)
# remove branches with Git
for
branch
in
original_branches
.
difference
(
new_branches
):
pushable
=
re
.
sub
(
'/'
,
' :'
,
branch
)
call
(
'git branch -rd %s'
%
branch
,
shell
=
True
)
call
(
'git push %s'
%
pushable
,
shell
=
True
)
Back
|
FazBrowse Home
|
New Git URL