如果在XCode中打开项目,如何使用脚本检查?

时间:2011-01-06 09:50:22

标签: xcode git bash

我想为我的iPhone项目引入内部版本号功能,并在每次提交到我的git repo时自动增加它。我计划使用Apple的agvtool来做,它建议当时不在XCode中打开项目

所以我的问题是: 1)到目前为止,我知道我需要从.git/hooks/pre-commit.sample创建一个可执行脚本。如何编写脚本以检查是否在XCode中打开了某个项目?

2)pre-commit.sh将在没有args的情况下调用git commit时执行,因此每当有人提交-a选项时,我都不会更新我的内部版本号。有没有办法解决这个问题?

干杯

2 个答案:

答案 0 :(得分:1)

我既不知道Xcode也不知道agvtool但是读到你的问题我觉得你每次提交时都希望增加你的构建号。对我来说这看起来很奇怪,因为提交git与实际构建无关。

你最好在你的构建系统中添加一个钩子而不是在git中。

答案 1 :(得分:1)

Xcode支持AppleScript。我用Xcode 4.2对此进行了测试,但我认为它应该在早期版本中使用。

首先,编写一个脚本文件isXcodeProjectOpen.scpt

-- Returns 1 if a project in the given directory is open, otherwise 0
on run argv
    set _path to first item of argv
    tell application "Xcode"
        repeat with _p in projects
            if project directory of _p is _path then
                return 1
            end if
        end repeat
    end tell
    return 0
end run

然后你可以从shell运行它:

ISOPEN=`osascript isXcodeProjectOpen.scpt /path/containing/project`
if [ -z $ISOPEN ]; then
   # all clear
else
   # not safe to run agvtool!
fi