Closed SebastianSchumann closed 1 hour ago
Did you talking about Create Branch
? In fact, SourceGit has not used the --no-verify
parameter.
No. We're using git-hooks to prevent users from committing directly to main
. Everyone has to create a branch and create a pull-request.
But via SourceGit you can simply commit to main
without getting an error message.
If the same operation is done with git commit
or SourceTree, I get the desired error message.
SourceGit doesn't care about any git hooks, which is something the git process needs to care about. In addition, the implementation of git commit
in the project is very simple:
namespace SourceGit.Commands
{
public class Commit : Command
{
public Commit(string repo, string message, bool amend, bool allowEmpty = false)
{
var file = Path.GetTempFileName();
File.WriteAllText(file, message);
WorkingDirectory = repo;
Context = repo;
TraitErrorAsOutput = true;
Args = $"commit --file=\"{file}\"";
if (amend)
Args += " --amend --no-edit";
if (allowEmpty)
Args += " --allow-empty";
}
}
}
Our pre-commit
-hock (<repo>/.githooks/pre-commit
) is:
#!/usr/bin/env bash
LC_ALL=C
local_branch="$(git rev-parse --abbrev-ref HEAD)"
user_name=$(echo $USERNAME | tr '[:upper:]' '[:lower:]')
valid_branch_regex="^(dev/${user_name}/\#[0-9]{4,}.*|${user_name}-patch-[0-9]+|project/.+)$"
message="There is something wrong with your branch name. Branch names in this project must adhere to this contract: $valid_branch_regex. Your commit will be rejected. You should rename your branch to a valid name and try again."
if [[ ! $local_branch =~ $valid_branch_regex ]]
then
echo "$message"
exit 1
fi
This script should enfoce a branch name of def/<username>/#<ticket>...
or project/...
.
Even if this file exists you're able to commit directly to main
without any error message.
I can NOT reproduce this issue. You said that you hooks file exists in <repo>/.githooks/pre-commit
. Can you change it to git standard path <repo>/.git/hooks/pre-commit
Or just check if git config core.hooksPath
points to your <repo>/.githooks
?
Yes - copying the hook to .get/hooks/pre-commit
works as expected.
git config core.hooksPath
points to <repo>/.githooks
- that's why git commit
and SourceTree also works.
That's strange, this project never changes the core.hooksPath
……
I have moved the pre-commit
to <repo>/.githooks
and manually run git config core.hooksPath <repo>/.githooks
. But it works fine on my PC:
Yes - copying the hook to .get/hooks/pre-commit works as expected. git config core.hooksPath points to
/.githooks - that's why git commit and SourceTree also works.
If it works fine with hooks under .git/hooks/
, it means that the git process did not repect the value of core.hooksPath
Interesting - creating a new repo, setting the path to .githooks
also works as expected.
😂
You can try these two commands under the repo that has these issue:
git config --unset core.hooksPath
reset the repo's local setting of core.hooksPath to defaultgit config core.hooksPath <repo>/.githooks
Mea culpa.
Thank you very much - unset
and re-configure did the job.
We use hooks, for example, to ensure branch names and to comply with some code guidelines. Unfortunately, SourceGit does not consider these.
It looks as if the
--no-verify
option is active by default. But this cannot be configured.The hooks should be considered or an option should be added to control the behavior.