Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

agit flow hook refuses forced pushes #16679

Closed
2 of 3 tasks
wULLSnpAXbWZGYDYyhWTKKspEQoaYxXyhoisqHf opened this issue Aug 12, 2021 · 7 comments
Closed
2 of 3 tasks

agit flow hook refuses forced pushes #16679

wULLSnpAXbWZGYDYyhWTKKspEQoaYxXyhoisqHf opened this issue Aug 12, 2021 · 7 comments
Labels
type/enhancement An improvement of existing functionality

Comments

@wULLSnpAXbWZGYDYyhWTKKspEQoaYxXyhoisqHf
Copy link
Contributor

  • Gitea version (or commit ref): Gitea version 1.16.0+dev-96-gf1a810e09 built with GNU Make 4.3, go1.16.7 : netgo, osusergo, bindata, sqlite, sqlite_unlock_notify

  • Git version: 2.33.0.rc0.290.g2c90b51f76

  • Operating system: Arch Linux

  • Built from: source

  • Run with: systemd

  • Database:

    • SQLite
  • Can you reproduce the bug at https://try.gitea.io:

    • I have not tried yet, I don't see why it wouldn't work in a fresh repo like I tried it with...
  • Log gist:

    • TBD

Description

First off, I appreciate this feature (implemented recently in #14295), it is really handy (I didn't know about agit flow before btw).

I have run into an issue when force pushing an update into a PR while doing this agit flow stuff (after initially opening the PR using this method).
The force push was then refused by Gitea (a git hook).
The command used was git push --force HEAD:refs/for/whatever-the-branch-was -o topic=topic-name if I recall correctly.
EDIT: this was a typo here, I meant to say I pushed the HEAD ref, not "HEADS".

Note that

  • branch protection has not been enabled in this particular instance,
  • repo hooks have been reinitialized as per the subject PR request (it was noted somewhere there).

I cannot tell whether that is intended behaviour or not, i.e. whether I even ought to try to force push in agit flow or not.

@lunny
Copy link
Member

lunny commented Aug 13, 2021

@a1012112796 Maybe you can take a look.

@lunny lunny added the type/bug label Aug 13, 2021
@zeripath
Copy link
Contributor

I think this is similar to the problem seen here #15373 (comment)

I'm suspicious that might be some weird regression or interaction with #15629.

@wULLSnpAXbWZGYDYyhWTKKspEQoaYxXyhoisqHf
Copy link
Contributor Author

I think this is similar to the problem seen here #15373 (comment)

I'm suspicious that might be some weird regression or interaction with #15629.

oh bugger 🙈

@a1012112796
Copy link
Member

Sorry, because can't get --force option in git hook, I use a push option to check if user want to force push
example:

git push -o force-push=true ...

ref:

_, forcePush = opts.GitPushOptions["force-push"]

@lunny
Copy link
Member

lunny commented Aug 14, 2021

@a1012112796
Copy link
Member

a1012112796 commented Aug 14, 2021

@a1012112796 could you use https://github.com/go-gitea/gitea/blob/main/modules/repository/push.go#L101 to detect it?

They are same, ref:

gitea/services/agit/agit.go

Lines 206 to 223 in 23a87a0

if !forcePush {
output, err := git.NewCommand("rev-list", "--max-count=1", oldCommitID, "^"+opts.NewCommitIDs[i]).RunInDirWithEnv(repo.RepoPath(), os.Environ())
if err != nil {
log.Error("Unable to detect force push between: %s and %s in %-v Error: %v", oldCommitID, opts.NewCommitIDs[i], repo, err)
ctx.JSON(http.StatusInternalServerError, private.Response{
Err: fmt.Sprintf("Fail to detect force push: %v", err),
})
return nil
} else if len(output) > 0 {
results = append(results, private.HockProcReceiveRefResult{
OriginalRef: oldCommitID,
OldOID: opts.OldCommitIDs[i],
NewOID: opts.NewCommitIDs[i],
Err: "request `force-push` push option",
})
continue
}
}

I means to check if user make sure they want to force push, like the usage of --force.

@lunny
Copy link
Member

lunny commented Oct 11, 2024

Fixed by https://gitea.com/gitea/docs/pulls/78

@lunny lunny added type/enhancement An improvement of existing functionality and removed type/bug labels Oct 11, 2024
@lunny lunny added this to the 1.23.0 milestone Oct 11, 2024
@lunny lunny closed this as completed Oct 12, 2024
@lunny lunny removed this from the 1.23.0 milestone Oct 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/enhancement An improvement of existing functionality
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants