#!/bin/sh # You should execute this script in the repository where you # want to convert grafts to replace refs. global GRAFTS_FILE := ""$(GIT_DIR:-.git)/info/grafts"" source $(git --exec-path)/git-sh-setup test -f $GRAFTS_FILE || die "Could not find graft file: '$GRAFTS_FILE'" grep '^[^# ]' $GRAFTS_FILE | while read definition { if test -n $definition { echo "Converting: $definition" git replace --graft $definition || die "Conversion failed for: $definition" } } mv $GRAFTS_FILE "$GRAFTS_FILE.bak" || die "Could not rename '$GRAFTS_FILE' to '$GRAFTS_FILE.bak'" echo "Success!" echo "All the grafts in '$GRAFTS_FILE' have been converted to replace refs!" echo "The grafts file '$GRAFTS_FILE' has been renamed: '$GRAFTS_FILE.bak'" (CommandList children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:GRAFTS_FILE) op: Equal rhs: { (DQ (BracedVarSub token: suffix_op: (StringUnary op_id:VTest_ColonHyphen arg_word:{(.git)}) spids: [13 17] ) (/info/grafts) ) } spids: [11] ) ] spids: [11] ) (C {(.)} { (CommandSubPart command_list: (CommandList children:[(C {(git)} {(--exec-path)})]) left_token: spids: [24 28] ) (/git-sh-setup) } ) (AndOr children: [ (C {(test)} {(-f)} {(DQ ($ VSub_Name "$GRAFTS_FILE"))}) (C {(die)} {(DQ ("Could not find graft file: '") ($ VSub_Name "$GRAFTS_FILE") ("'"))}) ] op_id: Op_DPipe ) (Pipeline children: [ (C {(grep)} {(SQ <"^[^# ]">)} {(DQ ($ VSub_Name "$GRAFTS_FILE"))}) (While cond: [(C {(read)} {(definition)})] body: (DoGroup children: [ (If arms: [ (if_arm cond: [(C {(test)} {(-n)} {(DQ ($ VSub_Name "$definition"))})] action: [ (C {(echo)} {(DQ ("Converting: ") ($ VSub_Name "$definition"))}) (AndOr children: [ (C {(git)} {(replace)} {(--graft)} {($ VSub_Name "$definition")}) (C {(die)} {(DQ ("Conversion failed for: ") ($ VSub_Name "$definition"))}) ] op_id: Op_DPipe ) ] spids: [-1 83] ) ] spids: [-1 113] ) ] spids: [69 115] ) ) ] negated: False ) (AndOr children: [ (C {(mv)} {(DQ ($ VSub_Name "$GRAFTS_FILE"))} {(DQ ($ VSub_Name "$GRAFTS_FILE") (.bak))}) (C {(die)} { (DQ ("Could not rename '") ($ VSub_Name "$GRAFTS_FILE") ("' to '") ($ VSub_Name "$GRAFTS_FILE") (".bak'") ) } ) ] op_id: Op_DPipe ) (C {(echo)} {(DQ ("Success!"))}) (C {(echo)} { (DQ ("All the grafts in '") ($ VSub_Name "$GRAFTS_FILE") ("' have been converted to replace refs!") ) } ) (C {(echo)} { (DQ ("The grafts file '") ($ VSub_Name "$GRAFTS_FILE") ("' has been renamed: '") ($ VSub_Name "$GRAFTS_FILE") (".bak'") ) } ) ] )