When I set the depth low (1-3) in the "getTransfersToApprove" function, I will often times get the same hash in trunk & branch transactions, they are supposed to be different. Why? The "attachToTangle" function will still run if I input identical transaction hashes for trunk and bundle, as seen here.
Strictly speaking : branch and trunk transaction can be the same. Let's think about transaction validating the genesis: there was only only one transaction on the tangle... so impossible to pick 2 distinct tips. (same reflection is also valid for a tangle with very low load: in this situation, there is almost always no more than one single tip on the tangle... so impossible to pick two distincts)
Tip selection is more or less random, and it is possible that the random-tip-selection-algorithm select twice the same tip.
That being said, on a healthy/honest node the probability for this to occurs is very low. The linked transaction is more probably kind of attempt to arm the network, or it has been issued on a node that didn't receive any (resp. didn't listen for) new tips from neighbors for a long time.