Skip to content

Commit

Permalink
commands,t: report invalid ref in push command
Browse files Browse the repository at this point in the history
Unlike the "git lfs fetch" command, the "git lfs push" command does
not currently report an error if an invalid ref is provided as a
command-line argument, so we update the command to output an error
message in this situation, and we add a test to confirm the new
behaviour works as expected.

Note that in contrast to the "git lfs fetch" command's older
implementation of this type of check, we simply report an error message
when an invalid ref is encountered, rather than calling our Panic()
function and also writing a stack trace to a log file.  This approach is
more in keeping with how many of our commands now handle similar error
conditions; e.g., the "git lfs fsck" and "git lfs migrate" commands
call ExitWithError() rather than Panic() when refs cannot be resolved.

Co-authored-by: Philip Peterson <[email protected]>
  • Loading branch information
chrisd8088 and philip-peterson committed Feb 1, 2024
1 parent 55ea5d2 commit 115484e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions commands/command_push.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ func lfsPushRefs(refnames []string, pushAll bool) ([]*git.RefUpdate, error) {
refs[i] = git.NewRefUpdate(cfg.Git, cfg.PushRemote(), ref, nil)
} else {
ref := &git.Ref{Name: name, Type: git.RefTypeOther, Sha: name}
if _, err := git.ResolveRef(name); err != nil {
return nil, errors.New(tr.Tr.Get("Invalid ref argument: %v", name))
}
refs[i] = git.NewRefUpdate(cfg.Git, cfg.PushRemote(), ref, nil)
}
}
Expand Down
10 changes: 10 additions & 0 deletions t/t-push.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ begin_test "push with tracked ref"
)
end_test

begin_test "push with invalid ref"
(
set -e
push_repo_setup "push-invalid-branch-required"

git lfs push origin jibberish >push.log 2>&1 && exit 1
grep "Invalid ref argument" push.log
)
end_test

begin_test "push with bad ref"
(
set -e
Expand Down

0 comments on commit 115484e

Please sign in to comment.