(a) If the action is by an employee of the contractor, or by any person who has furnished to him material for the building or improvement, the contractor shall be a necessary party defendant thereto; and in such action on motion of the plaintiff, the owner or proprietor may be cited to answer under oath how much was owing by him to the contractor on his contract with such contractor, at the time of the service on him of the notice required by Section 35-11-218; and such answer may be controverted, and proceedings had and judgment entered as in garnishment cases.
(b) When the lien is sought to be enforced by any person other than the contractor, it shall be the duty of the contractor to defend the action at his own expense; and after notice of an intention to file a statement of the lien, and pending the action, the owner or proprietor may withhold from the contractor money sufficient to cover the amount claimed, and the probable costs and expense of the action; and in case of recovery against the owner or proprietor, or his property, he shall be entitled to deduct from the amount owing by him to the contractor the amount of such judgment, costs, and expense; and if he shall have settled with the contractor, he shall be entitled to recover from the contractor the amount recovered of, and paid by him; and such recovery may be had in the same court, on motion, on three days' notice.