Omit current directory when browse --branch is used with no file argument (#4676)
This commit is contained in:
parent
3a4d947603
commit
dd0edc8fbd
2 changed files with 38 additions and 0 deletions
|
|
@ -192,6 +192,10 @@ func parseSection(baseRepo ghrepo.Interface, opts *BrowseOptions) (string, error
|
|||
}
|
||||
|
||||
func parseFile(opts BrowseOptions, f string) (p string, start int, end int, err error) {
|
||||
if f == "" {
|
||||
return
|
||||
}
|
||||
|
||||
parts := strings.SplitN(f, ":", 3)
|
||||
if len(parts) > 2 {
|
||||
err = fmt.Errorf("invalid file argument: %q", f)
|
||||
|
|
|
|||
|
|
@ -228,6 +228,35 @@ func Test_runBrowse(t *testing.T) {
|
|||
baseRepo: ghrepo.New("bchadwic", "LedZeppelinIV"),
|
||||
expectedURL: "https://github.com/bchadwic/LedZeppelinIV/tree/trunk/main.go",
|
||||
},
|
||||
{
|
||||
name: "branch flag within dir",
|
||||
opts: BrowseOptions{
|
||||
Branch: "feature-123",
|
||||
PathFromRepoRoot: func() string { return "pkg/dir" },
|
||||
},
|
||||
baseRepo: ghrepo.New("bstnc", "yeepers"),
|
||||
expectedURL: "https://github.com/bstnc/yeepers/tree/feature-123/",
|
||||
},
|
||||
{
|
||||
name: "branch flag within dir with .",
|
||||
opts: BrowseOptions{
|
||||
Branch: "feature-123",
|
||||
SelectorArg: ".",
|
||||
PathFromRepoRoot: func() string { return "pkg/dir" },
|
||||
},
|
||||
baseRepo: ghrepo.New("bstnc", "yeepers"),
|
||||
expectedURL: "https://github.com/bstnc/yeepers/tree/feature-123/pkg/dir",
|
||||
},
|
||||
{
|
||||
name: "branch flag within dir with dir",
|
||||
opts: BrowseOptions{
|
||||
Branch: "feature-123",
|
||||
SelectorArg: "inner/more",
|
||||
PathFromRepoRoot: func() string { return "pkg/dir" },
|
||||
},
|
||||
baseRepo: ghrepo.New("bstnc", "yeepers"),
|
||||
expectedURL: "https://github.com/bstnc/yeepers/tree/feature-123/pkg/dir/inner/more",
|
||||
},
|
||||
{
|
||||
name: "file with line number",
|
||||
opts: BrowseOptions{
|
||||
|
|
@ -466,6 +495,11 @@ func Test_parsePathFromFileArg(t *testing.T) {
|
|||
fileArg: filepath.Join("..", "..", "..") + s + "",
|
||||
expectedPath: "",
|
||||
},
|
||||
{
|
||||
name: "empty fileArg",
|
||||
fileArg: "",
|
||||
expectedPath: "",
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
path, _, _, _ := parseFile(BrowseOptions{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue