Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-shell
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-shell
Commits
01014c47
Commit
01014c47
authored
Apr 10, 2019
by
Nick Thomas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Pass the root directory into the fallback command
parent
f6a7f171
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
99 additions
and
12 deletions
+99
-12
go/cmd/gitlab-shell/main.go
go/cmd/gitlab-shell/main.go
+6
-5
go/internal/command/command.go
go/internal/command/command.go
+1
-1
go/internal/command/fallback/fallback.go
go/internal/command/fallback/fallback.go
+17
-6
go/internal/command/fallback/fallback_test.go
go/internal/command/fallback/fallback_test.go
+75
-0
No files found.
go/cmd/gitlab-shell/main.go
View file @
01014c47
...
...
@@ -26,8 +26,9 @@ func findRootDir() (string, error) {
// rubyExec will never return. It either replaces the current process with a
// Ruby interpreter, or outputs an error and kills the process.
func
execRuby
(
readWriter
*
readwriter
.
ReadWriter
)
{
cmd
:=
&
fallback
.
Command
{}
func
execRuby
(
rootDir
string
,
readWriter
*
readwriter
.
ReadWriter
)
{
cmd
:=
&
fallback
.
Command
{
RootDir
:
rootDir
,
Args
:
os
.
Args
}
if
err
:=
cmd
.
Execute
(
readWriter
);
err
!=
nil
{
fmt
.
Fprintf
(
readWriter
.
ErrOut
,
"Failed to exec: %v
\n
"
,
err
)
os
.
Exit
(
1
)
...
...
@@ -43,8 +44,8 @@ func main() {
rootDir
,
err
:=
findRootDir
()
if
err
!=
nil
{
fmt
.
Fprintln
(
readWriter
.
ErrOut
,
"Failed to determine root directory,
falling back to gitlab-shell-ruby
"
)
execRuby
(
readWriter
)
fmt
.
Fprintln
(
readWriter
.
ErrOut
,
"Failed to determine root directory,
exiting
"
)
os
.
Exit
(
1
)
}
// Fall back to Ruby in case of problems reading the config, but issue a
...
...
@@ -52,7 +53,7 @@ func main() {
config
,
err
:=
config
.
NewFromDir
(
rootDir
)
if
err
!=
nil
{
fmt
.
Fprintln
(
readWriter
.
ErrOut
,
"Failed to read config, falling back to gitlab-shell-ruby"
)
execRuby
(
readWriter
)
execRuby
(
r
ootDir
,
r
eadWriter
)
}
cmd
,
err
:=
command
.
New
(
os
.
Args
,
config
)
...
...
go/internal/command/command.go
View file @
01014c47
...
...
@@ -24,7 +24,7 @@ func New(arguments []string, config *config.Config) (Command, error) {
return
buildCommand
(
args
,
config
),
nil
}
return
&
fallback
.
Command
{},
nil
return
&
fallback
.
Command
{
RootDir
:
config
.
RootDir
,
Args
:
arguments
},
nil
}
func
buildCommand
(
args
*
commandargs
.
CommandArgs
,
config
*
config
.
Config
)
Command
{
...
...
go/internal/command/fallback/fallback.go
View file @
01014c47
...
...
@@ -8,14 +8,25 @@ import (
"gitlab.com/gitlab-org/gitlab-shell/go/internal/command/readwriter"
)
type
Command
struct
{}
type
Command
struct
{
RootDir
string
Args
[]
string
}
var
(
binDir
=
filepath
.
Dir
(
os
.
Args
[
0
])
// execFunc is overridden in tests
execFunc
=
syscall
.
Exec
)
const
(
RubyProgram
=
"gitlab-shell-ruby"
)
func
(
c
*
Command
)
Execute
(
_
*
readwriter
.
ReadWriter
)
error
{
rubyCmd
:=
filepath
.
Join
(
binDir
,
"gitlab-shell-ruby"
)
execErr
:=
syscall
.
Exec
(
rubyCmd
,
os
.
Args
,
os
.
Environ
())
return
execErr
func
(
c
*
Command
)
Execute
(
*
readwriter
.
ReadWriter
)
error
{
rubyCmd
:=
filepath
.
Join
(
c
.
RootDir
,
"bin"
,
RubyProgram
)
// Ensure rubyArgs[0] is the full path to gitlab-shell-ruby
rubyArgs
:=
append
([]
string
{
rubyCmd
},
c
.
Args
[
1
:
]
...
)
return
execFunc
(
rubyCmd
,
rubyArgs
,
os
.
Environ
())
}
go/internal/command/fallback/fallback_test.go
0 → 100644
View file @
01014c47
package
fallback
import
(
"errors"
"os"
"testing"
"github.com/stretchr/testify/require"
)
type
fakeExec
struct
{
OldExec
func
(
string
,
[]
string
,
[]
string
)
error
Error
error
Called
bool
Filename
string
Args
[]
string
Env
[]
string
}
var
(
fakeArgs
=
[]
string
{
"./test"
,
"foo"
,
"bar"
}
)
func
(
f
*
fakeExec
)
Exec
(
filename
string
,
args
[]
string
,
env
[]
string
)
error
{
f
.
Called
=
true
f
.
Filename
=
filename
f
.
Args
=
args
f
.
Env
=
env
return
f
.
Error
}
func
(
f
*
fakeExec
)
Setup
()
{
f
.
OldExec
=
execFunc
execFunc
=
f
.
Exec
}
func
(
f
*
fakeExec
)
Cleanup
()
{
execFunc
=
f
.
OldExec
}
func
TestExecuteExecsCommandSuccesfully
(
t
*
testing
.
T
)
{
cmd
:=
&
Command
{
RootDir
:
"/tmp"
,
Args
:
fakeArgs
}
// Override the exec func
fake
:=
&
fakeExec
{}
fake
.
Setup
()
defer
fake
.
Cleanup
()
require
.
NoError
(
t
,
cmd
.
Execute
(
nil
))
require
.
True
(
t
,
fake
.
Called
)
require
.
Equal
(
t
,
fake
.
Filename
,
"/tmp/bin/gitlab-shell-ruby"
)
require
.
Equal
(
t
,
fake
.
Args
,
[]
string
{
"/tmp/bin/gitlab-shell-ruby"
,
"foo"
,
"bar"
})
require
.
Equal
(
t
,
fake
.
Env
,
os
.
Environ
())
}
func
TestExecuteExecsCommandOnError
(
t
*
testing
.
T
)
{
cmd
:=
&
Command
{
RootDir
:
"/test"
,
Args
:
fakeArgs
}
// Override the exec func
fake
:=
&
fakeExec
{
Error
:
errors
.
New
(
"Test error"
)}
fake
.
Setup
()
defer
fake
.
Cleanup
()
require
.
Error
(
t
,
cmd
.
Execute
(
nil
))
require
.
True
(
t
,
fake
.
Called
)
}
func
TestExecuteGivenNonexistentCommand
(
t
*
testing
.
T
)
{
cmd
:=
&
Command
{
RootDir
:
"/tmp/does/not/exist"
,
Args
:
fakeArgs
}
require
.
Error
(
t
,
cmd
.
Execute
(
nil
))
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment