Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix forced branch creation on HEAD of a bare repo. #3977

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

Closed

Conversation

jfultz
Copy link
Contributor

@jfultz jfultz commented Oct 28, 2016

The code correctly detects that forced creation of a branch on a
nonbare repo should not be able to overwrite a branch which is
the HEAD reference. But there's no reason to prevent this on
a bare repo, and in fact, git allows this. I.e.,

git branch -f master new_sha

works on a bare repo with HEAD set to master. This change fixes
that problem, and updates tests so that, for this case, both the
bare and nonbare cases are checked for correct behavior.

@jfultz jfultz force-pushed the fix-forced-branch-creation-on-bare-repo branch from 104359c to c7ac7a2 Compare October 28, 2016 21:51
The code correctly detects that forced creation of a branch on a
nonbare repo should not be able to overwrite a branch which is
the HEAD reference.  But there's no reason to prevent this on
a bare repo, and in fact, git allows this.  I.e.,

   git branch -f master new_sha

works on a bare repo with HEAD set to master.  This change fixes
that problem, and updates tests so that, for this case, both the
bare and nonbare cases are checked for correct behavior.
@jfultz jfultz force-pushed the fix-forced-branch-creation-on-bare-repo branch from c7ac7a2 to bc7c633 Compare October 28, 2016 21:52
Copy link
Member

@pks-t pks-t left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good besides the memory leak. Thanks for working on this 👍

oid = git_commit_id(target);

cl_git_pass(git_branch_create(&branch, repo, "master", target, 1));
branch = NULL;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This leaks memory as you do not free branch here and overwrite it afterwards.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copied and pasted the code from the legacy test case, but in the legacy test case it should fail, so there's nothing to clean up. Oops. :P

@pks-t
Copy link
Member

pks-t commented Nov 2, 2016

Looks good. Will wait for comments and merge later this week if nothing comes up. Thanks 🎉

pks-t added a commit that referenced this pull request Nov 4, 2016
@pks-t
Copy link
Member

pks-t commented Nov 4, 2016

Manually squashed in the fixup and merged via 6e2fab9. Thanks for your work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants