-
Notifications
You must be signed in to change notification settings - Fork 7
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
git checkout without arguments from branch saves branch dump as master #6
Comments
@cgunther Nice catch. This is definitely a bug. I don't think This is severe enough that I think if [ "$3" = "1" ] && [ $1 != $2 ]
then
# branchbot...
fi That will only run |
In both of your examples, I agree because you're not actually changing branches, however I don't think that's the extent of possibilities for both heads matching. Imagine this scenario, starting on
The heads match, so we can assert no code changed, however we can't guarantee no data changed. In a perfect world, we'd almost need a "head" reference from the database. Certainly an obscure case, but theoretically possible. Maybe this is a scenario we prompt for what to do, assuming prompting is possible within a hook? |
Ah great point. Firstly, we need to identify what went wrong in your initial example, because we do have some safeguards around dumping/restoring when the source/destination branches are the same. I'm guessing that your If that's accurate, the problem is that # on master
$ git checkout -b foo
# dumps to master
$ git checkout -b bar
# dumps to foo and master
$ git checkout foo
# dumps to master and bar, restores foo The problem there is that This behavior is probably also not desired/wrong. What we really want to do is always dump to the source branch name. Not all branches that have the same HEAD as the source ref. I don't know how we get there, but assuming all of the above is accurate, and that is in fact the issue you ran into - we really should find a way to identify the source branch name. Otherwise, we should prompt the user as you said (e.g. "Which branch did you just come from? [list out branches with HEADs matching the source ref]) |
Yup, check out a new branch If you don't mind depending on git output,
On old capistrano deploys, we used to grab the branch name for staging like: `git branch` =~ /\* (\S+)\s/m
puts $1
=> "bar" We conditionally set it as the deploy branch as I'd guess it may not mark a branch if you're in detached head mode, where you have an individual commit checked out (or maybe a tag too, or maybe even in the midst of an interactive rebase). |
Yeah there's a few good ways to find the current branch, and I think our current code is reliable in doing that. However, it's more difficult to find the name of the branch the user is coming from. The We really need something like a Another option might be to completely change how Barring another option that I'm just not aware of, I think our only remaining option is to ask the user to select the appropriate branch when the source branch is ambiguous. Assuming we can prompt mid-git-hook. |
Ah, right, it's This was a once-in-seven-years issue, so certainly no urgency, just wanted to document it while it was fresh. |
Exactly. Not an easy problem to solve unfortunately, but definitely worth solving. I actually run into this all the time and I see branchbot dumping the database multiple times because the source ref is the HEAD for multiple branches. But it hasn't (yet) caused a major issue for me. But it certainly could. I'm also never overly concerned because TimeMachine takes frequent backups of my branch backups, so I can always restore them if needed (and have done that on multiple occasions). But not everyone has that safety net. Let's leave this open as a bug (which I think is accurate), and we'll likely tackle as a prompt if that's possible from a hook. |
I just hit this, didn't get a chance to dig in, but documenting it a bit for future self.
If you're on branch
foo
and rungit checkout
(no arguments, meant to rungit checkout .
to discard changes in my working directory), git leaves you on branchfoo
, but the hooks seem to cause branchbot to dump the state of the current database (branch) asmaster
, which effectively just blew away yourmaster
dump, replacing it with your feature dump.I'll have to come back and test this a bit more to confirm, but assuming that's reproducible, I'd be curious if we can catch this and do something better, either not dumping at all (you're not really changing branches), or at least not dumping to
master
.Edit: Should also note the feature branch didn't have any commits yet, so it's head commit would have matched
master
at that point. Perhaps if there had been a commit already, that deviation in head commit would have caused it to dump the feature DB named after the feature, rather than aftermaster
.The text was updated successfully, but these errors were encountered: