The Messenger of Allah ﷺ said, "Whoever takes an oath and says, 'If Allah wills,' has not broken his oath."
حدثنا محمود بن غيلان حدثنا عبد الصمد بن عبد الوارث حدثني أبي وحماد بن سلمة عن أيوب عن نافع
أن رسول الله ﷺ قال من حلف على يمين فقال إن شاء الله فلا حنث عليه
[Its chain of transmission is sahih]. Nasai also narrated it, 12/7, 13, no. 3824 (Oaths and Vows, chapter on swearing an oath and then making an exception), from the hadith of Abdul-Warith. Abu Dawud, no. 3261, 3262, Ibn Majah, no. 2105, and Nasai, no. 3860, narrated it from the hadith of Ayub Sakhtiyani through the same chain, and Ibn Hibban graded it sahih. There is also a narration on this subject from Abu Hurairah [coming up, no. 1532].