Mountainous countries remain an absolute nightmare to invade. It is no coincidence that Switzerland managed to remain neutral in the face of far larger powers and that Afghanistan is known as the Graveyard of Empires.
… in a foreign occupied country. Aside from snide remarks is anybody honestly trying to propose that civilians with guns is a deterrent for for anything the government wants to do? You may as well be throwing rocks.
In some cases, it probably is a deterrent. It is hard to know for sure because there is no way to A/B test a country. I think that some people probably overestimate the degree to which it is a deterrent, but I think it would certainly be wrong to say that it is not a deterrent at all. In some situations it can probably be a very effective deterrent.
The hypothesis that guns are a deterrent has little to do with the citizenry fighting against the army or the police. It is about the risk of political assassination by a rogue individual every time a politician walks outside. If the leaders start to deviate significantly from the will of the median person, that risk goes up by a lot, hence the deterrent effect. Would Kim Jong Un still be around if every person was armed? Perhaps, but it'd be quite a bit less likely.