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.
@@ -756,10 +770,12 @@ int cmd_update_ref(int argc,
756770 int delete = 0 , no_deref = 0 , read_stdin = 0 , end_null = 0 ;
757771 int create_reflog = 0 ;
758772 unsigned int flags = 0 ;
773+ int rename = 0 ;
759774
760775 struct option options [] = {
761776 OPT_STRING ( 'm' , NULL , & msg , N_ ("reason" ), N_ ("reason of the update" )),
762777 OPT_BOOL ('d' , NULL , & delete , N_ ("delete the reference" )),
778+ OPT_BOOL ( 0 , "rename" , & rename , N_ ("rename the reference" )),
763779 OPT_BOOL ( 0 , "no-deref" , & no_deref ,
764780 N_ ("update <refname> not the one it points to" )),
765781 OPT_BOOL ('z' , NULL , & end_null , N_ ("stdin has NUL-terminated arguments" )),
@@ -784,7 +800,7 @@ int cmd_update_ref(int argc,
784800 }
785801
786802 if (read_stdin ) {
787- if (delete || argc > 0 )
803+ if (delete || rename || argc > 0 )
788804 usage_with_options (git_update_ref_usage , options );
789805 if (end_null )
790806 line_termination = '\0' ;
@@ -797,6 +813,12 @@ int cmd_update_ref(int argc,
797813 if (end_null )
798814 usage_with_options (git_update_ref_usage , options );
799815
816+ if (rename ) {
817+ if (delete || argc < 2 || argc > 2 )
818+ usage_with_options (git_update_ref_usage , options );
819+ return do_rename_ref (argv [0 ], argv [1 ]);
820+ }
821+
800822 if (delete ) {
801823 if (argc < 1 || argc > 2 )
802824 usage_with_options (git_update_ref_usage , options );
0 commit comments