An earth-destroying asteroid is the more realistic form of this. We could get anywhere from days to years of notice it was going to hit (if years, it would just be a probable hit) and have to put together our Armageddon/Deep Impact mission to divert it. There are plenty of papers published on what we could do and the idea has had millions of dollars in funding, but it would need billions. We're screwed if the notice period is days, but we'd have a good chance to build something in months.