The original melody was composed by James Mauchline in 1843 and arranged (Mauchline will even say improved) by Pipe Major Alexander MacKellar.
Both were members of the 78th Highlanders.
Lyrics were added later, sung in particular by Andy Stewart.
NB: I have made a slight rhythmic change to the score proposed in the "Scots Guards" in the 3rd bar of the second part by removing the dotted eighth note and the double eighth note attached to prefer two simple eighth notes that seem to me more in accordance with the writing of the melody (cf. 3rd measure part-1).
I remain of course willing to restore the rhythm of the Scots Guards if it is attested as in accordance with the initial intention of the two composers.