# This shell scriplet is meant to be included by other shell scripts # to set up some variables pointing at the normal git directories and # a few helper shell functions. # Source git-sh-i18n for gettext support. source git-sh-i18n # Having this variable in your environment would break scripts because # you would cause "cd" to be taken to unexpected places. If you # like CDPATH, define it for your interactive shell sessions without # exporting it. # But we protect ourselves from such a user mistake nevertheless. unset CDPATH # Similarly for IFS, but some shells (e.g. FreeBSD 7.2) are buggy and # do not equate an unset IFS with IFS with the default, so here is # an explicit SP HT LF. global IFS := '' '' proc git_broken_path_fix { matchstr ":$PATH:" { *:$1:* { : ok } * { global PATH := $[ global SANE_TOOL_PATH := $1 global IFS := ':', path := '', sep := '' set x $PATH shiftfor elem in @Argv { matchstr "$SANE_TOOL_PATH:$elem" { (?*:/bin | ?*:/usr/bin { global path := ""$path$sep$SANE_TOOL_PATH"" global sep := ':' global SANE_TOOL_PATH := '' } } global path := ""$path$sep$elem"" global sep := ':' } echo $path] } } } # @@BROKEN_PATH_FIX@@ proc die { die_with_status 1 @Argv } proc die_with_status { global status := $1 shift printf >&2 '%s\n' "$ifsjoin(Argv)> !2 '%s\n' "$*" exit $status } global GIT_QUIET := '' proc say { if test -z $GIT_QUIET { printf '%s\n' "$ifsjoin(Argv)" } } if test -n $OPTIONS_SPEC { proc usage { $0 -h exit 1 } global parseopt_extra := '' test -n $OPTIONS_KEEPDASHDASH && global parseopt_extra := '"--keep-dashdash'" test -n $OPTIONS_STUCKLONG && global parseopt_extra := ""$parseopt_extra --stuck-long"" eval $[ echo $OPTIONS_SPEC | git rev-parse --parseopt $parseopt_extra -- @Argv || echo exit $Status] } else { global dashless := $[basename -- $0 | sed -e 's/-/ /] proc usage { die $[eval_gettext "usage: \$dashless \$USAGE] } if test -z $LONG_USAGE { global LONG_USAGE := $[eval_gettext "usage: \$dashless \$USAGE] } else { global LONG_USAGE := $[eval_gettext "usage: \$dashless \$USAGE $LONG_USAGE] } matchstr $1 { -h { echo $LONG_USAGE exit } } } # Set the name of the end-user facing command in the reflog when the # script may update refs. When GIT_REFLOG_ACTION is already set, this # will not overwrite it, so that a scripted Porcelain (e.g. "git # rebase") can set it to its own name (e.g. "rebase") and then call # another scripted Porcelain (e.g. "git am") and a call to this # function in the latter will keep the name of the end-user facing # program (e.g. "rebase") in GIT_REFLOG_ACTION, ensuring whatever it # does will be record as actions done as part of the end-user facing # operation (e.g. "rebase"). # # NOTE NOTE NOTE: consequently, after assigning a specific message to # GIT_REFLOG_ACTION when calling a "git" command to record a custom # reflog message, do not leave that custom value in GIT_REFLOG_ACTION, # after you are done. Other callers of "git" commands that rely on # writing the default "program name" in reflog expect the variable to # contain the value set by this function. # # To use a custom reflog message, do either one of these three: # # (a) use a single-shot export form: # GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION: preparing frotz" \ # git command-that-updates-a-ref # # (b) save the original away and restore: # SAVED_ACTION=$GIT_REFLOG_ACTION # GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION: preparing frotz" # git command-that-updates-a-ref # GIT_REFLOG_ACITON=$SAVED_ACTION # # (c) assign the variable in a subshell: # ( # GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION: preparing frotz" # git command-that-updates-a-ref # ) proc set_reflog_action { if test -z $(GIT_REFLOG_ACTION:+set) { global GIT_REFLOG_ACTION := "$ifsjoin(Argv)" export GIT_REFLOG_ACTION } } proc git_editor { if test -z $(GIT_EDITOR:+set) { global GIT_EDITOR := $[git var GIT_EDITOR] || return $? } eval $GIT_EDITOR '"$@"' } proc git_pager { if test -t 1 { global GIT_PAGER := $[git var GIT_PAGER] } else { global GIT_PAGER := 'cat' } for vardef in [@@PAGER_ENV@@] { global var := $(vardef%%=*) eval ": \"\${$vardef}\" && export $var" } eval $GIT_PAGER '"$@"' } proc sane_grep { env GREP_OPTIONS= LC_ALL=C grep @@SANE_TEXT_GREP@@ @Argv } proc sane_egrep { env GREP_OPTIONS= LC_ALL=C egrep @@SANE_TEXT_GREP@@ @Argv } proc is_bare_repository { git rev-parse --is-bare-repository } proc cd_to_toplevel { global cdup := $[git rev-parse --show-toplevel] && cd $cdup || do { gettextln "Cannot chdir to \$cdup, the toplevel of the working tree" > !2 exit 1 } } proc require_work_tree_exists { if test "z$[git rev-parse --is-bare-repository]" != zfalse { global program_name := $0 die $[gettext "fatal: \$program_name cannot be used without a working tree.] } } proc require_work_tree { test $[git rev-parse --is-inside-work-tree !2 >/dev/null] = true || do { global program_name := $0 die $[gettext "fatal: \$program_name cannot be used without a working tree.] } } proc require_clean_work_tree { git rev-parse --verify HEAD >/dev/null || exit 1 git update-index -q --ignore-submodules --refresh global err := '0' if ! git diff-files --quiet --ignore-submodules { global action := $1 matchstr $action { rebase { gettextln "Cannot rebase: You have unstaged changes." > !2 } "rewrite branches" { gettextln "Cannot rewrite branches: You have unstaged changes." > !2 } "pull with rebase" { gettextln "Cannot pull with rebase: You have unstaged changes." > !2 } * { eval_gettextln "Cannot \$action: You have unstaged changes." > !2 } } global err := '1' } if ! git diff-index --cached --quiet --ignore-submodules HEAD -- { if test $err = 0 { global action := $1 matchstr $action { rebase { gettextln "Cannot rebase: Your index contains uncommitted changes." > !2 } "pull with rebase" { gettextln "Cannot pull with rebase: Your index contains uncommitted changes." > !2 } * { eval_gettextln "Cannot \$action: Your index contains uncommitted changes." > !2 } } } else { gettextln "Additionally, your index contains uncommitted changes." > !2 } global err := '1' } if test $err = 1 { test -n $2 && echo $2 > !2 exit 1 } } # Generate a sed script to parse identities from a commit. # # Reads the commit from stdin, which should be in raw format (e.g., from # cat-file or "--pretty=raw"). # # The first argument specifies the ident line to parse (e.g., "author"), and # the second specifies the environment variable to put it in (e.g., "AUTHOR" # for "GIT_AUTHOR_*"). Multiple pairs can be given to parse author and # committer. proc pick_ident_script { while test $# -gt 0 { global lid := $1; shift global uid := $1; shift printf '%s' " /^$lid /{ s/'/'\\\\''/g h s/^$lid "'\([^<]*\) <[^>]*> .*$/\1/'" s/.*/GIT_$(uid)_NAME='&'/p g s/^$lid "'[^<]* <\([^>]*\)> .*$/\1/'" s/.*/GIT_$(uid)_EMAIL='&'/p g s/^$lid "'[^<]* <[^>]*> \(.*\)$/@\1/'" s/.*/GIT_$(uid)_DATE='&'/p } " } echo '/^$/q' } # Create a pick-script as above and feed it to sed. Stdout is suitable for # feeding to eval. proc parse_ident_from_commit { env LANG=C LC_ALL=C sed -ne $[pick_ident_script @Argv] } # Parse the author from a commit given as an argument. Stdout is suitable for # feeding to eval to set the usual GIT_* ident variables. proc get_author_ident_from_commit { global encoding := $[git config i18n.commitencoding || echo UTF-8] git show -s --pretty=raw --encoding="$encoding" $1 -- | parse_ident_from_commit author AUTHOR } # Clear repo-local GIT_* environment variables. Useful when switching to # another repository (e.g. when entering a submodule). See also the env # list in git_connect() proc clear_local_git_env { unset $[git rev-parse --local-env-vars] } # Generate a virtual base file for a two-file merge. Uses git apply to # remove lines from $1 that are not in $2, leaving only common lines. proc create_virtual_base { global sz0 := $[wc -c <$1] @@DIFF@@ -u -La/"$1" -Lb/"$1" $1 $2 | git apply --no-add global sz1 := $[wc -c <$1] # If we do not have enough common material, it is not # worth trying two-file merge using common subsections. expr $sz0 '<' $sz1 '*' 2 >/dev/null || : >$1 } # Platform specific tweaks to work around some commands matchstr $[uname -s] { *MINGW* { # Windows has its own (incompatible) sort and find proc sort { /usr/bin/sort @Argv } proc find { /usr/bin/find @Argv } # git sees Windows-style pwd proc pwd { builtin pwd -W } proc is_absolute_path { matchstr $1 { [/\\]* | [A-Za-z]:* { return 0 } } return 1 } } * { proc is_absolute_path { matchstr $1 { /* { return 0 } } return 1 } } } # Make sure we are in a valid repository of a vintage we understand, # if we require to be in a git repository. proc git_dir_init { global GIT_DIR := $[git rev-parse --git-dir] || exit if test -z $SUBDIRECTORY_OK { test -z $[git rev-parse --show-cdup] || do { global exit := $Status gettextln "You need to run this command from the toplevel of the working tree." > !2 exit $exit } } test -n $GIT_DIR && global GIT_DIR := $[cd $GIT_DIR && pwd] || do { gettextln "Unable to determine absolute path of git directory" > !2 exit 1 } : $(GIT_OBJECT_DIRECTORY="$(git rev-parse --git-path objects)") } if test -z $NONGIT_OK { git_dir_init } proc peel_committish { matchstr $1 { :/* { global peeltmp := $[git rev-parse --verify $1] && git rev-parse --verify "$(peeltmp)^0" } * { git rev-parse --verify "$(1)^0" } } } (CommandList children: [ (C {(.)} {(git-sh-i18n)}) (C {(unset)} {(CDPATH)}) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:IFS) op:Equal rhs:{(SQ <" \t\n">)} spids:[47])] spids: [47] ) (FuncDef name: git_broken_path_fix body: (BraceGroup children: [ (Case to_match: {(DQ (":") ($ VSub_Name "$PATH") (":"))} arms: [ (case_arm pat_list: [ {(Lit_Other "*") (Lit_Other ":") ($ VSub_Number "$1") (Lit_Other ":") (Lit_Other "*") } ] action: [(C {(Lit_Other ":")} {(ok)})] spids: [72 77 83 -1] ) (case_arm pat_list: [{(Lit_Other "*")}] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:PATH) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:SANE_TOOL_PATH) op: Equal rhs: {(DQ ($ VSub_Number "$1"))} spids: [94] ) ] spids: [94] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:IFS) op: Equal rhs: {(Lit_Other ":")} spids: [100] ) (assign_pair lhs: (LhsName name:path) op: Equal rhs: {(SQ )} spids: [103] ) (assign_pair lhs: (LhsName name:sep) op: Equal rhs: {(SQ )} spids: [105] ) ] spids: [100] ) (C {(set)} {(x)} {($ VSub_Name "$PATH")}) (C {(shift)}) (ForEach iter_name: elem do_arg_iter: True body: (DoGroup children: [ (Case to_match: { (DQ ($ VSub_Name "$SANE_TOOL_PATH") (":") ($ VSub_Name "$elem") ) } arms: [ (case_arm pat_list: [ {(Lit_Other "?") (Lit_Other "*") (Lit_Other ":") (/bin) } {(Lit_Other "?") (Lit_Other "*") (Lit_Other ":") (/usr/bin) } ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:path) op: Equal rhs: { (DQ ($ VSub_Name "$path") ($ VSub_Name "$sep") ($ VSub_Name "$SANE_TOOL_PATH") ) } spids: [152] ) ] spids: [152] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:sep) op: Equal rhs: {(Lit_Other ":")} spids: [160] ) ] spids: [160] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:SANE_TOOL_PATH) op: Equal rhs: {(SQ )} spids: [164] ) ] spids: [164] ) ] spids: [137 149 -1 167] ) ] spids: [126 134 167] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:path) op: Equal rhs: { (DQ ($ VSub_Name "$path") ($ VSub_Name "$sep") ($ VSub_Name "$elem") ) } spids: [170] ) ] spids: [170] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:sep) op: Equal rhs: {(Lit_Other ":")} spids: [178] ) ] spids: [178] ) ] spids: [123 182] ) spids: [-1 -1] ) (C {(echo)} {(DQ ($ VSub_Name "$path"))}) ] ) left_token: spids: [91 192] ) } spids: [90] ) ] spids: [90] ) ] spids: [86 87 195 -1] ) ] spids: [61 69 198] ) ] spids: [58] ) spids: [53 57] ) (FuncDef name: die body: (BraceGroup children:[(C {(die_with_status)} {(1)} {(DQ ($ VSub_At "$@"))})] spids:[212]) spids: [207 211] ) (FuncDef name: die_with_status body: (BraceGroup children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:status) op: Equal rhs: {($ VSub_Number "$1")} spids: [234] ) ] spids: [234] ) (C {(shift)}) (SimpleCommand words: [{(printf)} {(SQ <"%s\\n">)} {(DQ ($ VSub_Star "$*"))}] redirects: [(Redir op_id:Redir_GreatAnd fd:-1 arg_word:{(2)} spids:[243])] ) (C {(exit)} {(DQ ($ VSub_Name "$status"))}) ] spids: [231] ) spids: [226 230] ) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:GIT_QUIET) op:Equal rhs:{(SQ )} spids:[264])] spids: [264] ) (FuncDef name: say body: (BraceGroup children: [ (If arms: [ (if_arm cond: [(C {(test)} {(-z)} {(DQ ($ VSub_Name "$GIT_QUIET"))})] action: [(C {(printf)} {(SQ <"%s\\n">)} {(DQ ($ VSub_Star "$*"))})] spids: [-1 286] ) ] spids: [-1 300] ) ] spids: [272] ) spids: [267 271] ) (If arms: [ (if_arm cond: [ (Sentence child: (C {(test)} {(-n)} {(DQ ($ VSub_Name "$OPTIONS_SPEC"))}) terminator: ) ] action: [ (FuncDef name: usage body: (BraceGroup children: [(C {(DQ ($ VSub_Number "$0"))} {(-h)}) (C {(exit)} {(1)})] spids: [323] ) spids: [319 322] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:parseopt_extra) op: Equal rhs: {(SQ )} spids: [342] ) ] spids: [342] ) (AndOr children: [ (C {(Lit_Other "[")} {(-n)} {(DQ ($ VSub_Name "$OPTIONS_KEEPDASHDASH"))} {(Lit_Other "]")} ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:parseopt_extra) op: Equal rhs: {(DQ (--keep-dashdash))} spids: [358] ) ] spids: [358] ) ] op_id: Op_DAmp ) (AndOr children: [ (C {(Lit_Other "[")} {(-n)} {(DQ ($ VSub_Name "$OPTIONS_STUCKLONG"))} {(Lit_Other "]")}) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:parseopt_extra) op: Equal rhs: {(DQ ($ VSub_Name "$parseopt_extra") (" --stuck-long"))} spids: [377] ) ] spids: [377] ) ] op_id: Op_DAmp ) (C {(eval)} { (DQ (CommandSubPart command_list: (CommandList children: [ (AndOr children: [ (Pipeline children: [ (C {(echo)} {(DQ ($ VSub_Name "$OPTIONS_SPEC"))}) (C {(git)} {(rev-parse)} {(--parseopt)} {($ VSub_Name "$parseopt_extra")} {(--)} {(DQ ($ VSub_At "$@"))} ) ] negated: False ) (C {(echo)} {(exit)} {($ VSub_QMark "$?")}) ] op_id: Op_DPipe ) ] ) left_token: spids: [388 424] ) ) } ) ] spids: [-1 316] ) ] else_action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:dashless) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(basename)} {(--)} {(DQ ($ VSub_Number "$0"))}) (C {(sed)} {(-e)} {(SQ <"s/-/ /">)}) ] negated: False ) ] ) left_token: spids: [431 449] ) } spids: [430] ) ] spids: [430] ) (FuncDef name: usage body: (BraceGroup children: [ (C {(die)} { (DQ (CommandSubPart command_list: (CommandList children: [ (C {(eval_gettext)} { (DQ ("usage: ") (EscapedLiteralPart token:) ("dashless ") (EscapedLiteralPart token:) (USAGE) ) } ) ] ) left_token: spids: [462 472] ) ) } ) ] spids: [456] ) spids: [452 455] ) (If arms: [ (if_arm cond: [(C {(Lit_Other "[")} {(-z)} {(DQ ($ VSub_Name "$LONG_USAGE"))} {(Lit_Other "]")})] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:LONG_USAGE) op: Equal rhs: { (DQ (CommandSubPart command_list: (CommandList children: [ (C {(eval_gettext)} { (DQ ("usage: ") (EscapedLiteralPart token: ) ("dashless ") (EscapedLiteralPart token:) (USAGE) ) } ) ] ) left_token: spids: [498 508] ) ) } spids: [496] ) ] spids: [496] ) ] spids: [-1 493] ) ] else_action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:LONG_USAGE) op: Equal rhs: { (DQ (CommandSubPart command_list: (CommandList children: [ (C {(eval_gettext)} { (DQ ("usage: ") (EscapedLiteralPart token:) ("dashless ") (EscapedLiteralPart token:) ("USAGE\n") ("\n") ($ VSub_Name "$LONG_USAGE") ) } ) ] ) left_token: spids: [517 529] ) ) } spids: [515] ) ] spids: [515] ) ] spids: [512 533] ) (Case to_match: {(DQ ($ VSub_Number "$1"))} arms: [ (case_arm pat_list: [{(-h)}] action: [(C {(echo)} {(DQ ($ VSub_Name "$LONG_USAGE"))}) (C {(exit)})] spids: [546 547 -1 560] ) ] spids: [537 543 560] ) ] spids: [427 562] ) (FuncDef name: set_reflog_action body: (BraceGroup children: [ (If arms: [ (if_arm cond: [ (C {(Lit_Other "[")} {(-z)} { (DQ (BracedVarSub token: suffix_op: (StringUnary op_id:VTest_ColonPlus arg_word:{(set)}) spids: [681 685] ) ) } {(Lit_Other "]")} ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:GIT_REFLOG_ACTION) op: Equal rhs: {(DQ ($ VSub_Star "$*"))} spids: [694] ) ] spids: [694] ) (C {(export)} {(GIT_REFLOG_ACTION)}) ] spids: [-1 691] ) ] spids: [-1 705] ) ] spids: [671] ) spids: [667 670] ) (FuncDef name: git_editor body: (BraceGroup children: [ (If arms: [ (if_arm cond: [ (C {(test)} {(-z)} { (DQ (BracedVarSub token: suffix_op: (StringUnary op_id:VTest_ColonPlus arg_word:{(set)}) spids: [724 728] ) ) } ) ] action: [ (AndOr children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:GIT_EDITOR) op: Equal rhs: { (DQ (CommandSubPart command_list: (CommandList children: [(C {(git)} {(var)} {(GIT_EDITOR)})] ) left_token: spids: [737 743] ) ) } spids: [735] ) ] spids: [735] ) (ControlFlow token: arg_word: {($ VSub_QMark "$?")} ) ] op_id: Op_DPipe ) ] spids: [-1 732] ) ] spids: [-1 753] ) (C {(eval)} {(DQ ($ VSub_Name "$GIT_EDITOR"))} {(SQ <"\"$@\"">)}) ] spids: [714] ) spids: [710 713] ) (FuncDef name: git_pager body: (BraceGroup children: [ (If arms: [ (if_arm cond: [(C {(test)} {(-t)} {(1)})] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:GIT_PAGER) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [(C {(git)} {(var)} {(GIT_PAGER)})] ) left_token: spids: [790 796] ) } spids: [789] ) ] spids: [789] ) ] spids: [-1 786] ) ] else_action: [ (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:GIT_PAGER) op:Equal rhs:{(cat)} spids:[802])] spids: [802] ) ] spids: [799 806] ) (ForEach iter_name: vardef iter_words: [ {(Lit_Other "@") (Lit_Other "@") (PAGER_ENV) (Lit_Other "@") (Lit_Other "@")} ] do_arg_iter: False body: (DoGroup children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:var) op: Equal rhs: { (BracedVarSub token: suffix_op: (StringUnary op_id:VOp1_DPercent arg_word:{("=*")}) spids: [826 830] ) } spids: [825] ) ] spids: [825] ) (C {(eval)} { (DQ (": ") (EscapedLiteralPart token:) (EscapedLiteralPart token:) ("{") ($ VSub_Name "$vardef") ("}") (EscapedLiteralPart token:) (" && export ") ($ VSub_Name "$var") ) } ) ] spids: [822 848] ) spids: [814 -1] ) (C {(eval)} {(DQ ($ VSub_Name "$GIT_PAGER"))} {(SQ <"\"$@\"">)}) ] spids: [774] ) spids: [770 773] ) (FuncDef name: sane_grep body: (BraceGroup children: [ (SimpleCommand words: [ {(grep)} {(Lit_Other "@") (Lit_Other "@") (SANE_TEXT_GREP) (Lit_Other "@") (Lit_Other "@")} {(DQ ($ VSub_At "$@"))} ] more_env: [ (env_pair name:GREP_OPTIONS val:{(SQ )} spids:[873]) (env_pair name:LC_ALL val:{(C)} spids:[875]) ] ) ] spids: [870] ) spids: [865 869] ) (FuncDef name: sane_egrep body: (BraceGroup children: [ (SimpleCommand words: [ {(egrep)} {(Lit_Other "@") (Lit_Other "@") (SANE_TEXT_GREP) (Lit_Other "@") (Lit_Other "@")} {(DQ ($ VSub_At "$@"))} ] more_env: [ (env_pair name:GREP_OPTIONS val:{(SQ )} spids:[901]) (env_pair name:LC_ALL val:{(C)} spids:[903]) ] ) ] spids: [898] ) spids: [893 897] ) (FuncDef name: is_bare_repository body: (BraceGroup children:[(C {(git)} {(rev-parse)} {(--is-bare-repository)})] spids:[926]) spids: [921 925] ) (FuncDef name: cd_to_toplevel body: (BraceGroup children: [ (AndOr children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:cdup) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [(C {(git)} {(rev-parse)} {(--show-toplevel)})] ) left_token: spids: [947 953] ) } spids: [946] ) ] spids: [946] ) (AndOr children: [ (C {(cd)} {(DQ ($ VSub_Name "$cdup"))}) (BraceGroup children: [ (SimpleCommand words: [ {(gettextln)} { (DQ ("Cannot chdir to ") (EscapedLiteralPart token: ) ("cdup, the toplevel of the working tree") ) } ] redirects: [(Redir op_id:Redir_GreatAnd fd:-1 arg_word:{(2)} spids:[977])] ) (C {(exit)} {(1)}) ] spids: [966] ) ] op_id: Op_DPipe ) ] op_id: Op_DAmp ) ] spids: [943] ) spids: [938 942] ) (FuncDef name: require_work_tree_exists body: (BraceGroup children: [ (If arms: [ (if_arm cond: [ (C {(test)} { (DQ (z) (CommandSubPart command_list: (CommandList children: [(C {(git)} {(rev-parse)} {(--is-bare-repository)})] ) left_token: spids: [1005 1011] ) ) } {(KW_Bang "!") (Lit_Other "=")} {(zfalse)} ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:program_name) op: Equal rhs: {($ VSub_Number "$0")} spids: [1023] ) ] spids: [1023] ) (C {(die)} { (DQ (CommandSubPart command_list: (CommandList children: [ (C {(gettext)} { (DQ ("fatal: ") (EscapedLiteralPart token: ) ("program_name cannot be used without a working tree.") ) } ) ] ) left_token: spids: [1030 1038] ) ) } ) ] spids: [-1 1020] ) ] spids: [-1 1042] ) ] spids: [996] ) spids: [991 995] ) (FuncDef name: require_work_tree body: (BraceGroup children: [ (AndOr children: [ (C {(test)} { (DQ (CommandSubPart command_list: (CommandList children: [ (SimpleCommand words: [{(git)} {(rev-parse)} {(--is-inside-work-tree)}] redirects: [ (Redir op_id: Redir_Great fd: 2 arg_word: {(/dev/null)} spids: [1065] ) ] ) ] ) left_token: spids: [1058 1067] ) ) } {(Lit_Other "=")} {(true)} ) (BraceGroup children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:program_name) op: Equal rhs: {($ VSub_Number "$0")} spids: [1079] ) ] spids: [1079] ) (C {(die)} { (DQ (CommandSubPart command_list: (CommandList children: [ (C {(gettext)} { (DQ ("fatal: ") (EscapedLiteralPart token: ) ("program_name cannot be used without a working tree.") ) } ) ] ) left_token: spids: [1086 1094] ) ) } ) ] spids: [1076] ) ] op_id: Op_DPipe ) ] spids: [1052] ) spids: [1047 1051] ) (FuncDef name: require_clean_work_tree body: (BraceGroup children: [ (AndOr children: [ (SimpleCommand words: [{(git)} {(rev-parse)} {(--verify)} {(HEAD)}] redirects: [(Redir op_id:Redir_Great fd:-1 arg_word:{(/dev/null)} spids:[1119])] ) (C {(exit)} {(1)}) ] op_id: Op_DPipe ) (C {(git)} {(update-index)} {(-q)} {(--ignore-submodules)} {(--refresh)}) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:err) op:Equal rhs:{(0)} spids:[1140])] spids: [1140] ) (If arms: [ (if_arm cond: [ (Pipeline children: [(C {(git)} {(diff-files)} {(--quiet)} {(--ignore-submodules)})] negated: True ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:action) op: Equal rhs: {($ VSub_Number "$1")} spids: [1161] ) ] spids: [1161] ) (Case to_match: {(DQ ($ VSub_Name "$action"))} arms: [ (case_arm pat_list: [{(rebase)}] action: [ (SimpleCommand words: [{(gettextln)} {(DQ ("Cannot rebase: You have unstaged changes."))}] redirects: [ (Redir op_id: Redir_GreatAnd fd: -1 arg_word: {(2)} spids: [1184] ) ] ) ] spids: [1174 1175 1188 -1] ) (case_arm pat_list: [{(DQ ("rewrite branches"))}] action: [ (SimpleCommand words: [ {(gettextln)} {(DQ ("Cannot rewrite branches: You have unstaged changes."))} ] redirects: [ (Redir op_id: Redir_GreatAnd fd: -1 arg_word: {(2)} spids: [1203] ) ] ) ] spids: [1192 1194 1207 -1] ) (case_arm pat_list: [{(DQ ("pull with rebase"))}] action: [ (SimpleCommand words: [ {(gettextln)} {(DQ ("Cannot pull with rebase: You have unstaged changes."))} ] redirects: [ (Redir op_id: Redir_GreatAnd fd: -1 arg_word: {(2)} spids: [1222] ) ] ) ] spids: [1211 1213 1226 -1] ) (case_arm pat_list: [{(Lit_Other "*")}] action: [ (SimpleCommand words: [ {(eval_gettextln)} { (DQ ("Cannot ") (EscapedLiteralPart token:) ("action: You have unstaged changes.") ) } ] redirects: [ (Redir op_id: Redir_GreatAnd fd: -1 arg_word: {(2)} spids: [1241] ) ] ) ] spids: [1229 1230 1245 -1] ) ] spids: [1165 1171 1248] ) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:err) op:Equal rhs:{(1)} spids:[1251])] spids: [1251] ) ] spids: [-1 1158] ) ] spids: [-1 1255] ) (If arms: [ (if_arm cond: [ (Pipeline children: [ (C {(git)} {(diff-index)} {(--cached)} {(--quiet)} {(--ignore-submodules)} {(HEAD)} {(--)} ) ] negated: True ) ] action: [ (If arms: [ (if_arm cond: [(C {(test)} {($ VSub_Name "$err")} {(Lit_Other "=")} {(0)})] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:action) op: Equal rhs: {($ VSub_Number "$1")} spids: [1295] ) ] spids: [1295] ) (Case to_match: {(DQ ($ VSub_Name "$action"))} arms: [ (case_arm pat_list: [{(rebase)}] action: [ (SimpleCommand words: [ {(gettextln)} { (DQ ( "Cannot rebase: Your index contains uncommitted changes." ) ) } ] redirects: [ (Redir op_id: Redir_GreatAnd fd: -1 arg_word: {(2)} spids: [1318] ) ] ) ] spids: [1308 1309 1322 -1] ) (case_arm pat_list: [{(DQ ("pull with rebase"))}] action: [ (SimpleCommand words: [ {(gettextln)} { (DQ ( "Cannot pull with rebase: Your index contains uncommitted changes." ) ) } ] redirects: [ (Redir op_id: Redir_GreatAnd fd: -1 arg_word: {(2)} spids: [1337] ) ] ) ] spids: [1326 1328 1341 -1] ) (case_arm pat_list: [{(Lit_Other "*")}] action: [ (SimpleCommand words: [ {(eval_gettextln)} { (DQ ("Cannot ") (EscapedLiteralPart token: ) ("action: Your index contains uncommitted changes.") ) } ] redirects: [ (Redir op_id: Redir_GreatAnd fd: -1 arg_word: {(2)} spids: [1356] ) ] ) ] spids: [1344 1345 1360 -1] ) ] spids: [1299 1305 1363] ) ] spids: [-1 1292] ) ] else_action: [ (SimpleCommand words: [ {(gettextln)} {(DQ ("Additionally, your index contains uncommitted changes."))} ] redirects: [(Redir op_id:Redir_GreatAnd fd:-1 arg_word:{(2)} spids:[1375])] ) ] spids: [1366 1379] ) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:err) op:Equal rhs:{(1)} spids:[1382])] spids: [1382] ) ] spids: [-1 1278] ) ] spids: [-1 1386] ) (If arms: [ (if_arm cond: [(C {(test)} {($ VSub_Name "$err")} {(Lit_Other "=")} {(1)})] action: [ (AndOr children: [ (C {(test)} {(-n)} {(DQ ($ VSub_Number "$2"))}) (SimpleCommand words: [{(echo)} {(DQ ($ VSub_Number "$2"))}] redirects: [(Redir op_id:Redir_GreatAnd fd:-1 arg_word:{(2)} spids:[1420])] ) ] op_id: Op_DAmp ) (C {(exit)} {(1)}) ] spids: [-1 1401] ) ] spids: [-1 1429] ) ] spids: [1108] ) spids: [1103 1107] ) (FuncDef name: pick_ident_script body: (BraceGroup children: [ (While cond: [(C {(test)} {($ VSub_Pound "$#")} {(-gt)} {(0)})] body: (DoGroup children: [ (Sentence child: (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:lid) op: Equal rhs: {($ VSub_Number "$1")} spids: [1483] ) ] spids: [1483] ) terminator: ) (C {(shift)}) (Sentence child: (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:uid) op: Equal rhs: {($ VSub_Number "$1")} spids: [1490] ) ] spids: [1490] ) terminator: ) (C {(shift)}) (C {(printf)} {(SQ <"%s">)} { (DQ ("\n") ("\t\t/^") ($ VSub_Name "$lid") (" /{\n") ("\t\t\ts/'/'") (EscapedLiteralPart token: ) (EscapedLiteralPart token:) ("''/g\n") ("\t\t\th\n") ("\t\t\ts/^") ($ VSub_Name "$lid") (" ") ) (SQ <"\\([^<]*\\) <[^>]*> .*$/\\1/">) (DQ ("\n") ("\t\t\ts/.*/GIT_") (${ VSub_Name uid) ("_NAME='&'/p\n") ("\n") ("\t\t\tg\n") ("\t\t\ts/^") ($ VSub_Name "$lid") (" ") ) (SQ <"[^<]* <\\([^>]*\\)> .*$/\\1/">) (DQ ("\n") ("\t\t\ts/.*/GIT_") (${ VSub_Name uid) ("_EMAIL='&'/p\n") ("\n") ("\t\t\tg\n") ("\t\t\ts/^") ($ VSub_Name "$lid") (" ") ) (SQ <"[^<]* <[^>]*> \\(.*\\)$/@\\1/">) (DQ ("\n") ("\t\t\ts/.*/GIT_") (${ VSub_Name uid) ("_DATE='&'/p\n") ("\t\t}\n") ("\t\t") ) } ) ] spids: [1480 1564] ) ) (C {(echo)} {(SQ <"/^$/q">)}) ] spids: [1466] ) spids: [1461 1465] ) (FuncDef name: parse_ident_from_commit body: (BraceGroup children: [ (SimpleCommand words: [ {(sed)} {(-ne)} { (DQ (CommandSubPart command_list: (CommandList children: [(C {(pick_ident_script)} {(DQ ($ VSub_At "$@"))})] ) left_token: spids: [1601 1607] ) ) } ] more_env: [ (env_pair name:LANG val:{(C)} spids:[1590]) (env_pair name:LC_ALL val:{(C)} spids:[1593]) ] ) ] spids: [1587] ) spids: [1582 1586] ) (FuncDef name: get_author_ident_from_commit body: (BraceGroup children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:encoding) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (AndOr children: [ (C {(git)} {(config)} {(i18n.commitencoding)}) (C {(echo)} {(UTF-8)}) ] op_id: Op_DPipe ) ] ) left_token: spids: [1628 1640] ) } spids: [1627] ) ] spids: [1627] ) (Pipeline children: [ (C {(git)} {(show)} {(-s)} {(--pretty) (Lit_Other "=") (raw)} {(--encoding) (Lit_Other "=") (DQ ($ VSub_Name "$encoding"))} {(DQ ($ VSub_Number "$1"))} {(--)} ) (C {(parse_ident_from_commit)} {(author)} {(AUTHOR)}) ] negated: False ) ] spids: [1624] ) spids: [1619 1623] ) (FuncDef name: clear_local_git_env body: (BraceGroup children: [ (C {(unset)} { (CommandSubPart command_list: (CommandList children: [(C {(git)} {(rev-parse)} {(--local-env-vars)})] ) left_token: spids: [1695 1701] ) } ) ] spids: [1690] ) spids: [1686 1689] ) (FuncDef name: create_virtual_base body: (BraceGroup children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:sz0) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (SimpleCommand words: [{(wc)} {(-c)}] redirects: [ (Redir op_id: Redir_Less fd: -1 arg_word: {(DQ ($ VSub_Number "$1"))} spids: [1725] ) ] ) ] ) left_token: spids: [1720 1729] ) } spids: [1719] ) ] spids: [1719] ) (Pipeline children: [ (C {(Lit_Other "@") (Lit_Other "@") (DIFF) (Lit_Other "@") (Lit_Other "@")} {(-u)} {(-La/) (DQ ($ VSub_Number "$1"))} {(-Lb/) (DQ ($ VSub_Number "$1"))} {(DQ ($ VSub_Number "$1"))} {(DQ ($ VSub_Number "$2"))} ) (C {(git)} {(apply)} {(--no-add)}) ] negated: False ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:sz1) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (SimpleCommand words: [{(wc)} {(-c)}] redirects: [ (Redir op_id: Redir_Less fd: -1 arg_word: {(DQ ($ VSub_Number "$1"))} spids: [1773] ) ] ) ] ) left_token: spids: [1768 1777] ) } spids: [1767] ) ] spids: [1767] ) (AndOr children: [ (SimpleCommand words: [ {(expr)} {($ VSub_Name "$sz0")} {(EscapedLiteralPart token:)} {($ VSub_Name "$sz1")} {(EscapedLiteralPart token:)} {(2)} ] redirects: [(Redir op_id:Redir_Great fd:-1 arg_word:{(/dev/null)} spids:[1801])] ) (SimpleCommand words: [{(Lit_Other ":")}] redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(DQ ($ VSub_Number "$1"))} spids: [1808] ) ] ) ] op_id: Op_DPipe ) ] spids: [1716] ) spids: [1712 1715] ) (Case to_match: { (CommandSubPart command_list: (CommandList children:[(C {(uname)} {(-s)})]) left_token: spids: [1822 1826] ) } arms: [ (case_arm pat_list: [{(Lit_Other "*") (MINGW) (Lit_Other "*")}] action: [ (FuncDef name: sort body: (BraceGroup children: [(C {(/usr/bin/sort)} {(DQ ($ VSub_At "$@"))})] spids: [1845] ) spids: [1840 1844] ) (FuncDef name: find body: (BraceGroup children: [(C {(/usr/bin/find)} {(DQ ($ VSub_At "$@"))})] spids: [1863] ) spids: [1858 1862] ) (FuncDef name: pwd body: (BraceGroup children:[(C {(builtin)} {(pwd)} {(-W)})] spids:[1885]) spids: [1880 1884] ) (FuncDef name: is_absolute_path body: (BraceGroup children: [ (Case to_match: {(DQ ($ VSub_Number "$1"))} arms: [ (case_arm pat_list: [ {(Lit_Other "[") (/) (EscapedLiteralPart token:) (Lit_Other "]") (Lit_Other "*") } {(Lit_Other "[") (A-Za-z) (Lit_Other "]") (Lit_Other ":") (Lit_Other "*")} ] action: [(ControlFlow token: arg_word:{(0)})] spids: [1915 1928 1935 -1] ) ] spids: [1906 1912 1938] ) (ControlFlow token: arg_word:{(1)}) ] spids: [1903] ) spids: [1898 1902] ) ] spids: [1830 1833 1949 -1] ) (case_arm pat_list: [{(Lit_Other "*")}] action: [ (FuncDef name: is_absolute_path body: (BraceGroup children: [ (Case to_match: {(DQ ($ VSub_Number "$1"))} arms: [ (case_arm pat_list: [{(/) (Lit_Other "*")}] action: [(ControlFlow token: arg_word:{(0)})] spids: [1972 1974 1981 -1] ) ] spids: [1963 1969 1984] ) (ControlFlow token: arg_word:{(1)}) ] spids: [1960] ) spids: [1955 1959] ) ] spids: [1951 1952 -1 1994] ) ] spids: [1820 1828 1994] ) (FuncDef name: git_dir_init body: (BraceGroup children: [ (AndOr children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:GIT_DIR) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [(C {(git)} {(rev-parse)} {(--git-dir)})] ) left_token: spids: [2012 2018] ) } spids: [2011] ) ] spids: [2011] ) (C {(exit)}) ] op_id: Op_DPipe ) (If arms: [ (if_arm cond: [ (C {(Lit_Other "[")} {(-z)} {(DQ ($ VSub_Name "$SUBDIRECTORY_OK"))} {(Lit_Other "]")}) ] action: [ (AndOr children: [ (C {(test)} {(-z)} { (DQ (CommandSubPart command_list: (CommandList children: [(C {(git)} {(rev-parse)} {(--show-cdup)})] ) left_token: spids: [2046 2052] ) ) } ) (BraceGroup children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:exit) op: Equal rhs: {($ VSub_QMark "$?")} spids: [2060] ) ] spids: [2060] ) (SimpleCommand words: [ {(gettextln)} { (DQ ( "You need to run this command from the toplevel of the working tree." ) ) } ] redirects: [ (Redir op_id: Redir_GreatAnd fd: -1 arg_word: {(2)} spids: [2070] ) ] ) (C {(exit)} {($ VSub_Name "$exit")}) ] spids: [2057] ) ] op_id: Op_DPipe ) ] spids: [-1 2038] ) ] spids: [-1 2082] ) (AndOr children: [ (C {(test)} {(-n)} {(DQ ($ VSub_Name "$GIT_DIR"))}) (AndOr children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:GIT_DIR) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (AndOr children: [ (C {(cd)} {(DQ ($ VSub_Name "$GIT_DIR"))}) (C {(pwd)}) ] op_id: Op_DAmp ) ] ) left_token: spids: [2096 2106] ) } spids: [2095] ) ] spids: [2095] ) (BraceGroup children: [ (SimpleCommand words: [ {(gettextln)} {(DQ ("Unable to determine absolute path of git directory"))} ] redirects: [(Redir op_id:Redir_GreatAnd fd:-1 arg_word:{(2)} spids:[2119])] ) (C {(exit)} {(1)}) ] spids: [2110] ) ] op_id: Op_DPipe ) ] op_id: Op_DAmp ) (C {(Lit_Other ":")} { (DQ (BracedVarSub token: suffix_op: (StringUnary op_id: VTest_Equals arg_word: { (DQ (CommandSubPart command_list: (CommandList children: [(C {(git)} {(rev-parse)} {(--git-path)} {(objects)})] ) left_token: spids: [2138 2146] ) ) } ) spids: [2134 2148] ) ) } ) ] spids: [2008] ) spids: [2003 2007] ) (If arms: [ (if_arm cond: [(C {(test)} {(-z)} {(DQ ($ VSub_Name "$NONGIT_OK"))})] action: [(C {(git_dir_init)})] spids: [-1 2164] ) ] spids: [-1 2169] ) (FuncDef name: peel_committish body: (BraceGroup children: [ (Case to_match: {(DQ ($ VSub_Number "$1"))} arms: [ (case_arm pat_list: [{(Lit_Other ":") (/) (Lit_Other "*")}] action: [ (AndOr children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:peeltmp) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (C {(git)} {(rev-parse)} {(--verify)} {(DQ ($ VSub_Number "$1"))} ) ] ) left_token: spids: [2196 2206] ) } spids: [2195] ) ] spids: [2195] ) (C {(git)} {(rev-parse)} {(--verify)} {(DQ (${ VSub_Name peeltmp) ("^0"))}) ] op_id: Op_DAmp ) ] spids: [2189 2192 2225 -1] ) (case_arm pat_list: [{(Lit_Other "*")}] action: [(C {(git)} {(rev-parse)} {(--verify)} {(DQ (${ VSub_Number 1) ("^0"))})] spids: [2228 2229 2246 -1] ) ] spids: [2180 2186 2249] ) ] spids: [2177] ) spids: [2172 2176] ) ] )