1515static const char * const git_update_ref_usage [] = {
1616 N_ ("git update-ref [<options>] -d <refname> [<old-oid>]" ),
1717 N_ ("git update-ref [<options>] <refname> <new-oid> [<old-oid>]" ),
18+ N_ ("git update-ref [<options>] --rename <refname> <refname>" ),
1819 N_ ("git update-ref [<options>] --stdin [-z] [--batch-updates]" ),
1920 NULL
2021};
@@ -25,6 +26,19 @@ static unsigned int default_flags;
2526static unsigned create_reflog_flag ;
2627static const char * msg ;
2728
29+ static int do_rename_ref (const char * from , const char * to )
30+ {
31+ struct strbuf msg = STRBUF_INIT ;
32+ int ret ;
33+
34+ strbuf_addf (& msg , "update-ref: renamed %s to %s" , from , to );
35+ ret = refs_rename_ref (get_main_ref_store (the_repository ),
36+ from , to , msg .buf );
37+ strbuf_release (& msg );
38+
39+ return !!ret ;
40+ }
41+
2842/*
2943 * Parse one whitespace- or NUL-terminated, possibly C-quoted argument
3044 * and append the result to arg. Return a pointer to the terminator.
@@ -759,10 +773,12 @@ int cmd_update_ref(int argc,
759773 int delete = 0 , no_deref = 0 , read_stdin = 0 , end_null = 0 ;
760774 int create_reflog = 0 ;
761775 unsigned int flags = 0 ;
776+ int rename = 0 ;
762777
763778 struct option options [] = {
764779 OPT_STRING ( 'm' , NULL , & msg , N_ ("reason" ), N_ ("reason of the update" )),
765780 OPT_BOOL ('d' , NULL , & delete , N_ ("delete the reference" )),
781+ OPT_BOOL ( 0 , "rename" , & rename , N_ ("rename the reference" )),
766782 OPT_BOOL ( 0 , "no-deref" , & no_deref ,
767783 N_ ("update <refname> not the one it points to" )),
768784 OPT_BOOL ('z' , NULL , & end_null , N_ ("stdin has NUL-terminated arguments" )),
@@ -787,7 +803,7 @@ int cmd_update_ref(int argc,
787803 }
788804
789805 if (read_stdin ) {
790- if (delete || argc > 0 )
806+ if (delete || rename || argc > 0 )
791807 usage_with_options (git_update_ref_usage , options );
792808 if (end_null )
793809 line_termination = '\0' ;
@@ -800,6 +816,12 @@ int cmd_update_ref(int argc,
800816 if (end_null )
801817 usage_with_options (git_update_ref_usage , options );
802818
819+ if (rename ) {
820+ if (delete || argc < 2 || argc > 2 )
821+ usage_with_options (git_update_ref_usage , options );
822+ return do_rename_ref (argv [0 ], argv [1 ]);
823+ }
824+
803825 if (delete ) {
804826 if (argc < 1 || argc > 2 )
805827 usage_with_options (git_update_ref_usage , options );
0 commit comments