@@ -291,71 +291,6 @@ static int merge_working_tree(struct checkout_opts *opts,
291291 return 0 ;
292292}
293293
294- /*
295- * We really should allow cb_data... Yuck
296- */
297- static const char * branch_name ;
298- static int branch_name_len ;
299- static char * found_remote ;
300- static char * found_merge ;
301- static int read_branch_config (const char * var , const char * value )
302- {
303- const char * name ;
304- if (prefixcmp (var , "branch." ))
305- return 0 ; /* not ours */
306- name = var + strlen ("branch." );
307- if (strncmp (name , branch_name , branch_name_len ) ||
308- name [branch_name_len ] != '.' )
309- return 0 ; /* not ours either */
310- if (!strcmp (name + branch_name_len , ".remote" )) {
311- /*
312- * Yeah, I know Christian's clean-up should
313- * be used here, but the topic is based on an
314- * older fork point.
315- */
316- if (!value )
317- return error ("'%s' not string" , var );
318- found_remote = xstrdup (value );
319- return 0 ;
320- }
321- if (!strcmp (name + branch_name_len , ".merge" )) {
322- if (!value )
323- return error ("'%s' not string" , var );
324- found_merge = xstrdup (value );
325- return 0 ;
326- }
327- return 0 ; /* not ours */
328- }
329-
330- static int find_build_base (const char * ours , char * * base )
331- {
332- struct remote * remote ;
333- struct refspec spec ;
334-
335- * base = NULL ;
336-
337- branch_name = ours + strlen ("refs/heads/" );
338- branch_name_len = strlen (branch_name );
339- found_remote = NULL ;
340- found_merge = NULL ;
341- git_config (read_branch_config );
342-
343- if (!found_remote || !found_merge ) {
344- cleanup :
345- free (found_remote );
346- free (found_merge );
347- return 0 ;
348- }
349-
350- remote = remote_get (found_remote );
351- memset (& spec , 0 , sizeof (spec ));
352- spec .src = found_merge ;
353- if (remote_find_tracking (remote , & spec ))
354- goto cleanup ;
355- * base = spec .dst ;
356- return 1 ;
357- }
358-
359294static void adjust_to_tracking (struct branch_info * new , struct checkout_opts * opts )
360295{
361296 /*
@@ -369,15 +304,16 @@ static void adjust_to_tracking(struct branch_info *new, struct checkout_opts *op
369304 const char * msgfmt ;
370305 char symmetric [84 ];
371306 int show_log ;
307+ struct branch * branch = branch_get (NULL );
372308
373- if (!resolve_ref ( new -> path , sha1 , 1 , NULL ) )
309+ if (!branch || ! branch -> merge )
374310 return ;
375- ours = lookup_commit (sha1 );
376311
377- if (!find_build_base (new -> path , & base ))
378- return ;
312+ base = branch -> merge [0 ]-> dst ;
313+
314+ ours = new -> commit ;
379315
380- sprintf (symmetric , "%s" , sha1_to_hex (sha1 ));
316+ sprintf (symmetric , "%s" , sha1_to_hex (ours -> object . sha1 ));
381317
382318 /*
383319 * Ok, it is tracking base; is it ahead of us?
@@ -466,7 +402,7 @@ static void update_refs_for_switch(struct checkout_opts *opts,
466402 }
467403 remove_branch_state ();
468404 strbuf_release (& msg );
469- if (new -> path )
405+ if (new -> path || ! strcmp ( new -> name , "HEAD" ) )
470406 adjust_to_tracking (new , opts );
471407}
472408
0 commit comments