@@ -22,7 +22,6 @@ def __init__(self, remote: str = None, branch: str = None):
2222 self .remote = remote
2323 self .branch = branch
2424 settings .max_branches_per_commit = 2
25- settings .color_by = "notlocal"
2625
2726 if self .remote and self .remote not in self .repo .remotes :
2827 print ("git-sim error: no remote with name '" + self .remote + "'" )
@@ -68,19 +67,30 @@ def construct(self):
6867
6968 # Push the local clone into the local clone of the remote repo
7069 push_result = 0
70+ self .orig_repo = None
7171 try :
7272 self .repo .git .push (self .remote , self .branch )
7373 # If push fails...
7474 except git .GitCommandError as e :
75- if "rejected" in e .stderr and "fetch first" in e .stderr :
75+ if "rejected" in e .stderr and ( "fetch first" in e .stderr ) :
7676 push_result = 1
7777 self .orig_repo = self .repo
7878 self .repo = self .remote_repo
79+ settings .color_by = "notlocal1"
80+ elif "rejected" in e .stderr and ("non-fast-forward" in e .stderr ):
81+ push_result = 2
82+ self .orig_repo = self .repo
83+ self .repo = self .remote_repo
84+ settings .color_by = "notlocal2"
7985 else :
8086 print (f"git-sim error: git push failed: { e .stderr } " )
87+ return
8188
8289 head_commit = self .get_commit ()
83- self .parse_commits (head_commit , make_branches_remote = (self .remote if self .remote else self .repo .remotes [0 ].name ))
90+ if push_result > 0 :
91+ self .parse_commits (head_commit , make_branches_remote = (self .remote if self .remote else self .repo .remotes [0 ].name ))
92+ else :
93+ self .parse_commits (head_commit )
8494 self .recenter_frame ()
8595 self .scale_frame ()
8696 self .failed_push (push_result )
@@ -134,17 +144,53 @@ def failed_push(self, push_result):
134144 weight = m .BOLD ,
135145 )
136146 text4 .move_to (text3 .get_center ()).shift (m .DOWN / 2 )
147+ texts = [text1 , text2 , text3 , text4 ]
137148
138- self .toFadeOut .add (text1 )
139- self .toFadeOut .add (text2 )
140- self .toFadeOut .add (text3 )
141- self .toFadeOut .add (text4 )
142- self .recenter_frame ()
143- self .scale_frame ()
144- if settings .animate :
145- self .play (m .AddTextLetterByLetter (text2 ), m .AddTextLetterByLetter (text2 ), m .AddTextLetterByLetter (text3 ), m .AddTextLetterByLetter (text4 ))
146- else :
147- self .add (text1 , text2 , text3 , text4 )
149+ elif push_result == 2 :
150+ text1 = m .Text (
151+ f"'git push' failed since the tip of your current branch is behind the remote." ,
152+ font = "Monospace" ,
153+ font_size = 20 ,
154+ color = self .fontColor ,
155+ weight = m .BOLD ,
156+ )
157+ text1 .move_to ([self .camera .frame .get_center ()[0 ], 5 , 0 ])
158+
159+ text2 = m .Text (
160+ f"Run 'git pull' (or 'git-sim pull' to simulate first) and then try again." ,
161+ font = "Monospace" ,
162+ font_size = 20 ,
163+ color = self .fontColor ,
164+ weight = m .BOLD ,
165+ )
166+ text2 .move_to (text1 .get_center ()).shift (m .DOWN / 2 )
167+
168+ text3 = m .Text (
169+ f"Gold commits exist are ahead of your current branch tip (need to be pulled)." ,
170+ font = "Monospace" ,
171+ font_size = 20 ,
172+ color = m .GOLD ,
173+ weight = m .BOLD ,
174+ )
175+ text3 .move_to (text2 .get_center ()).shift (m .DOWN / 2 )
176+
177+ text4 = m .Text (
178+ f"Red commits are up to date in both local and remote branches." ,
179+ font = "Monospace" ,
180+ font_size = 20 ,
181+ color = m .RED ,
182+ weight = m .BOLD ,
183+ )
184+ text4 .move_to (text3 .get_center ()).shift (m .DOWN / 2 )
185+ texts = [text1 , text2 , text3 , text4 ]
186+
187+ self .toFadeOut .add (* texts )
188+ self .recenter_frame ()
189+ self .scale_frame ()
190+ if settings .animate :
191+ self .play (* [m .AddTextLetterByLetter (t ) for t in texts ])
192+ else :
193+ self .add (* texts )
148194
149195
150196
0 commit comments