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
00338214
Commit
00338214
authored
4 years ago
by
Hugo Hörnquist
Browse files
Options
Downloads
Patches
Plain Diff
Git-open better error handling.
parent
5d1b083d
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
+15
-19
15 additions, 19 deletions
git-open
with
15 additions
and
19 deletions
git-open
+
15
−
19
View file @
00338214
...
@@ -17,7 +17,8 @@ def gitconf(field):
...
@@ -17,7 +17,8 @@ def gitconf(field):
return
popen
(
"
git config
"
+
field
)
return
popen
(
"
git config
"
+
field
)
def
remote_url
(
remote_name
):
def
remote_url
(
remote_name
):
return
gitconf
(
"
remote.{}.url
"
.
format
(
remote_name
))
# return gitconf("remote.{}.url".format(remote_name))
return
popen
(
f
'
git remote get-url
{
remote_name
}
'
).
strip
()
def
to_http
(
url
):
def
to_http
(
url
):
if
url
[
0
:
4
]
==
"
http
"
:
if
url
[
0
:
4
]
==
"
http
"
:
...
@@ -25,7 +26,8 @@ def to_http(url):
...
@@ -25,7 +26,8 @@ def to_http(url):
if
url
[
0
:
4
]
==
"
git@
"
:
if
url
[
0
:
4
]
==
"
git@
"
:
base
,
path
=
url
[
4
:].
split
(
"
:
"
)
base
,
path
=
url
[
4
:].
split
(
"
:
"
)
return
"
https://
"
+
base
+
"
/
"
+
path
return
"
https://
"
+
base
+
"
/
"
+
path
return
"
http://www.nicememe.website
"
raise
Exception
(
"
URL doesn
'
t start with either
'
http
'
or
'
git@
'"
)
# return "http://www.nicememe.website"
def
xdg_open
(
item
):
def
xdg_open
(
item
):
subprocess
.
run
([
"
xdg-open
"
,
item
])
subprocess
.
run
([
"
xdg-open
"
,
item
])
...
@@ -34,10 +36,10 @@ def err(s):
...
@@ -34,10 +36,10 @@ def err(s):
print
(
"
\x1b
[0;31mError
\x1b
[m
"
+
s
)
print
(
"
\x1b
[0;31mError
\x1b
[m
"
+
s
)
def
warn
(
s
):
def
warn
(
s
):
print
(
"
\x1b
[0;3
2
mWarn
\x1b
[m
"
+
s
)
print
(
"
\x1b
[0;3
3
mWarn
\x1b
[m
"
+
s
)
def
info
(
s
):
def
info
(
s
):
print
(
"
\x1b
[0;3
3
mInfo
\x1b
[m
"
+
s
)
print
(
"
\x1b
[0;3
2
mInfo
\x1b
[m
"
+
s
)
def
main
(
args
):
def
main
(
args
):
out
=
popen
(
"
git remote
"
)
out
=
popen
(
"
git remote
"
)
...
@@ -49,23 +51,17 @@ def main(args):
...
@@ -49,23 +51,17 @@ def main(args):
if
not
remotes
:
if
not
remotes
:
err
(
"
No remotes
"
)
err
(
"
No remotes
"
)
if
len
(
remotes
)
==
1
:
if
remote
and
remotes
[
0
]
!=
remote
:
err
(
"
No remote with name
"
+
remote
)
return
xdg_open
(
to_http
(
remote_url
(
remotes
[
0
])))
for
remote
in
remotes
:
try
:
url
=
to_http
(
remote_url
(
remote
))
xdg_open
(
url
)
info
(
f
'
opening
{
url
}
'
)
break
except
Exception
as
e
:
warn
(
str
(
e
))
else
:
else
:
if
remote
:
err
(
"
All remotes failed
"
)
if
remote
in
remotes
:
xdg_open
(
to_http
(
remote_url
(
remote
)))
return
else
:
err
(
"
No remote with name
"
+
remote
)
return
info
(
"
Multiple remotes found, defaulting to
"
+
remotes
[
0
])
xdg_open
(
to_http
(
remote_url
(
remotes
[
0
])))
if
__name__
==
"
__main__
"
:
if
__name__
==
"
__main__
"
:
main
(
sys
.
argv
)
main
(
sys
.
argv
)
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