@matheusbsbs / matheus-bagliano / commits / ec39d83a55
Fork 0

git-gui: Don't let the user pull into an uncommitted working directory.

If there are modified files present in the working directory then we should not let the user perform a pull as it may fail due to the modified files being uncommitted but needing to be merged at the file level. Yes there are many cases where a merge will complete successfully even though there are modified or untracked files sitting in the working directory. But users generally shouldn't be attempting merges like that, and if they are they probably are advanced enough to just use the command line and bypass this little safety check. We also no longer run a rescan after a successful pull has completed. Usually this is unnecessary as a successful pull won't leave modified files laying around. Instead we just update our HEAD and PARENT values with the new commit, if there is one. Unfortunately this does let the user get into an insane state as there are bugs in core Git's git-pull and git-merge programs where the exit status is sent back as a 0 rather than non-0 when a failure is detected. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Shawn O. Pearce committed Nov 7, 2006 at 22:00 UTC ec39d83a55124660d03a744e0e7f67072a833950
1 file changed +39 -1
git-gui
+39 -1
@@ -642,7 +642,40 @@ proc fetch_from {remote} {
642 }
643
644 proc pull_remote {remote branch} {
645 + global HEAD commit_type
646 + global file_states
647 +
648 if {![lock_index update]} return
649 +
650 + # -- Our in memory state should match the repository.
651 + #
652 + repository_state curHEAD cur_type
653 + if {$commit_type != $cur_type || $HEAD != $curHEAD} {
654 + error_popup {Last scanned state does not match repository state.
655 +
656 +Its highly likely that another Git program modified the
657 +repository since our last scan. A rescan is required
658 +before a pull can be started.
659 +}
660 + unlock_index
661 + update_status
662 + return
663 + }
664 +
665 + # -- No differences should exist before a pull.
666 + #
667 + if {[array size file_states] != 0} {
668 + error_popup {Uncommitted but modified files are present.
669 +
670 +You should not perform a pull with unmodified files in your working
671 +directory as Git would be unable to recover from an incorrect merge.
672 +
673 +Commit or throw away all changes before starting a pull operation.
674 +}
675 + unlock_index
676 + return
677 + }
678 +
679 set w [new_console "pull $remote $branch" \
680 "Pulling new changes from branch $branch in $remote"]
681 set cmd [list git pull]
@@ -652,9 +685,14 @@ proc pull_remote {remote branch} {
685 }
686
687 proc post_pull_remote {remote branch success} {
688 + global HEAD PARENT commit_type
689 + global ui_status_value
690 +
691 unlock_index
692 if {$success} {
657 - update_status "Successfully pulled $branch from $remote."
693 + repository_state HEAD commit_type
694 + set PARENT $HEAD
695 + set $ui_status_value {Ready.}
696 } else {
697 update_status "Conflicts detected while pulling $branch from $remote."
698 }