Like merging errors, or rebase errors. Does it have a unique error code?
I set-up a test to fail. This is what I got:
$ git merge newbranch
Auto-merging test.txt
CONFLICT (content): Merge conflict in test.txt
Automatic merge failed; fix conflicts and then commit the result.
$ echo $?
1
Git returns 0
when it merges correctly, as expected.
&&
; that's how their tests are implemented. –
Schulte git rebase
the same behavior? –
Vanburen git checkout somebranch
seems to return 1 too. –
Judges A simple git checkout somebranch seems to return 1 too
I was just bitten by this! Had a command chain git checkout mybranch && git pull
and it failed to pull
even though the checkout
appeared to succeed! Posted a question about it which, naturally, was promptly closed by the admins. –
Sate In short, no. You're going to see exit code 1 for errors, and 0 for success.
From a quick grepping of the source, there are some of the expected 127 and 128 for their specific purposes (command not found, errors already reported), and a few unusual codes in a few places, but for run of the mill errors, it's all exit(1)
.
man
pages for details. –
Oleaster Running git status
on a non-git repo returns 128, not 1, which is helpful in quickly determining whether a git repo exists or not.
git rev-parse --is-inside-work-tree
is better –
Aeolic git push --delete origin a_remote_tag_name
This returns 256 if the tag doesn't exist using git version 1.8.3.1
It would be nice to have a consolidated list of specific return codes returned by each command and what they indicate. This might also help prevent changing the return code meanings (which automation scripts might rely on).
Error 128, with no error message from git, could be a catch-all for "unexpected problem".
I was getting this on operations that needed to modify files under .git (e.g. "git checkout -- myfile
" to revert a modified file) by a different user. (In my case "chmod -R og+w .git
" fixed it; naturally, don't do that unless you understand the security implications for your case!)
Git 2.24 (Q4 2019) does illustrate how git
commands return code.
See commit 50094ca, commit c1a6f21, commit 854b5cb, commit dd2b6b6, commit 6bd26f5, commit c6ec6da, commit f2e2fa8, commit 460609c, commit 92014b6, commit 0ab74e9, commit cb46c40, commit b562a54 (27 Aug 2019), and commit fe49814 (20 Aug 2019) by Denton Liu (Denton-L
).
(Merged by Junio C Hamano -- gitster
-- in commit 1c6fc94, 30 Sep 2019)
t4014: stop losing return codes of git commands
Currently, there are two ways where the return codes of Git commands are lost.
The first way is when a command is in the upstream of a pipe. In a pipe, only the return code of the last command is used. Thus, all other commands will have their return codes masked.
Rewrite pipes so that there are no Git commands upstream.The other way is when a command is in a non-assignment subshell.
The return code will be lost in favour of the surrounding command's.
Rewrite instances of this such that Git commands output to a file and surrounding commands only call subshells with non-Git commands.
So instead of writing:
git cat-file commit rebuild-1 | grep "^Side .* with .* backslash-n"
Type:
git cat-file commit rebuild-1 >actual &&
grep "^Side .* with .* backslash-n" actual
© 2022 - 2024 — McMap. All rights reserved.
git merge
(at 1.7.4 - kernel.org/pub/software/scm/git/docs/v1.7.4/git-merge.html) only mention the return status in one place (if you use "--ff-only" and it can't do a fast-forward commit, it returns non-zero - it doesn't explicitly say what is returned if it all works or if there was a merge conflict. – Fireplug