Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,8 @@ git drs bucket add-project production \

### `git drs version`

Display version information.
Display version information. Works from any directory, without a Git repository
or git-drs initialization, and does not create a repository log file.

```bash
git drs version
Expand Down
2 changes: 2 additions & 0 deletions docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ export PATH="$PATH:$HOME/.local/bin"

## Verify The Install

Run either command from any directory; no Git repository or git-drs initialization is required.

```bash
git-drs version
git drs version
Expand Down
10 changes: 6 additions & 4 deletions git-drs.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ import (

func main() {

_, err := drslog.NewLogger("", true)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to open log file: %v", err)
os.Exit(1)
// Version only reads build metadata and needs no repository log.
if len(os.Args) < 2 || os.Args[1] != "version" {
if _, err := drslog.NewLogger("", true); err != nil {
fmt.Fprintf(os.Stderr, "Failed to open log file: %v", err)
os.Exit(1)
}
}

// Keep credential helper out of the user-facing command tree/help output.
Expand Down
33 changes: 33 additions & 0 deletions git-drs_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package main

import (
"bytes"
"os"
"os/exec"
"path/filepath"
"testing"

"github.com/stretchr/testify/require"
)

func TestVersionOutsideRepository(t *testing.T) {
binary := filepath.Join(t.TempDir(), "git-drs")
build := exec.Command("go", "build", "-o", binary, ".")
output, err := build.CombinedOutput()
require.NoError(t, err, "%s", output)

dir := t.TempDir()
command := exec.Command(binary, "version")
command.Dir = dir
// Prevent an inherited Git environment from pointing at a repository.
command.Env = append(os.Environ(), "GIT_DIR=", "GIT_WORK_TREE=", "GIT_CEILING_DIRECTORIES="+filepath.Dir(dir))
var stderr bytes.Buffer
command.Stderr = &stderr
output, err = command.Output()
require.NoError(t, err, "%s", stderr.String())
require.Empty(t, stderr.String())
require.Regexp(t, `^git-drs \S+\n$`, string(output))
entries, err := os.ReadDir(dir)
require.NoError(t, err)
require.Empty(t, entries, "version should not create repository or log files")
}
Loading