Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
G
git-scripts
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hugo Hörnquist
git-scripts
Commits
c07d33f6
Commit
c07d33f6
authored
2 years ago
by
Hugo Hörnquist
Browse files
Options
Downloads
Patches
Plain Diff
open: fix linter warnings.
parent
89671c1b
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
git-open
+16
-5
16 additions, 5 deletions
git-open
with
16 additions
and
5 deletions
git-open
+
16
−
5
View file @
c07d33f6
...
...
@@ -40,13 +40,16 @@ def popen(str):
sys
.
exit
(
1
)
return
out
def
gitconf
(
field
):
return
popen
(
"
git config
"
+
field
)
def
remote_url
(
remote_name
):
# return gitconf("remote.{}.url".format(remote_name))
return
popen
(
f
'
git remote get-url
{
remote_name
}
'
).
strip
()
def
to_http
(
url
):
for
pattern
in
configuration
[
'
patterns
'
]:
if
match
:
=
re
.
match
(
pattern
[
'
i
'
],
url
):
...
...
@@ -69,23 +72,29 @@ def to_http(url):
return
"
https://
"
+
base
+
"
/
"
+
path
raise
Exception
(
"
URL doesn
'
t start with either
'
http
'
or
'
git@
'"
)
def
xdg_open
(
item
):
subprocess
.
run
([
"
xdg-open
"
,
item
])
def
err
(
s
):
print
(
"
\x1b
[0;31mError
\x1b
[m
"
+
s
)
def
warn
(
s
):
print
(
"
\x1b
[0;33mWarn
\x1b
[m
"
+
s
)
def
info
(
s
):
print
(
"
\x1b
[0;32mInfo
\x1b
[m
"
+
s
)
def
open_remote
(
remote
):
url
=
to_http
(
remote_url
(
remote
))
xdg_open
(
url
)
info
(
f
'
opening
{
url
}
'
)
def
main
(
args
):
out
=
popen
(
"
git remote
"
)
remotes
=
out
.
strip
().
split
(
"
\n
"
)
...
...
@@ -94,7 +103,7 @@ def main(args):
do
=
open_remote
if
args
.
dry_run
:
do
=
lambda
x
:
print
(
to_http
(
remote_url
(
x
)))
do
=
lambda
x
:
print
(
to_http
(
remote_url
(
x
)))
# noqa: E731
if
not
remotes
:
err
(
"
No remotes
"
)
...
...
@@ -117,6 +126,7 @@ def main(args):
else
:
err
(
"
All remotes failed
"
)
def
load_configuration
():
global
configuration
# TODO possibly add ~/.config/git/open.yaml to list
...
...
@@ -129,10 +139,12 @@ def load_configuration():
except
FileNotFoundError
:
pass
if
__name__
==
"
__main__
"
:
# Note that argparse gives `--help' and `-h', but git "eats"
# `--help'. `-h' does however work.
parser
=
argparse
.
ArgumentParser
(
description
=
'
open git remotes in web browser
'
)
parser
=
argparse
.
ArgumentParser
(
description
=
'
open git remotes in web browser
'
)
parser
.
add_argument
(
'
-n
'
,
'
--dry-run
'
,
action
=
'
store_true
'
,
dest
=
'
dry_run
'
)
parser
.
add_argument
(
'
remote
'
,
action
=
'
store
'
,
nargs
=
'
?
'
)
args
=
parser
.
parse_args
()
...
...
@@ -141,4 +153,3 @@ if __name__ == "__main__":
load_configuration
()
main
(
args
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment