{"thread":{"id":"40020","subject":"Error pushing new branch: value too great for base (error token is...","startedAt":"2015-08-05T17:32:26Z","lastAt":"2015-08-11T06:30:23Z","messageCount":6,"participants":["Gaurav Chhabra","Eric Sunshine","Jacob Keller"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"267523","messageId":"CAGDgvc3Gxn=pKBfYC+yrUhCmL9X6bqjPVwVokF0qPsXmhx_EaQ@mail.gmail.com","threadId":"40020","inReplyTo":null,"subject":"Error pushing new branch: value too great for base (error token is...","fromName":"Gaurav Chhabra","fromEmail":"varuag.chhabra@gmail.com","sentAt":"2015-08-05T17:32:26Z","receivedAt":"2015-08-05T17:32:26Z","isPatch":false,"sender":{"key":"varuag.chhabra@gmail.com","avatar":"https://gravatar.com/avatar/b731428347fdc09c456902cac39c52957f1e296e8edd38f6162400e8402f480e?d=mp&s=160"},"body":"I had written the following code to check whether a push is for branch deletion:\n\n#!/bin/bash\n\nNULL=\"0000000000000000000000000000000000000000\"\n\nwhile read old_sha new_sha refname ; do\n    echo \"Stdin: [$old_sha] [$new_sha] [$refname]\"\n\n    if [[ \"$new_sha\" -eq \"$NULL\" ]]; then   # Line 17\n        echo \"Skipping checks...\"\n        continue\n    fi\n    ...\n    ...\n    ...\ndone\n\n\nWhile it works fine for branch deletion, i noticed that if i create a\nbranch and push it to remote, i get the following error due to the\nabove-mentioned code:\n\n$ git push origin rel-a\nCounting objects: 5, done.\nDelta compression using up to 4 threads.\nCompressing objects: 100% (2/2), done.\nWriting objects: 100% (3/3), 407 bytes | 0 bytes/s, done.\nTotal 3 (delta 0), reused 0 (delta 0)\nremote: Stdin: [0000000000000000000000000000000000000000]\n[9226289d2416af4cb7365d7aaa5e382bdb3d9a89] [refs/heads/rel-a]\nremote:\nremote: hooks/pre-receive: line 17: [[:\n9226289d2416af4cb7365d7aaa5e382bdb3d9a89: value too great for base\n(error token is \"922628\n9d2416af4cb7365d7aaa5e382bdb3d9a89\")\n\n\nAlthough the new branch gets pushed to remote but i'm not sure why i'm\ngetting this error and how can i fix it. I checked online and i get\nfew links where folks had similar issue but in each such case, the\nerror token was 08 or 09. I still tried the suggestion of using \"10#\"\nin front of my $new_sha variable but to no avail.\n\nAny suggestions?\n"},{"id":"267528","messageId":"CAPig+cTXO3699MdqSFVDBcnKcHAT=Mkp=c=r3C8F5nT8tfr6gw@mail.gmail.com","threadId":"40020","inReplyTo":"CAGDgvc3Gxn=pKBfYC+yrUhCmL9X6bqjPVwVokF0qPsXmhx_EaQ@mail.gmail.com","subject":"Re: Error pushing new branch: value too great for base (error token is...","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2015-08-05T17:53:19Z","receivedAt":"2015-08-05T17:53:19Z","isPatch":false,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Wed, Aug 5, 2015 at 1:32 PM, Gaurav Chhabra <varuag.chhabra@gmail.com> wrote:\n> I had written the following code to check whether a push is for branch deletion:\n>\n> #!/bin/bash\n>\n> NULL=\"0000000000000000000000000000000000000000\"\n>     if [[ \"$new_sha\" -eq \"$NULL\" ]]; then   # Line 17\n> remote: Stdin: [0000000000000000000000000000000000000000]\n> [9226289d2416af4cb7365d7aaa5e382bdb3d9a89] [refs/heads/rel-a]\n> remote:\n> remote: hooks/pre-receive: line 17: [[:\n> 9226289d2416af4cb7365d7aaa5e382bdb3d9a89: value too great for base\n> (error token is \"922628\n> 9d2416af4cb7365d7aaa5e382bdb3d9a89\")\n>\n> Although the new branch gets pushed to remote but i'm not sure why i'm\n> getting this error and how can i fix it. I checked online and i get\n> few links where folks had similar issue but in each such case, the\n> error token was 08 or 09. I still tried the suggestion of using \"10#\"\n> in front of my $new_sha variable but to no avail.\n>\n> Any suggestions?\n\nYes, try using the string comparison '=' operator rather than the\nnumeric comparison operator '-eq'.\n\n    if [[ \"$new_sha\" = \"$NULL\" ]]; then\n"},{"id":"267745","messageId":"CAGDgvc1FJ0K+OLQBj8iXPCnqMFyBD3mp32k0aTztQkKKuxNxtQ@mail.gmail.com","threadId":"40020","inReplyTo":"CAGDgvc2hc+f5CuPXc2pr5uYd9kniVpuffrb6z416CicxBgVxJQ@mail.gmail.com","subject":"Re: Error pushing new branch: value too great for base (error token is...","fromName":"Gaurav Chhabra","fromEmail":"varuag.chhabra@gmail.com","sentAt":"2015-08-10T09:54:07Z","receivedAt":"2015-08-10T09:54:07Z","isPatch":false,"sender":{"key":"varuag.chhabra@gmail.com","avatar":"https://gravatar.com/avatar/b731428347fdc09c456902cac39c52957f1e296e8edd38f6162400e8402f480e?d=mp&s=160"},"body":"Apologies for the delay in reply! I tried your suggestion and it\nworks. Thanks! :)\n\nI'm curious why integer comparison is throwing error. Shouldn't i be\ncomparing numbers with numeric operator?\n\nOn Mon, Aug 10, 2015 at 3:23 PM, Gaurav Chhabra\n<varuag.chhabra@gmail.com> wrote:\n> Apologies for the delay in reply! I tried your suggestion and it works.\n> Thanks! :)\n>\n> I'm curious why integer comparison is throwing error. Shouldn't i be\n> comparing numbers with numeric operator?\n>\n>\n> On Wed, Aug 5, 2015 at 11:23 PM, Eric Sunshine <sunshine@sunshineco.com>\n> wrote:\n>>\n>> On Wed, Aug 5, 2015 at 1:32 PM, Gaurav Chhabra <varuag.chhabra@gmail.com>\n>> wrote:\n>> > I had written the following code to check whether a push is for branch\n>> > deletion:\n>> >\n>> > #!/bin/bash\n>> >\n>> > NULL=\"0000000000000000000000000000000000000000\"\n>> >     if [[ \"$new_sha\" -eq \"$NULL\" ]]; then   # Line 17\n>> > remote: Stdin: [0000000000000000000000000000000000000000]\n>> > [9226289d2416af4cb7365d7aaa5e382bdb3d9a89] [refs/heads/rel-a]\n>> > remote:\n>> > remote: hooks/pre-receive: line 17: [[:\n>> > 9226289d2416af4cb7365d7aaa5e382bdb3d9a89: value too great for base\n>> > (error token is \"922628\n>> > 9d2416af4cb7365d7aaa5e382bdb3d9a89\")\n>> >\n>> > Although the new branch gets pushed to remote but i'm not sure why i'm\n>> > getting this error and how can i fix it. I checked online and i get\n>> > few links where folks had similar issue but in each such case, the\n>> > error token was 08 or 09. I still tried the suggestion of using \"10#\"\n>> > in front of my $new_sha variable but to no avail.\n>> >\n>> > Any suggestions?\n>>\n>> Yes, try using the string comparison '=' operator rather than the\n>> numeric comparison operator '-eq'.\n>>\n>>     if [[ \"$new_sha\" = \"$NULL\" ]]; then\n>\n>\n"},{"id":"267796","messageId":"CA+P7+xpKHw8xkpMSjCftmAnMh=J_R9HxhYD48O2-P2WKUH1diw@mail.gmail.com","threadId":"40020","inReplyTo":"CAGDgvc1FJ0K+OLQBj8iXPCnqMFyBD3mp32k0aTztQkKKuxNxtQ@mail.gmail.com","subject":"Re: Error pushing new branch: value too great for base (error token is...","fromName":"Jacob Keller","fromEmail":"jacob.keller@gmail.com","sentAt":"2015-08-10T22:29:02Z","receivedAt":"2015-08-10T22:29:02Z","isPatch":false,"sender":{"key":"jacob.keller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/874719?v=4"},"body":"On Mon, Aug 10, 2015 at 2:54 AM, Gaurav Chhabra\n<varuag.chhabra@gmail.com> wrote:\n> Apologies for the delay in reply! I tried your suggestion and it\n> works. Thanks! :)\n>\n> I'm curious why integer comparison is throwing error. Shouldn't i be\n> comparing numbers with numeric operator?\n>\n\nYes, but shell doesn't treat hex numbers as numbers. So it will work\nonly if the string is a decimal number.\n\nRegards,\nJake\n"},{"id":"267800","messageId":"CAPig+cTB0VU6rmLT1H7sPMNBPE0zKvWmMp_obS5VpZBAi2nYLA@mail.gmail.com","threadId":"40020","inReplyTo":"CA+P7+xpKHw8xkpMSjCftmAnMh=J_R9HxhYD48O2-P2WKUH1diw@mail.gmail.com","subject":"Re: Error pushing new branch: value too great for base (error token is...","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2015-08-10T22:47:50Z","receivedAt":"2015-08-10T22:47:50Z","isPatch":false,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Mon, Aug 10, 2015 at 6:29 PM, Jacob Keller <jacob.keller@gmail.com> wrote:\n> On Mon, Aug 10, 2015 at 2:54 AM, Gaurav Chhabra\n> <varuag.chhabra@gmail.com> wrote:\n>> Apologies for the delay in reply! I tried your suggestion and it\n>> works. Thanks! :)\n>>\n>> I'm curious why integer comparison is throwing error. Shouldn't i be\n>> comparing numbers with numeric operator?\n>\n> Yes, but shell doesn't treat hex numbers as numbers. So it will work\n> only if the string is a decimal number.\n\nThis particular case deserves a bit more explanation. The expression\nin question was this:\n\n    if [[ \"$new_sha\" -eq \"$NULL\" ]]; then\n\nwhere 'new_sha' was 9226289d2416af4cb7365d7aaa5e382bdb3d9a89.\n\nIn Bash, inside the [[ .. ]], it did attempt evaluating the SHA1 as a\n*decimal* number, however, when it encountered the \"d\", it complained\nthat it was outside the allowed range of decimal digits (\"0\"...\"9\").\nHad the SHA1 been prefixed by a \"0x\", the [[...]] context would have\ndealt with it just fine.\n\nOutside the [[...]] context, arguments to -eq do need to be base-10 integers.\n\nNevertheless, a SHA1 is effective an opaque value. There's little, if\nanything, to be gained by treating it as a numeric quantity, hence\nstring '=' makes more sense than numeric '-eq'.\n"},{"id":"267814","messageId":"CAGDgvc3kA4oC=gp7XoPZJNrQ=p6HoUiXgcECG_xdRR=uJ03+aQ@mail.gmail.com","threadId":"40020","inReplyTo":"CAPig+cTB0VU6rmLT1H7sPMNBPE0zKvWmMp_obS5VpZBAi2nYLA@mail.gmail.com","subject":"Re: Error pushing new branch: value too great for base (error token is...","fromName":"Gaurav Chhabra","fromEmail":"varuag.chhabra@gmail.com","sentAt":"2015-08-11T06:30:23Z","receivedAt":"2015-08-11T06:30:23Z","isPatch":false,"sender":{"key":"varuag.chhabra@gmail.com","avatar":"https://gravatar.com/avatar/b731428347fdc09c456902cac39c52957f1e296e8edd38f6162400e8402f480e?d=mp&s=160"},"body":"Thanks for the detailed explanation Eric! That really helped clear my\ndoubts. Also tried with \"0x\" and it's working fine however, as\nsuggested by you, i will use '='\n\nThanks again! :)\n\nOn Tue, Aug 11, 2015 at 4:17 AM, Eric Sunshine <sunshine@sunshineco.com> wrote:\n> On Mon, Aug 10, 2015 at 6:29 PM, Jacob Keller <jacob.keller@gmail.com> wrote:\n>> On Mon, Aug 10, 2015 at 2:54 AM, Gaurav Chhabra\n>> <varuag.chhabra@gmail.com> wrote:\n>>> Apologies for the delay in reply! I tried your suggestion and it\n>>> works. Thanks! :)\n>>>\n>>> I'm curious why integer comparison is throwing error. Shouldn't i be\n>>> comparing numbers with numeric operator?\n>>\n>> Yes, but shell doesn't treat hex numbers as numbers. So it will work\n>> only if the string is a decimal number.\n>\n> This particular case deserves a bit more explanation. The expression\n> in question was this:\n>\n>     if [[ \"$new_sha\" -eq \"$NULL\" ]]; then\n>\n> where 'new_sha' was 9226289d2416af4cb7365d7aaa5e382bdb3d9a89.\n>\n> In Bash, inside the [[ .. ]], it did attempt evaluating the SHA1 as a\n> *decimal* number, however, when it encountered the \"d\", it complained\n> that it was outside the allowed range of decimal digits (\"0\"...\"9\").\n> Had the SHA1 been prefixed by a \"0x\", the [[...]] context would have\n> dealt with it just fine.\n>\n> Outside the [[...]] context, arguments to -eq do need to be base-10 integers.\n>\n> Nevertheless, a SHA1 is effective an opaque value. There's little, if\n> anything, to be gained by treating it as a numeric quantity, hence\n> string '=' makes more sense than numeric '-eq'.\n"}]}